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 17: def self.adapters 18: @adapters ||= {} 19: end
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 29: def self.context 30: Thread.current[:dm_repository_contexts] ||= [] 31: end
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 41: def self.default_name 42: :default 43: end
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 221: def initialize(name) 222: @name = name.to_sym 223: @identity_maps = {} 224: end
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 64: def adapter 65: # Make adapter instantiation lazy so we can defer repository setup until it's actually 66: # needed. Do not remove this code. 67: @adapter ||= 68: begin 69: adapters = self.class.adapters 70: 71: unless adapters.key?(@name) 72: raise RepositoryNotSetupError, "Adapter not set: #{@name}. Did you forget to setup?" 73: end 74: 75: adapters[@name] 76: end 77: end
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 145: def create(resources) 146: adapter.create(resources) 147: end
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 194: def delete(collection) 195: return 0 unless collection.query.valid? 196: adapter.delete(collection) 197: end
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 93: def identity_map(model) 94: @identity_maps[model.base_model] ||= IdentityMap.new 95: end
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 207: def inspect 208: "#<#{self.class.name} @name=#{@name}>" 209: end
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 130: def new_query(model, options = {}) 131: adapter.new_query(self, model, options) 132: end
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 160: def read(query) 161: return [] unless query.valid? 162: query.model.load(adapter.read(query), query) 163: end
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 108: def scope 109: context = Repository.context 110: 111: context << self 112: 113: begin 114: yield self 115: ensure 116: context.pop 117: end 118: end
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 178: def update(attributes, collection) 179: return 0 unless collection.query.valid? && attributes.any? 180: adapter.update(attributes, collection) 181: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.