Class: Appfuel::Repository::MappingCollection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection = {}) ⇒ MappingCollection

Returns a new instance of MappingCollection.



6
7
8
9
# File 'lib/appfuel/storage/repository/mapping_collection.rb', line 6

def initialize(collection = {})
  @collection = collection
  fail "collection must be a hash" unless collection.is_a?(Hash)
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



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

def collection
  @collection
end

Instance Method Details

#container_name(type, domain_name) ⇒ Object



37
38
39
40
# File 'lib/appfuel/storage/repository/mapping_collection.rb', line 37

def container_name(type, domain_name)
  map = storage_map(type, domain_name)
  map.container_name
end

#each_attr(type, domain_name, &block) ⇒ Object



42
43
44
45
# File 'lib/appfuel/storage/repository/mapping_collection.rb', line 42

def each_attr(type, domain_name, &block)
  map = storage_map(type, domain_name)
  map.each(&block)
end

#entity?(domain_name) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/appfuel/storage/repository/mapping_collection.rb', line 23

def entity?(domain_name)
  collection.key?(domain_name)
end

#load(storage_map) ⇒ Object

map {

domain_name => {
 type => map
}

}



16
17
18
19
20
21
# File 'lib/appfuel/storage/repository/mapping_collection.rb', line 16

def load(storage_map)
  domain_name  = storage_map.domain_name
  storage_type = storage_map.storage_type
  collection[domain_name] = {} unless  collection.key?(domain_name)
  collection[domain_name][storage_type] = storage_map
end

#storage_attr(type, domain_name, domain_attr) ⇒ Object



27
28
29
30
# File 'lib/appfuel/storage/repository/mapping_collection.rb', line 27

def storage_attr(type, domain_name, domain_attr)
  map = storage_map(type, domain_name)
  map.storage_attr(domain_attr)
end

#storage_key(type, domain_name) ⇒ Object



32
33
34
35
# File 'lib/appfuel/storage/repository/mapping_collection.rb', line 32

def storage_key(type, domain_name)
  map = storage_map(type, domain_name)
  map.storage_key
end

#storage_map(type, domain_name) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/appfuel/storage/repository/mapping_collection.rb', line 47

def storage_map(type, domain_name)
  unless entity?(domain_name)
    fail "#{domain_name} is not registered in map"
  end

  unless collection[domain_name].key?(type)
    fail "#{domain_name} storage #{type} is not registered in map"
  end

  collection[domain_name][type]
end