Class: DataMapper::Repository
- Inherits:
-
Object
- Object
- DataMapper::Repository
- Extended by:
- Equalizer
- Includes:
- Assertions
- Defined in:
- lib/dm-core/repository.rb
Instance Attribute Summary (collapse)
- - (Object) name (also: #to_sym) readonly
Class Method Summary (collapse)
-
+ (Hash(Symbol => Adapters::AbstractAdapter)) adapters
private
Get the list of adapters registered for all Repositories, keyed by repository name.
-
+ (Array) context
private
Get the stack of current repository contexts.
-
+ (Symbol) default_name
private
Get the default name of this Repository.
Instance Method Summary (collapse)
-
- (Adapters::AbstractAdapter) adapter
Get the adapter for this repository.
-
- (Integer) create(resources)
Create one or more resource instances in this repository.
-
- (Integer) delete(collection)
Delete one or more resource instances.
-
- (IdentityMap) identity_map(model)
private
Get the identity for a particular model within this repository.
-
- (String) inspect
private
Return a human readable representation of the repository.
-
- (Query) new_query(model, options = {})
Create a Query or subclass instance for this repository.
-
- (Array) read(query)
Retrieve a collection of results of a query.
-
- (Object) scope {|repository| ... }
private
Executes a block in the scope of this Repository.
-
- (Integer) update(attributes, collection)
Update the attributes of one or more resource instances.
Methods included from Equalizer
Methods included from Assertions
Instance Attribute Details
- (Object) name (readonly) Also known as: to_sym
46 47 48 |
# File 'lib/dm-core/repository.rb', line 46 def name @name end |
Class Method Details
+ (Hash(Symbol => Adapters::AbstractAdapter)) adapters
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the list of adapters registered for all Repositories, keyed by repository name.
TODO: create example
17 18 19 |
# File 'lib/dm-core/repository.rb', line 17 def self.adapters @adapters ||= {} end |
+ (Array) context
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the stack of current repository contexts
TODO: create example
29 30 31 |
# File 'lib/dm-core/repository.rb', line 29 def self.context Thread.current[:dm_repository_contexts] ||= [] end |
+ (Symbol) default_name
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the default name of this Repository
TODO: create example
41 42 43 |
# File 'lib/dm-core/repository.rb', line 41 def self.default_name :default end |
Instance Method Details
- (Adapters::AbstractAdapter) adapter
Get the adapter for this repository
Lazy loads adapter setup from registered adapters
TODO: create example
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# 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 |
- (Integer) create(resources)
Create one or more resource instances in this repository.
TODO: create example
145 146 147 |
# File 'lib/dm-core/repository.rb', line 145 def create(resources) adapter.create(resources) end |
- (Integer) delete(collection)
Delete one or more resource instances
TODO: create example
194 195 196 197 |
# File 'lib/dm-core/repository.rb', line 194 def delete(collection) return 0 unless collection.query.valid? adapter.delete(collection) end |
- (IdentityMap) identity_map(model)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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
93 94 95 |
# File 'lib/dm-core/repository.rb', line 93 def identity_map(model) @identity_maps[model.base_model] ||= IdentityMap.new end |
- (String) inspect
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a human readable representation of the repository
TODO: create example
207 208 209 |
# File 'lib/dm-core/repository.rb', line 207 def inspect "#<#{self.class.name} @name=#{@name}>" end |
- (Query) new_query(model, options = {})
Create a Query or subclass instance for this repository.
130 131 132 |
# File 'lib/dm-core/repository.rb', line 130 def new_query(model, = {}) adapter.new_query(self, model, ) end |
- (Array) read(query)
Retrieve a collection of results of a query
TODO: create example
160 161 162 163 |
# File 'lib/dm-core/repository.rb', line 160 def read(query) return [] unless query.valid? query.model.load(adapter.read(query), query) end |
- (Object) scope {|repository| ... }
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Executes a block in the scope of this Repository
TODO: create example
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/dm-core/repository.rb', line 108 def scope context = Repository.context context << self begin yield self ensure context.pop end end |
- (Integer) update(attributes, collection)
Update the attributes of one or more resource instances
TODO: create example
178 179 180 181 |
# 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 |