Class: Inspec::ProfileContext
- Inherits:
-
Object
- Object
- Inspec::ProfileContext
- Defined in:
- lib/inspec/profile_context.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#only_ifs ⇒ Object
readonly
Returns the value of attribute only_ifs.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
-
#initialize(profile_id, backend, profile_registry = {}, only_ifs = []) ⇒ ProfileContext
constructor
A new instance of ProfileContext.
- #load(content, source = nil, line = nil) ⇒ Object
- #register_rule(r) ⇒ Object
- #reload_dsl ⇒ Object
- #set_header(field, val) ⇒ Object
- #unregister_rule(id) ⇒ Object
Constructor Details
#initialize(profile_id, backend, profile_registry = {}, only_ifs = []) ⇒ ProfileContext
Returns a new instance of ProfileContext.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/inspec/profile_context.rb', line 13 def initialize(profile_id, backend, profile_registry = {}, only_ifs = []) if backend.nil? fail 'ProfileContext is initiated with a backend == nil. ' \ 'This is a backend error which must be fixed upstream.' end @profile_id = profile_id @rules = profile_registry @only_ifs = only_ifs @backend = backend reload_dsl end |
Instance Attribute Details
#only_ifs ⇒ Object (readonly)
Returns the value of attribute only_ifs.
12 13 14 |
# File 'lib/inspec/profile_context.rb', line 12 def only_ifs @only_ifs end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
12 13 14 |
# File 'lib/inspec/profile_context.rb', line 12 def rules @rules end |
Instance Method Details
#load(content, source = nil, line = nil) ⇒ Object
34 35 36 37 |
# File 'lib/inspec/profile_context.rb', line 34 def load(content, source = nil, line = nil) @current_load = { file: source } @profile_context.instance_eval(content, source || 'unknown', line || 1) end |
#register_rule(r) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/inspec/profile_context.rb', line 44 def register_rule(r) # get the full ID 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 return end # add the rule to the registry existing = @rules[full_id] if existing.nil? @rules[full_id] = r else Inspec::Rule.merge(existing, r) end end |
#reload_dsl ⇒ Object
27 28 29 30 31 32 |
# File 'lib/inspec/profile_context.rb', line 27 def reload_dsl dsl = create_inner_dsl(@backend) outer_dsl = create_outer_dsl(dsl) ctx = create_context(outer_dsl) @profile_context = ctx.new end |
#set_header(field, val) ⇒ Object
63 64 65 |
# File 'lib/inspec/profile_context.rb', line 63 def set_header(field, val) @current_load[field] = val end |