Class: AbideDevUtils::Sce::Control
  
  
  
  
  
    - Inherits:
 
    - 
      Object
      
        
          - Object
 
          
            - AbideDevUtils::Sce::Control
 
          
        
        show all
      
     
  
  
  
  
  
  
  
      - Includes:
 
      - DotNumberComparable
 
  
  
  
  
  
  
    - Defined in:
 
    - lib/abide_dev_utils/sce/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.
   
 
  
    
      
153
154
155
156
157
158
159
160
161
162 
     | 
    
      # File 'lib/abide_dev_utils/sce/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
  @profiles_levels = find_levels_and_profiles
  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 
  
  
  
  
    
      
251
252
253
254
255
256
257
258 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 251
def method_missing(meth, *args, &block)
  meth_s = meth.to_s
  if AbideDevUtils::Sce::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.
   
 
  
  
    
      
151
152
153 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 151
def dependent
  @dependent
end 
     | 
  
 
    
      
      
      
  
  
    #framework  ⇒ Object  
  
  
  
  
    
Returns the value of attribute framework.
   
 
  
  
    
      
151
152
153 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 151
def framework
  @framework
end 
     | 
  
 
    
      
      
      
  
  
    #id  ⇒ Object  
  
  
  
  
    
Returns the value of attribute id.
   
 
  
  
    
      
151
152
153 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 151
def id
  @id
end 
     | 
  
 
    
      
      
      
  
  
    #params  ⇒ Object  
  
  
  
  
    
Returns the value of attribute params.
   
 
  
  
    
      
151
152
153 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 151
def params
  @params
end 
     | 
  
 
    
      
      
      
  
  
    #profiles_levels  ⇒ Object  
  
  
  
  
    
Returns the value of attribute profiles_levels.
   
 
  
  
    
      
151
152
153 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 151
def profiles_levels
  @profiles_levels
end 
     | 
  
 
    
      
      
      
  
  
    #resource  ⇒ Object  
  
  
  
  
    
Returns the value of attribute resource.
   
 
  
  
    
      
151
152
153 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 151
def resource
  @resource
end 
     | 
  
 
    
   
  
    Instance Method Details
    
      
  
  
    #alternate_ids(level: nil, profile: nil)  ⇒ Object 
  
  
  
  
    
      
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 182
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 
  
  
  
  
    
      
202
203
204 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 202
def display_title
  send(display_title_type) unless display_title_type.nil?
end 
     | 
  
 
    
      
  
  
    #filtered_profiles_levels(prof: nil, lvl: nil)  ⇒ Object 
  
  
  
  
    
      
222
223
224
225
226
227
228
229
230 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 222
def filtered_profiles_levels(prof: nil, lvl: nil)
  return profiles_levels if (prof.nil? || prof.empty?) && (lvl.nil? || lvl.empty?)
  if prof && lvl && !prof.empty? && !lvl.empty?
    return profiles_levels_by_profile(prof).concat(profiles_levels_by_level(lvl))
  end
  return profiles_levels_by_profile(prof) unless prof&.empty?
  profiles_levels_by_level(lvl)
end
     | 
  
 
    
      
  
  
    #id_map_type  ⇒ Object 
  
  
  
  
    
      
198
199
200 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 198
def id_map_type
  @mapper.map_type(id)
end 
     | 
  
 
    
      
  
  
    #levels  ⇒ Object 
  
  
  
  
    
      
232
233
234 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 232
def levels
  profiles_levels.map { |plstr| plstr.split(';;;', 2).last }
end
     | 
  
 
    
      
  
  
    #param_hashes  ⇒ Object 
  
  
  
  
    
      
172
173
174
175
176
177
178
179
180 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 172
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 
  
  
  
  
    
      
164
165
166 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 164
def params?
  !(params.nil? || params.empty? || params == 'no_params') || (resource.sce_options? || resource.sce_protected?)
end 
     | 
  
 
    
      
  
  
    #profiles  ⇒ Object 
  
  
  
  
    
      
236
237
238 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 236
def profiles
  profiles_levels.map { |plstr| plstr.split(';;;', 2).first }
end
     | 
  
 
    
      
  
  
    #profiles_levels_by_level(lvl)  ⇒ Object 
  
  
  
  
    
      
206
207
208
209
210
211
212 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 206
def profiles_levels_by_level(lvl)
  pls = profiles_levels.map do |plstr|
    _, l = plstr.split(';;;', 2)
    plstr if l == lvl || (lvl.is_a?(Array) && lvl.include?(l))
  end
  pls.compact.uniq
end
     | 
  
 
    
      
  
  
    #profiles_levels_by_profile(prof)  ⇒ Object 
  
  
  
  
    
      
214
215
216
217
218
219
220 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 214
def profiles_levels_by_profile(prof)
  pls = profiles_levels.map do |plstr|
    p, = plstr.split(';;;', 2)
    plstr if p == prof || (prof.is_a?(Array) && prof.include?(p))
  end
  pls.compact.uniq
end
     | 
  
 
    
      
  
  
    #resource_properties?  ⇒ Boolean 
  
  
  
  
    
      
168
169
170 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 168
def resource_properties?
  resource.sce_options? || resource.sce_protected?
end 
     | 
  
 
    
      
  
  
    #respond_to_missing?(meth, include_private = false)  ⇒ Boolean 
  
  
  
  
    
      
260
261
262 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 260
def respond_to_missing?(meth, include_private = false)
  AbideDevUtils::Sce::Mapping::ALL_TYPES.include?(meth.to_s) || super
end 
     | 
  
 
    
      
  
  
    #to_h  ⇒ Object 
  
  
  
  
    
      
264
265
266
267
268
269
270
271
272
273
274 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 264
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 
  
  
  
  
    
      
240
241
242
243
244
245
246
247
248
249 
     | 
    
      # File 'lib/abide_dev_utils/sce/benchmark.rb', line 240
def valid_maps?
  valid = AbideDevUtils::Sce::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::Sce::Mapping::FRAMEWORK_TYPES[framework].length
end
     |