Class: AbideDevUtils::CEM::Control

Inherits:
Object
  • Object
show all
Includes:
DotNumberComparable
Defined in:
lib/abide_dev_utils/cem/benchmark.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.



153
154
155
156
157
158
159
160
161
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 153

def initialize(id, params, resource, framework, mapper)
  validate_id_with_framework(id, framework, mapper)
  @id = id
  @params = 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



224
225
226
227
228
229
230
231
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 224

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

Instance Attribute Details

#dependentObject (readonly)

Returns the value of attribute dependent.



151
152
153
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 151

def dependent
  @dependent
end

#frameworkObject (readonly)

Returns the value of attribute framework.



151
152
153
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 151

def framework
  @framework
end

#idObject (readonly)

Returns the value of attribute id.



151
152
153
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 151

def id
  @id
end

#paramsObject (readonly)

Returns the value of attribute params.



151
152
153
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 151

def params
  @params
end

#resourceObject (readonly)

Returns the value of attribute resource.



151
152
153
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 151

def resource
  @resource
end

Instance Method Details

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



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 181

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



201
202
203
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 201

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

#id_map_typeObject



197
198
199
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 197

def id_map_type
  @mapper.map_type(id)
end

#levelsObject



205
206
207
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 205

def levels
  levels_and_profiles[0]
end

#param_hashesObject



171
172
173
174
175
176
177
178
179
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 171

def param_hashes
  return [no_params] unless params?

  params.each_with_object([]) do |(param, param_val), ar|
    ar << { name: param,
            type: ruby_class_to_puppet_type(param_val.class.to_s),
            default: param_val }
  end
end

#params?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 163

def params?
  !(params.nil? || params.empty? || params == 'no_params') || (resource.cem_options? || resource.cem_protected?)
end

#profilesObject



209
210
211
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 209

def profiles
  levels_and_profiles[1]
end

#resource_properties?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 167

def resource_properties?
  resource.cem_options? || resource.cem_protected?
end

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

Returns:

  • (Boolean)


233
234
235
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 233

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

#to_hObject



237
238
239
240
241
242
243
244
245
246
247
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 237

def to_h
  {
    id: id,
    display_title: display_title,
    alternate_ids: alternate_ids,
    levels: levels,
    profiles: profiles,
    params: param_hashes,
    resource: resource.to_stubbed_h,
  }
end

#valid_maps?Boolean

Returns:

  • (Boolean)


213
214
215
216
217
218
219
220
221
222
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 213

def valid_maps?
  valid = AbideDevUtils::CEM::Mapping::FRAMEWORK_TYPES[framework].each_with_object([]) do |mtype, arr|
    arr << if @mapper.map_type(id) == mtype
             id
           else
             @mapper.get(id).find { |x| @mapper.map_type(x) == mtype }
           end
  end
  valid.compact.length == AbideDevUtils::CEM::Mapping::FRAMEWORK_TYPES[framework].length
end