Merge pull request #193 from chef/group-title

Merged change 6ed6a2db-4cf1-4474-ac23-ae430fd28a97

From review branch group-title into master

Signed-off-by: chartmann <chartmann@chef.io>
This commit is contained in:
chef-delivery 2015-11-02 13:23:52 -08:00
commit e71f89691c
2 changed files with 18 additions and 5 deletions

View file

@ -43,8 +43,9 @@ module Inspec
title: rule.title,
desc: rule.desc,
impact: rule.impact,
code: rule.instance_variable_get(:@__code),
checks: rule.instance_variable_get(:@checks),
code: rule.instance_variable_get(:@__code),
group_title: rule.instance_variable_get(:@__group_title),
}
end
end
@ -55,7 +56,7 @@ module Inspec
res[:rules].each do |gid, group|
next if gid.to_s.empty?
path = gid.sub(File.join(@path, ''), '')
rules[path] = { title: '', rules: {} }
rules[path] = { title: path, rules: {} }
group.each do |id, rule|
next if id.to_s.empty?
data = rule.dup
@ -64,6 +65,9 @@ module Inspec
data[:impact] = 1.0 if data[:impact] > 1.0
data[:impact] = 0.0 if data[:impact] < 0.0
rules[path][:rules][id] = data
# TODO: temporarily flatten the group down; replace this with
# proper hierarchy later on
rules[path][:title] = data[:group_title]
end
end
res[:rules] = rules

View file

@ -7,7 +7,7 @@ require 'inspec/dsl'
require 'rspec/core/dsl'
module Inspec
class ProfileContext
class ProfileContext # rubocop:disable Metrics/ClassLength
attr_reader :rules, :only_ifs
def initialize(profile_id, backend, profile_registry = {}, only_ifs = [])
if backend.nil?
@ -27,7 +27,7 @@ module Inspec
end
def load(content, source = nil, line = nil)
@current_file = source
@current_load = { file: source }
@profile_context.instance_eval(content, source || 'unknown', line || 1)
end
@ -38,7 +38,8 @@ module Inspec
def register_rule(r)
# get the full ID
r.instance_variable_set(:@__file, @current_file)
r.instance_variable_set(:@__file, @current_load[:file])
r.instance_variable_set(:@__group_title, @current_load[:title])
full_id = Inspec::Rule.full_id(@profile_id, r)
if full_id.nil?
# TODO: error
@ -54,6 +55,10 @@ module Inspec
end
end
def set_header(field, val)
@current_load[field] = val
end
private
# Creates the inner DSL which includes all resources for
@ -136,6 +141,10 @@ module Inspec
Class.new(outer_dsl) do
include Inspec::DSL
define_method :title do |arg|
profile_context_owner.set_header(:title, arg)
end
define_method :__register_rule do |*args|
profile_context_owner.register_rule(*args)
end