Module: PersistentMap::Extend

Included in:
HammerCLIImport::BaseCommand
Defined in:
lib/hammer_cli_import/persistentmap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#map_descriptionObject (readonly)

Returns the value of attribute map_description.



67
68
69
# File 'lib/hammer_cli_import/persistentmap.rb', line 67

def map_description
  @map_description
end

#map_target_entityObject (readonly)

Returns the value of attribute map_target_entity.



67
68
69
# File 'lib/hammer_cli_import/persistentmap.rb', line 67

def map_target_entity
  @map_target_entity
end

#mapsObject (readonly)

Returns the value of attribute maps.



67
68
69
# File 'lib/hammer_cli_import/persistentmap.rb', line 67

def maps
  @maps
end

Instance Method Details

#persistent_map(symbol) ⇒ Object

Raises:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/hammer_cli_import/persistentmap.rb', line 69

def persistent_map(symbol)
  defs = PersistentMap.definitions

  raise PersistentMapError, "Unknown persistent map: #{symbol}" unless defs.key? symbol

  # Names of persistent maps
  @maps ||= []
  @maps.push symbol

  key_spec, val_spec, target_entity = defs[symbol]

  # Which entities they are mapped to?
  # Usually they are mapped to the same entities on Sat6 (speaking of api)
  # But sometimes you need to create same type of Sat6 entities based on
  # different Sat5 entities, and then it is time for this extra option.
  @map_target_entity ||= {}
  @map_target_entity[symbol] = target_entity

  # How keys and values looks like (so they can be nicely stored)
  @map_description ||= {}
  @map_description[symbol] = [key_spec, val_spec]
end

#persistent_maps(*list) ⇒ Object

Raises:



92
93
94
95
96
97
# File 'lib/hammer_cli_import/persistentmap.rb', line 92

def persistent_maps(*list)
  raise PersistentMapError, 'Persistent maps should be declared only once' if @maps
  list.each do |map_sym|
    persistent_map map_sym
  end
end