Class: CemSpecHelper::ResourceDataSpec::Resource
- Inherits:
-
Object
- Object
- CemSpecHelper::ResourceDataSpec::Resource
- Defined in:
- lib/cem_spec_helper/resource_data_spec.rb
Overview
The Resource class represents a single resource from the resource data file
Instance Attribute Summary collapse
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#controls(include_special: true) ⇒ Array<String>
An array of control names implemented by the resource.
-
#initialize(title, data) ⇒ Resource
constructor
A new instance of Resource.
-
#params ⇒ Hash
A hash of parameter names => default values.
-
#verify_no_duplicate_controls ⇒ TrueClass, FalseClass
Whether or not the resource has any duplicate control names.
Constructor Details
#initialize(title, data) ⇒ Resource
Returns a new instance of Resource.
246 247 248 249 250 251 252 |
# File 'lib/cem_spec_helper/resource_data_spec.rb', line 246 def initialize(title, data) @title = title @data = data @type = @data['type'] @no_params = false @control_data = load_control_data end |
Instance Attribute Details
#title ⇒ Object (readonly)
Returns the value of attribute title.
242 243 244 |
# File 'lib/cem_spec_helper/resource_data_spec.rb', line 242 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
242 243 244 |
# File 'lib/cem_spec_helper/resource_data_spec.rb', line 242 def type @type end |
Instance Method Details
#controls(include_special: true) ⇒ Array<String>
Returns An array of control names implemented by the resource.
256 257 258 259 260 261 |
# File 'lib/cem_spec_helper/resource_data_spec.rb', line 256 def controls(include_special: true) ctrls = @no_params ? @control_data : @control_data.keys return ctrls if include_special ctrls.reject { |c| SPECIAL_CONTROLS.include?(c) } end |
#params ⇒ Hash
Returns A hash of parameter names => default values.
264 265 266 267 268 |
# File 'lib/cem_spec_helper/resource_data_spec.rb', line 264 def params # rubocop:disable Style/CollectionMethods control_data.map { |_, v| v if v.is_a?(Hash) }.flatten.compact.uniq.inject(:merge) # rubocop:enable Style/CollectionMethods end |
#verify_no_duplicate_controls ⇒ TrueClass, FalseClass
Returns Whether or not the resource has any duplicate control names.
271 272 273 |
# File 'lib/cem_spec_helper/resource_data_spec.rb', line 271 def verify_no_duplicate_controls controls.uniq == controls end |