Class: CemSpecHelper::MappingDataSpec::Mapping

Inherits:
Object
  • Object
show all
Defined in:
lib/cem_spec_helper/mapping_data_spec.rb

Overview

This class represents a mapping of a framework, OS, and major OS version.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(framework, os, majver) ⇒ Mapping

Returns a new instance of Mapping.

Parameters:

  • framework (String)

    The framework to create the mapping for

  • os (String)

    The OS to create the mapping for

  • majver (String)

    The major OS version to create the mapping for



127
128
129
130
131
132
133
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 127

def initialize(framework, os, majver)
  @framework = framework
  @os = os
  @majver = majver
  @module_name = CemSpecHelper::MODULE_NAME
  @maps = {}
end

Instance Attribute Details

#frameworkObject (readonly)

Returns the value of attribute framework.



122
123
124
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 122

def framework
  @framework
end

#majverObject (readonly)

Returns the value of attribute majver.



122
123
124
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 122

def majver
  @majver
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



122
123
124
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 122

def module_name
  @module_name
end

#osObject (readonly)

Returns the value of attribute os.



122
123
124
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 122

def os
  @os
end

Instance Method Details

#add_map(type, map_file) ⇒ Object

Add a map to the mapping

Parameters:

  • type (String)

    The type of map to add

  • map_file (String)

    The path to the map file to add



143
144
145
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 143

def add_map(type, map_file)
  @maps[type] = YAML.load_file(map_file)
end

#map_typesArray<String>

Returns An array of the map types.

Returns:

  • (Array<String>)

    An array of the map types



148
149
150
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 148

def map_types
  @maps.keys
end

#mapsArray<Hash>

Returns An array of hashes representing the maps.

Returns:

  • (Array<Hash>)

    An array of hashes representing the maps



136
137
138
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 136

def maps
  @maps.values
end

#to_sString

Returns A string representation of the mapping.

Returns:

  • (String)

    A string representation of the mapping



190
191
192
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 190

def to_s
  "Mapping[#{framework}, #{os}, #{majver}]"
end

#verify_map_size(keys_with_array_val = find_keys_with_array_val(@maps.dup)) ⇒ TrueClass

Verify that all the mappings have the same size

Parameters:

  • keys_with_array_val (Hash) (defaults to: find_keys_with_array_val(@maps.dup))

    A hash of keys with array values

Returns:

  • (TrueClass)

    True if all the mappings have the same size

Raises:

  • (RuntimeError)

    If the mappings do not have the same size



156
157
158
159
160
161
162
163
164
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 156

def verify_map_size(keys_with_array_val = find_keys_with_array_val(@maps.dup))
  result = keys_with_array_val.each_with_object([]) do |(id, map), res|
    actual_length = 1 + map.length
    res << id if actual_length != map_types.length
  end
  raise "IDs with incorrect map size:\n#{result.join("\n")}" unless result.empty?

  true
end

#verify_one_to_oneTrueClass

Verify that all mappings are one-to-one, or that there are no duplicate IDs shared between maps.

Returns:

  • (TrueClass)

    True if all mappings are one-to-one

Raises:

  • (RuntimeError)

    If there are duplicate IDs shared between maps



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 170

def verify_one_to_one
  results = @maps.keys.each_with_object([]) do |t, arr|
    keys_with_array_val = find_keys_with_array_val(@maps[t])
    keys_with_array_val.each do |k, v|
      keys_with_array_val.each do |o_k, o_v|
        next if o_k == k

        diff = v - o_v
        arr << k if diff.length < v.length
      end
    end
  end
  results.compact!
  results.uniq!
  raise "IDs with one-to-many or many-to-many relationships:\n#{results.join("\n")}" unless results.empty?

  true
end