Class: CemSpecHelper::ResourceDataSpec::Resource

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(title, data) ⇒ Resource

Returns a new instance of Resource.

Parameters:

  • title (String)

    The title of the resource

  • data (Hash)

    The resource data



231
232
233
234
235
236
237
# File 'lib/cem_spec_helper/resource_data_spec.rb', line 231

def initialize(title, data)
  @title = title
  @data = data
  @type = @data['type']
  @no_params = false
  @control_data = load_control_data
end

Instance Attribute Details

#titleObject (readonly)

Returns the value of attribute title.



227
228
229
# File 'lib/cem_spec_helper/resource_data_spec.rb', line 227

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



227
228
229
# File 'lib/cem_spec_helper/resource_data_spec.rb', line 227

def type
  @type
end

Instance Method Details

#controls(include_special: true) ⇒ Array<String>

Returns An array of control names implemented by the resource.

Parameters:

  • include_special (Boolean) (defaults to: true)

    Whether or not to include special controls (sce_options, sce_protected)

Returns:

  • (Array<String>)

    An array of control names implemented by the resource



241
242
243
244
245
246
# File 'lib/cem_spec_helper/resource_data_spec.rb', line 241

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

#paramsHash

Returns A hash of parameter names => default values.

Returns:

  • (Hash)

    A hash of parameter names => default values



249
250
251
252
253
# File 'lib/cem_spec_helper/resource_data_spec.rb', line 249

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_controlsTrueClass, FalseClass

Returns Whether or not the resource has any duplicate control names.

Returns:

  • (TrueClass, FalseClass)

    Whether or not the resource has any duplicate control names



256
257
258
# File 'lib/cem_spec_helper/resource_data_spec.rb', line 256

def verify_no_duplicate_controls
  controls.uniq == controls
end