Sha256: f7dd305f34290fe4101a2f8017a175dc9d6dae414b1fd3563cff0af15cb515a8

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

# encoding: utf-8

module ROM

  # A repository with a given +name+ and +adapter+
  #
  # @api private
  class Repository
    include Concord.new(:name, :adapter, :relations)

    # Build a repository with a given +name+ and +uri+
    #
    # @param [Symbol] name
    #   the repository's name
    #
    # @param [Addressable::URI] uri
    #   the uri for initializing the adapter
    #
    # @return [Repository]
    #
    # @api private
    def self.build(name, uri, relations = {})
      new(name, Axiom::Adapter.build(uri), relations)
    end

    # Return the relation identified by +name+
    #
    # @example
    #
    #   repo = Repository.coerce(:test, 'in_memory://test')
    #   repo.register(:foo, [[:id, String], [:foo, String]])
    #   repo[:foo]
    #
    #   # => <Axiom::Relation header=Axiom::Header ...>
    #
    # @param [Symbol] name
    #   the name of the relation
    #
    # @return [Axiom::Relation]
    #
    # @raise [KeyError]
    #
    # @api public
    def [](name)
      relations.fetch(name)
    end

    # Register a relation with this repository
    #
    # @param [Axiom::Relation::Base] relation
    #
    # @return [Object] relation gateway
    #
    # @api public
    def []=(name, relation)
      adapter[name]   = relation
      relations[name] = adapter[name]
    end

  end # Repository

end # ROM

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rom-relation-0.1.2 lib/rom/repository.rb
rom-relation-0.1.1 lib/rom/repository.rb
rom-relation-0.1.0 lib/rom/repository.rb