Class: CemSpecHelper::MappingDataSpec::Mapping

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(framework, os, majver, module_name: 'cem_linux') ⇒ Mapping

Returns a new instance of Mapping.



57
58
59
60
61
62
63
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 57

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

Instance Attribute Details

#frameworkObject (readonly)

Returns the value of attribute framework.



55
56
57
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 55

def framework
  @framework
end

#majverObject (readonly)

Returns the value of attribute majver.



55
56
57
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 55

def majver
  @majver
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



55
56
57
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 55

def module_name
  @module_name
end

#osObject (readonly)

Returns the value of attribute os.



55
56
57
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 55

def os
  @os
end

Instance Method Details

#add_map(type, map_file) ⇒ Object



69
70
71
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 69

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

#map_typesObject



73
74
75
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 73

def map_types
  @maps.keys
end

#mapsObject



65
66
67
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 65

def maps
  @maps.values
end

#to_sObject



106
107
108
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 106

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

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



77
78
79
80
81
82
83
84
85
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 77

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_oneObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cem_spec_helper/mapping_data_spec.rb', line 87

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