Class: ComplianceEngine::Component
- Inherits:
-
Object
- Object
- ComplianceEngine::Component
- Defined in:
- lib/compliance_engine/component.rb
Overview
A generic compliance engine data component
Instance Attribute Summary collapse
-
#component ⇒ Object
Returns the value of attribute component.
-
#enforcement_tolerance ⇒ Object
Returns the value of attribute enforcement_tolerance.
-
#environment_data ⇒ Object
Returns the value of attribute environment_data.
-
#facts ⇒ Object
Returns the value of attribute facts.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Return a single key from the component.
-
#add(filename, value) ⇒ Object
Adds a value to the fragments array of the component.
-
#ces ⇒ Array, Hash
Returns the ces of the component.
-
#controls ⇒ Hash
Returns the controls of the component.
-
#description ⇒ String
Returns the description of the component.
-
#identifiers ⇒ Hash
Returns the identifiers of the component.
-
#initialize(name, data: nil) ⇒ Component
constructor
A generic compliance engine data component.
-
#invalidate_cache(data = nil) ⇒ NilClass
Invalidate the cache of computed data.
-
#key ⇒ String
Returns the key of the component.
-
#oval_ids ⇒ Array
Returns the oval ids of the component.
-
#title ⇒ String
Returns the title of the component.
-
#to_a ⇒ Array
Returns an array of fragments from the component.
-
#to_h ⇒ Hash
Returns the merged data from the component.
Constructor Details
#initialize(name, data: nil) ⇒ Component
A generic compliance engine data component
12 13 14 15 |
# File 'lib/compliance_engine/component.rb', line 12 def initialize(name, data: nil) context_variables.each { |var| instance_variable_set(var, data&.instance_variable_get(var)) } @component ||= { key: name, fragments: {} } end |
Instance Attribute Details
#component ⇒ Object
Returns the value of attribute component.
17 18 19 |
# File 'lib/compliance_engine/component.rb', line 17 def component @component end |
#enforcement_tolerance ⇒ Object
Returns the value of attribute enforcement_tolerance.
17 18 19 |
# File 'lib/compliance_engine/component.rb', line 17 def enforcement_tolerance @enforcement_tolerance end |
#environment_data ⇒ Object
Returns the value of attribute environment_data.
17 18 19 |
# File 'lib/compliance_engine/component.rb', line 17 def environment_data @environment_data end |
#facts ⇒ Object
Returns the value of attribute facts.
17 18 19 |
# File 'lib/compliance_engine/component.rb', line 17 def facts @facts end |
Instance Method Details
#[](key) ⇒ Object
Return a single key from the component
105 106 107 |
# File 'lib/compliance_engine/component.rb', line 105 def [](key) element[key] end |
#add(filename, value) ⇒ Object
Adds a value to the fragments array of the component.
33 34 35 |
# File 'lib/compliance_engine/component.rb', line 33 def add(filename, value) component[:fragments][filename] = value end |
#ces ⇒ Array, Hash
This returns an Array for checks and a Hash for other components
Returns the ces of the component
97 98 99 |
# File 'lib/compliance_engine/component.rb', line 97 def ces element['ces'] end |
#controls ⇒ Hash
Returns the controls of the component
82 83 84 |
# File 'lib/compliance_engine/component.rb', line 82 def controls element['controls'] end |
#description ⇒ String
Returns the description of the component
68 69 70 |
# File 'lib/compliance_engine/component.rb', line 68 def description element['description'] end |
#identifiers ⇒ Hash
Returns the identifiers of the component
89 90 91 |
# File 'lib/compliance_engine/component.rb', line 89 def identifiers element['identifiers'] end |
#invalidate_cache(data = nil) ⇒ NilClass
Invalidate the cache of computed data
23 24 25 26 27 |
# File 'lib/compliance_engine/component.rb', line 23 def invalidate_cache(data = nil) context_variables.each { |var| instance_variable_set(var, data&.instance_variable_get(var)) } cache_variables.each { |var| instance_variable_set(var, nil) } nil end |
#key ⇒ String
Returns the key of the component
54 55 56 |
# File 'lib/compliance_engine/component.rb', line 54 def key component[:key] end |
#oval_ids ⇒ Array
Returns the oval ids of the component
75 76 77 |
# File 'lib/compliance_engine/component.rb', line 75 def oval_ids element['oval-ids'] end |
#title ⇒ String
Returns the title of the component
61 62 63 |
# File 'lib/compliance_engine/component.rb', line 61 def title element['title'] end |
#to_a ⇒ Array
Returns an array of fragments from the component
40 41 42 |
# File 'lib/compliance_engine/component.rb', line 40 def to_a component[:fragments].values end |
#to_h ⇒ Hash
Returns the merged data from the component
47 48 49 |
# File 'lib/compliance_engine/component.rb', line 47 def to_h element end |