mirror of
https://github.com/inspec/inspec
synced 2024-11-23 05:03:07 +00:00
expose simpleconfig groups
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
4d70aed6ee
commit
8b97bdbaa7
2 changed files with 7 additions and 1 deletions
|
@ -3,7 +3,7 @@
|
|||
# license: All rights reserved
|
||||
|
||||
class SimpleConfig
|
||||
attr_reader :params
|
||||
attr_reader :params, :groups
|
||||
def initialize(raw_data, opts = {})
|
||||
parse(raw_data, opts)
|
||||
end
|
||||
|
@ -17,6 +17,7 @@ class SimpleConfig
|
|||
# no comments can be added to the end of an assignment/statement line
|
||||
def parse(raw_data, opts = {})
|
||||
@params = {}
|
||||
@groups = []
|
||||
@vals = @params
|
||||
options = default_options.merge(opts || {})
|
||||
rest = raw_data
|
||||
|
@ -82,6 +83,7 @@ class SimpleConfig
|
|||
return nil if opts[:group_re].nil?
|
||||
m = opts[:group_re].match(line)
|
||||
return nil if m.nil?
|
||||
@groups.push(m[1])
|
||||
@vals = @params[m[1]] = {}
|
||||
end
|
||||
|
||||
|
|
|
@ -51,16 +51,19 @@ describe 'SimpleConfig' do
|
|||
it 'handles groups' do
|
||||
cur = SimpleConfig.new('[g]')
|
||||
cur.params.must_equal({ 'g' => {} })
|
||||
cur.groups.must_equal(['g'])
|
||||
end
|
||||
|
||||
it 'handles non-group assignments and groups' do
|
||||
cur = SimpleConfig.new("a = b\n[g]")
|
||||
cur.params.must_equal({ 'a' => 'b', 'g' => {} })
|
||||
cur.groups.must_equal(['g'])
|
||||
end
|
||||
|
||||
it 'handles assignments in groups' do
|
||||
cur = SimpleConfig.new("[g]\na = b")
|
||||
cur.params.must_equal({ 'g' => { 'a' => 'b' } })
|
||||
cur.groups.must_equal(['g'])
|
||||
end
|
||||
|
||||
it 'handles multiple groups' do
|
||||
|
@ -70,6 +73,7 @@ describe 'SimpleConfig' do
|
|||
'k' => { 'c' => 'd' },
|
||||
}
|
||||
cur.params.must_equal(res)
|
||||
cur.groups.must_equal(['g', 'k'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue