Class: ComplianceEngine::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/compliance_engine/component.rb

Overview

A generic compliance engine data component

Direct Known Subclasses

Ce, Check, Control, Profile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, data: nil) ⇒ Component

A generic compliance engine data component

Parameters:



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

#componentObject

Returns the value of attribute component.



17
18
19
# File 'lib/compliance_engine/component.rb', line 17

def component
  @component
end

#enforcement_toleranceObject

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_dataObject

Returns the value of attribute environment_data.



17
18
19
# File 'lib/compliance_engine/component.rb', line 17

def environment_data
  @environment_data
end

#factsObject

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

Parameters:

  • key (String)

    the key of the value to return

Returns:

  • (Object)

    the value of the key



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.

Parameters:

  • value (Object)

    The value to be added to the fragments array.

Returns:

  • (Object)


33
34
35
# File 'lib/compliance_engine/component.rb', line 33

def add(filename, value)
  component[:fragments][filename] = value
end

#cesArray, Hash

Note:

This returns an Array for checks and a Hash for other components

Returns the ces of the component

Returns:

  • (Array, Hash)

    the ces of the component



97
98
99
# File 'lib/compliance_engine/component.rb', line 97

def ces
  element['ces']
end

#controlsHash

Returns the controls of the component

Returns:

  • (Hash)

    the controls of the component



82
83
84
# File 'lib/compliance_engine/component.rb', line 82

def controls
  element['controls']
end

#descriptionString

Returns the description of the component

Returns:

  • (String)

    the description of the component



68
69
70
# File 'lib/compliance_engine/component.rb', line 68

def description
  element['description']
end

#identifiersHash

Returns the identifiers of the component

Returns:

  • (Hash)

    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

Parameters:

Returns:

  • (NilClass)


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

#keyString

Returns the key of the component

Returns:

  • (String)

    the key of the component



54
55
56
# File 'lib/compliance_engine/component.rb', line 54

def key
  component[:key]
end

#oval_idsArray

Returns the oval ids of the component

Returns:

  • (Array)

    the oval ids of the component



75
76
77
# File 'lib/compliance_engine/component.rb', line 75

def oval_ids
  element['oval-ids']
end

#titleString

Returns the title of the component

Returns:

  • (String)

    the title of the component



61
62
63
# File 'lib/compliance_engine/component.rb', line 61

def title
  element['title']
end

#to_aArray

Returns an array of fragments from the component

Returns:

  • (Array)

    an array of fragments



40
41
42
# File 'lib/compliance_engine/component.rb', line 40

def to_a
  component[:fragments].values
end

#to_hHash

Returns the merged data from the component

Returns:

  • (Hash)

    merged data



47
48
49
# File 'lib/compliance_engine/component.rb', line 47

def to_h
  element
end