Class: AbideDevUtils::CEM::Control
- Inherits:
-
Object
- Object
- AbideDevUtils::CEM::Control
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
#<=>, #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.
148
149
150
151
152
153
154
155
156
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 148
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
219
220
221
222
223
224
225
226
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 219
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
#dependent ⇒ Object
Returns the value of attribute dependent.
146
147
148
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 146
def dependent
@dependent
end
|
#framework ⇒ Object
Returns the value of attribute framework.
146
147
148
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 146
def framework
@framework
end
|
#id ⇒ Object
Returns the value of attribute id.
146
147
148
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 146
def id
@id
end
|
#params ⇒ Object
Returns the value of attribute params.
146
147
148
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 146
def params
@params
end
|
#resource ⇒ Object
Returns the value of attribute resource.
146
147
148
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 146
def resource
@resource
end
|
Instance Method Details
#alternate_ids(level: nil, profile: nil) ⇒ Object
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 176
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_title ⇒ Object
196
197
198
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 196
def display_title
send(display_title_type) unless display_title_type.nil?
end
|
#id_map_type ⇒ Object
192
193
194
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 192
def id_map_type
@mapper.map_type(id)
end
|
#levels ⇒ Object
200
201
202
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 200
def levels
levels_and_profiles[0]
end
|
#param_hashes ⇒ Object
166
167
168
169
170
171
172
173
174
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 166
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
158
159
160
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 158
def params?
!(params.nil? || params.empty? || params == 'no_params') || (resource.cem_options? || resource.cem_protected?)
end
|
#profiles ⇒ Object
204
205
206
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 204
def profiles
levels_and_profiles[1]
end
|
#resource_properties? ⇒ Boolean
162
163
164
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 162
def resource_properties?
resource.cem_options? || resource.cem_protected?
end
|
#respond_to_missing?(meth, include_private = false) ⇒ Boolean
228
229
230
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 228
def respond_to_missing?(meth, include_private = false)
AbideDevUtils::CEM::Mapping::ALL_TYPES.include?(meth.to_s) || super
end
|
#to_h ⇒ Object
232
233
234
235
236
237
238
239
240
241
242
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 232
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
208
209
210
211
212
213
214
215
216
217
|
# File 'lib/abide_dev_utils/cem/benchmark.rb', line 208
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
|