Skip to content

Commit 9fdf3ca

Browse files
committed
Create facts.matching method
1 parent e1d2762 commit 9fdf3ca

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

lib/octocatalog-diff/facts.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,12 @@ def override(key, value)
120120
@facts['values'][key] = value
121121
end
122122
end
123+
124+
# Find all facts matching a particular pattern
125+
# @param regex [Regexp] Regular expression to match
126+
# @return [Array<String>] Facts that match the regexp
127+
def matching(regex)
128+
@facts['values'].keys.select { |fact| regex.match(fact) }
129+
end
123130
end
124131
end

spec/octocatalog-diff/tests/facts_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,11 @@
133133
expect(result_arr[3].strip).to eq('apt_update_last_success: 1458162123')
134134
end
135135
end
136+
137+
describe '#matching' do
138+
it 'should return facts that match the regexp' do
139+
expect(@obj.matching(/(last|stamp)/)).to eq(%w[apt_update_last_success timestamp])
140+
end
141+
end
136142
end
137143
end

0 commit comments

Comments
 (0)