Class: AbideDevUtils::CEM::HieraData::ResourceData::Control

Inherits:
Object
  • Object
show all
Includes:
DotNumberComparable
Defined in:
lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb

Overview

Represents a singular rule in a benchmark

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DotNumberComparable

#<=>, #number_child_of?, #number_eq, #number_gt, #number_lt, #number_parent_of?

Constructor Details

#initialize(id, params, resource, framework, mapper) ⇒ Control

Returns a new instance of Control.



17
18
19
20
21
22
23
24
25
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb', line 17

def initialize(id, params, resource, framework, mapper)
  validate_id_with_framework(id, framework, mapper)
  @id = id
  @parameters = Parameters.new(params)
  @resource = resource
  @framework = framework
  @mapper = mapper
  raise AbideDevUtils::Errors::NoMappingDataForControlError, @id unless @mapper.get(id)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb', line 59

def method_missing(meth, *args, &block)
  meth_s = meth.to_s
  if AbideDevUtils::CEM::HieraData::MappingData::ALL_TYPES.include?(meth_s)
    @mapper.get(id).find { |x| @mapper.map_type(x) == meth_s }
  else
    super
  end
end

Instance Attribute Details

#frameworkObject (readonly)

Returns the value of attribute framework.



15
16
17
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb', line 15

def framework
  @framework
end

#idObject (readonly)

Returns the value of attribute id.



15
16
17
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb', line 15

def id
  @id
end

#parametersObject (readonly)

Returns the value of attribute parameters.



15
16
17
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb', line 15

def parameters
  @parameters
end

#resourceObject (readonly)

Returns the value of attribute resource.



15
16
17
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb', line 15

def resource
  @resource
end

Instance Method Details

#alternate_ids(level: nil, profile: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb', line 27

def alternate_ids(level: nil, profile: nil)
  id_map = @mapper.get(id, level: level, profile: profile)
  if display_title_type.to_s == @mapper.map_type(id)
    id_map
  else
    alt_ids = id_map.each_with_object([]) do |mapval, arr|
      arr << if display_title_type.to_s == @mapper.map_type(mapval)
               @mapper.get(mapval, level: level, profile: profile)
             else
               mapval
             end
    end
    alt_ids.flatten.uniq
  end
end

#display_titleObject



47
48
49
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb', line 47

def display_title
  send(display_title_type) unless display_title_type.nil?
end

#id_map_typeObject



43
44
45
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb', line 43

def id_map_type
  @mapper.map_type(id)
end

#levelsObject



51
52
53
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb', line 51

def levels
  levels_and_profiles[0]
end

#profilesObject



55
56
57
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb', line 55

def profiles
  levels_and_profiles[1]
end

#respond_to_missing?(meth, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb', line 68

def respond_to_missing?(meth, include_private = false)
  AbideDevUtils::CEM::HieraData::MappingData::ALL_TYPES.include?(meth.to_s) || super
end

#to_hObject



72
73
74
75
76
77
78
79
80
81
# File 'lib/abide_dev_utils/cem/hiera_data/resource_data/control.rb', line 72

def to_h
  {
    id: id,
    display_title: display_title,
    alternate_ids: alternate_ids,
    levels: levels,
    profiles: profiles,
    resource: resource,
  }.merge(parameters.to_h)
end