File tree Expand file tree Collapse file tree
lib/octocatalog-diff/api/v1
spec/octocatalog-diff/tests/api/v1 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ class Override
1313 # Constructor: Accepts a key and value.
1414 # @param input [Hash] Must contain :key and :value
1515 def initialize ( input )
16- @key = input . fetch ( :key )
16+ key = input . fetch ( :key )
17+ @key = key =~ %r{\A /(.+)/\Z } ? Regexp . new ( Regexp . last_match ( 1 ) ) : key
1718 @value = parsed_value ( input . fetch ( :value ) )
1819 end
1920
@@ -29,6 +30,7 @@ def self.create_from_input(input, key = nil)
2930 # If input is not a string, we can still construct the object if the key is given.
3031 # That input would come directly from code and not from the command line, since inputs
3132 # from the command line are always strings.
33+ # Also support regular expressions for the key name, if delimited by //.
3234 if key . nil? && input . is_a? ( String )
3335 unless input . include? ( '=' )
3436 raise ArgumentError , "Fact override '#{ input } ' is not in 'key=(data type)value' format"
Original file line number Diff line number Diff line change 66
77describe OctocatalogDiff ::API ::V1 ::Override do
88 describe '#new' do
9- it 'should raise error if fact_name is not supplied' do
9+ it 'should raise error if fact name is not supplied' do
1010 expect { described_class . new ( value : 'bar' ) } . to raise_error ( KeyError , /key/ )
1111 end
1212
1313 it 'should raise error if value is not supplied' do
1414 expect { described_class . new ( key : 'bar' ) } . to raise_error ( KeyError , /value/ )
1515 end
16+
17+ it 'should return a regexp if fact name is a regexp' do
18+ testobj = described_class . new ( key : '/foo/' , value : 'bar' )
19+ expect ( testobj . key ) . to eq ( /foo/ )
20+ expect ( testobj . value ) . to eq ( 'bar' )
21+ end
1622 end
1723
1824 describe '#key' do
You can’t perform that action at this time.
0 commit comments