Class: Appfuel::Repository::StorageMap

Inherits:
Object
  • Object
show all
Defined in:
lib/appfuel/storage/repository/storage_map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ StorageMap

Returns a new instance of StorageMap.



7
8
9
10
11
12
13
14
15
# File 'lib/appfuel/storage/repository/storage_map.rb', line 7

def initialize(data)
  fail "Mapping data must be a hash" unless data.is_a?(Hash)

  @container_name = data[:container]
  @domain_name    = data.fetch(:domain_name)  { domain_name_failure }.to_s
  @storage_type   = data.fetch(:storage_type) { storage_type_failure }
  @storage_key    = data.fetch(:storage_key)  { storage_key_failure }
  @entries        = data.fetch(:entries)      { entries_failure }
end

Instance Attribute Details

#container_nameObject (readonly)

Returns the value of attribute container_name.



4
5
6
# File 'lib/appfuel/storage/repository/storage_map.rb', line 4

def container_name
  @container_name
end

#domain_nameObject (readonly)

Returns the value of attribute domain_name.



4
5
6
# File 'lib/appfuel/storage/repository/storage_map.rb', line 4

def domain_name
  @domain_name
end

#entriesObject (readonly)

Returns the value of attribute entries.



4
5
6
# File 'lib/appfuel/storage/repository/storage_map.rb', line 4

def entries
  @entries
end

#storage_keyObject (readonly)

Returns the value of attribute storage_key.



4
5
6
# File 'lib/appfuel/storage/repository/storage_map.rb', line 4

def storage_key
  @storage_key
end

#storage_typeObject (readonly)

Returns the value of attribute storage_type.



4
5
6
# File 'lib/appfuel/storage/repository/storage_map.rb', line 4

def storage_type
  @storage_type
end

Instance Method Details

#domain_attr(storage_attr) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/appfuel/storage/repository/storage_map.rb', line 25

def domain_attr(storage_attr)
  entries.each do |data|
     return data[:domain_attr] if data[:storage_attr] == storage_attr
  end

  fail "[storage_map #{domain_name}] #{storage_attr} not registered"
end

#eachObject



33
34
35
36
37
# File 'lib/appfuel/storage/repository/storage_map.rb', line 33

def each
  entries.each do |data|
    yield data[:domain_attr], data[:storage_attr], data[:skip]
  end
end

#storage_attr(domain_attr) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/appfuel/storage/repository/storage_map.rb', line 17

def storage_attr(domain_attr)
  entries.each do |data|
     return data[:storage_attr] if data[:domain_attr] == domain_attr
  end

  fail "[storage_map #{domain_name}] #{domain_attr} not registered"
end