Class: DataMapper::Repository

### Home Classes Methods

### In Files

- lib/dm-core/repository.rb

### Parent

Object

### Methods

- ::adapters
- ::context
- ::default_name
- ::new
- #adapter
- #create
- #delete
- #identity_map
- #inspect
- #new_query
- #read
- #scope
- #update

### Included Modules

- DataMapper::Assertions

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- DataMapper
- DataMapper::Adapters
- DataMapper::Adapters::AbstractAdapter
- DataMapper::Adapters::InMemoryAdapter
- DataMapper::Assertions
- DataMapper::Associations
- DataMapper::Associations::ManyToMany
- DataMapper::Associations::ManyToMany::Collection
- DataMapper::Associations::ManyToMany::Relationship
- DataMapper::Associations::ManyToOne
- DataMapper::Associations::ManyToOne::Relationship
- DataMapper::Associations::OneToMany
- DataMapper::Associations::OneToMany::Collection
- DataMapper::Associations::OneToMany::Relationship
- DataMapper::Associations::OneToOne
- DataMapper::Associations::OneToOne::Relationship
- DataMapper::Associations::Relationship
- DataMapper::Chainable
- DataMapper::Collection
- DataMapper::Deprecate
- DataMapper::DescendantSet
- DataMapper::Equalizer
- DataMapper::Ext
- DataMapper::Ext::Array
- DataMapper::Ext::Hash
- DataMapper::Ext::Module
- DataMapper::Ext::Object
- DataMapper::Ext::String
- DataMapper::Hook
- DataMapper::Hook::ClassMethods
- DataMapper::IdentityMap
- DataMapper::ImmutableDeletedError
- DataMapper::ImmutableError
- DataMapper::IncompleteModelError
- DataMapper::Inflector
- DataMapper::Inflector::Inflections
- DataMapper::LocalObjectSpace
- DataMapper::Logger
- DataMapper::Mash
- DataMapper::Model
- DataMapper::Model::Hook
- DataMapper::Model::Hook::MethodCommand
- DataMapper::Model::Hook::Methods
- DataMapper::Model::Hook::ProcCommand
- DataMapper::Model::Is
- DataMapper::Model::Property
- DataMapper::Model::Relationship
- DataMapper::Model::Scope
- DataMapper::NamingConventions
- DataMapper::NamingConventions::Field
- DataMapper::NamingConventions::Field::Underscored
- DataMapper::NamingConventions::Field::UnderscoredAndPluralized
- DataMapper::NamingConventions::Field::UnderscoredAndPluralizedWithoutModule
- DataMapper::NamingConventions::Field::Yaml
- DataMapper::NamingConventions::Resource
- DataMapper::NamingConventions::Resource::Underscored
- DataMapper::NamingConventions::Resource::UnderscoredAndPluralized
- DataMapper::NamingConventions::Resource::UnderscoredAndPluralizedWithoutLeadingModule
- DataMapper::NamingConventions::Resource::UnderscoredAndPluralizedWithoutModule
- DataMapper::NamingConventions::Resource::Yaml
- DataMapper::ObjectNotFoundError
- DataMapper::OrderedSet
- DataMapper::OrderedSet::Cache
- DataMapper::OrderedSet::Cache::API
- DataMapper::PersistenceError
- DataMapper::PluginNotFoundError
- DataMapper::Property
- DataMapper::Property::Binary
- DataMapper::Property::Boolean
- DataMapper::Property::Class
- DataMapper::Property::Date
- DataMapper::Property::DateTime
- DataMapper::Property::Decimal
- DataMapper::Property::Discriminator
- DataMapper::Property::Discriminator::Model
- DataMapper::Property::Float
- DataMapper::Property::Integer
- DataMapper::Property::Lookup
- DataMapper::Property::Numeric
- DataMapper::Property::Object
- DataMapper::Property::PassThroughLoadDump
- DataMapper::Property::Serial
- DataMapper::Property::String
- DataMapper::Property::Text
- DataMapper::Property::Time
- DataMapper::Property::Typecast
- DataMapper::Property::Typecast::Numeric
- DataMapper::Property::Typecast::Time
- DataMapper::PropertySet
- DataMapper::Query
- DataMapper::Query::Conditions
- DataMapper::Query::Conditions::AbstractComparison
- DataMapper::Query::Conditions::AbstractOperation
- DataMapper::Query::Conditions::AndOperation
- DataMapper::Query::Conditions::Comparison
- DataMapper::Query::Conditions::EqualToComparison
- DataMapper::Query::Conditions::FlattenOperation
- DataMapper::Query::Conditions::GreaterThanComparison
- DataMapper::Query::Conditions::GreaterThanOrEqualToComparison
- DataMapper::Query::Conditions::InclusionComparison
- DataMapper::Query::Conditions::LessThanComparison
- DataMapper::Query::Conditions::LessThanOrEqualToComparison
- DataMapper::Query::Conditions::LikeComparison
- DataMapper::Query::Conditions::NotOperation
- DataMapper::Query::Conditions::NullOperation
- DataMapper::Query::Conditions::Operation
- DataMapper::Query::Conditions::OrOperation
- DataMapper::Query::Conditions::RegexpComparison
- DataMapper::Query::Conditions::RelationshipHandler
- DataMapper::Query::Direction
- DataMapper::Query::Operator
- DataMapper::Query::Path
- DataMapper::Query::Sort
- DataMapper::RelationshipSet
- DataMapper::Repository
- DataMapper::RepositoryNotSetupError
- DataMapper::Resource
- DataMapper::Resource::PersistenceState
- DataMapper::Resource::PersistenceState::Clean
- DataMapper::Resource::PersistenceState::Deleted
- DataMapper::Resource::PersistenceState::Dirty
- DataMapper::Resource::PersistenceState::Immutable
- DataMapper::Resource::PersistenceState::Persisted
- DataMapper::Resource::PersistenceState::Transient
- DataMapper::SaveFailureError
- DataMapper::Spec
- DataMapper::Spec::Adapters
- DataMapper::Spec::Adapters::Adapter
- DataMapper::Spec::Adapters::Helpers
- DataMapper::Spec::Adapters::InMemoryAdapter
- DataMapper::Spec::CollectionHelpers
- DataMapper::Spec::CollectionHelpers::GroupMethods
- DataMapper::Spec::Helpers
- DataMapper::Spec::PendingHelpers
- DataMapper::Subject
- DataMapper::SubjectSet
- DataMapper::SubjectSet::NameCache
- DataMapper::Undefined
- DataMapper::UnknownRelationshipError
- DataMapper::UnsavedParentError
- DataMapper::UpdateConflictError
- Blog
- Blog::Article
- ChildSubType
- CounterAdapter
- Heffalump
- Kernel
- LazyArray
- Object
- OtherComparison
- Pathname
- SubType
- Symbol

No matching classes.

# DataMapper::Repository

### Attributes

name[R]

@api semipublic

to_sym[R]

@api semipublic

### Public Class Methods

adapters() click to toggle source

Get the list of adapters registered for all Repositories, keyed by repository name.

    TODO: create example

@return [Hash(Symbol => Adapters::AbstractAdapter)]

    the adapters registered for all Repositories

@api private

    # File lib/dm-core/repository.rb, line 17
    def self.adapters
      @adapters ||= {}
    end

context() click to toggle source

Get the stack of current repository contexts

    TODO: create example

@return [Array]

    List of Repository contexts for the current Thread

@api private

    # File lib/dm-core/repository.rb, line 29
    def self.context
      Thread.current[:dm_repository_contexts] ||= []
    end

default_name() click to toggle source

Get the default name of this Repository

    TODO: create example

@return [Symbol]

    the default name of this repository

@api private

    # File lib/dm-core/repository.rb, line 41
    def self.default_name
      :default
    end

new(name) click to toggle source

Initializes a new Repository

    TODO: create example

@param [Symbol] name

    The name of the Repository

@api semipublic

    # File lib/dm-core/repository.rb, line 221
    def initialize(name)
      @name          = name.to_sym
      @identity_maps = {}
    end

### Public Instance Methods

adapter() click to toggle source

Get the adapter for this repository

Lazy loads adapter setup from registered adapters

    TODO: create example

@return [Adapters::AbstractAdapter]

    the adapter for this repository

@raise [RepositoryNotSetupError]

    if there is no adapter registered for a repository named @name

@api semipublic

    # File lib/dm-core/repository.rb, line 64
    def adapter
      # Make adapter instantiation lazy so we can defer repository setup until it's actually
      # needed. Do not remove this code.
      @adapter ||=
        begin
          adapters = self.class.adapters

          unless adapters.key?(@name)
            raise RepositoryNotSetupError, "Adapter not set: #{@name}. Did you forget to setup?"
          end

          adapters[@name]
        end
    end

create(resources) click to toggle source

Create one or more resource instances in this repository.

    TODO: create example

@param [Enumerable(Resource)] resources

    The list of resources (model instances) to create

@return [Integer]

    The number of records that were actually saved into the data-store

@api semipublic

    # File lib/dm-core/repository.rb, line 145
    def create(resources)
      adapter.create(resources)
    end

delete(collection) click to toggle source

Delete one or more resource instances

    TODO: create example

@param [Collection] collection

    collection of records to be deleted

@return [Integer]

    the number of records deleted

@api semipublic

    # File lib/dm-core/repository.rb, line 194
    def delete(collection)
      return 0 unless collection.query.valid?
      adapter.delete(collection)
    end

identity_map(model) click to toggle source

Get the identity for a particular model within this repository.

If one doesn't yet exist, create a new default in-memory IdentityMap for the requested model.

    TODO: create example

@param [Model] model

    Model whose identity map should be returned

@return [IdentityMap]

    The IdentityMap for model in this Repository

@api private

    # File lib/dm-core/repository.rb, line 93
    def identity_map(model)
      @identity_maps[model.base_model] ||= IdentityMap.new
    end

inspect() click to toggle source

Return a human readable representation of the repository

    TODO: create example

@return [String]

    human readable representation of the repository

@api private

    # File lib/dm-core/repository.rb, line 207
    def inspect
      "#<#{self.class.name} @name=#{@name}>"
    end

new_query(model, options = {}) click to toggle source

Create a Query or subclass instance for this repository.

@param [Model] model

    the Model to retrieve results from

@param [Hash] options

    the conditions and scope

@return [Query]

@api semipublic

    # File lib/dm-core/repository.rb, line 130
    def new_query(model, options = {})
      adapter.new_query(self, model, options)
    end

read(query) click to toggle source

Retrieve a collection of results of a query

    TODO: create example

@param [Query] query

    composition of the query to perform

@return [Array]

    result set of the query

@api semipublic

    # File lib/dm-core/repository.rb, line 160
    def read(query)
      return [] unless query.valid?
      query.model.load(adapter.read(query), query)
    end

scope() click to toggle source

Executes a block in the scope of this Repository

    TODO: create example

@yieldparam [Repository] repository

    yields self within the block

@yield

    execute block in the scope of this Repository

@api private

    # File lib/dm-core/repository.rb, line 108
    def scope
      context = Repository.context

      context << self

      begin
        yield self
      ensure
        context.pop
      end
    end

update(attributes, collection) click to toggle source

Update the attributes of one or more resource instances

    TODO: create example

@param [Hash(Property => Object)] attributes

    hash of attribute values to set, keyed by Property

@param [Collection] collection

    collection of records to be updated

@return [Integer]

    the number of records updated

@api semipublic

    # File lib/dm-core/repository.rb, line 178
    def update(attributes, collection)
      return 0 unless collection.query.valid? && attributes.any?
      adapter.update(attributes, collection)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.