Sha256: 4d3daed4ca35978a7e84b5ff0e344c7f8c2b7e243a763e6c373b428f075a1794

Contents?: true

Size: 1.51 KB

Versions: 33

Compression:

Stored size: 1.51 KB

Contents

module Appfuel
  module Repository
    class MappingCollection
      attr_reader :collection

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

      # map {
      #  domain_name => {
      #   type => map
      #  }
      # }
      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

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

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

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

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

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

      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
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
appfuel-0.7.0 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.6.16 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.6.15 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.6.14 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.6.13 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.6.12 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.6.11 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.6.10 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.6.9 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.6.8 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.6.7 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.6.6 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.6.5 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.6.4 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.6.3 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.6.1 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.5.16 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.5.15 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.5.14 lib/appfuel/storage/repository/mapping_collection.rb
appfuel-0.5.13 lib/appfuel/storage/repository/mapping_collection.rb