Class: DataMapper::Repository
- Inherits:
-
Object
- Object
- DataMapper::Repository
- Extended by:
- Equalizer
- Includes:
- Extlib::Assertions
- Defined in:
- lib/dm-core/repository.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
TODO: document.
Class Method Summary collapse
-
.adapters ⇒ Hash(Symbol => Adapters::AbstractAdapter)
private
Get the list of adapters registered for all Repositories, keyed by repository name.
-
.context ⇒ Array
private
Get the stack of current repository contexts.
-
.default_name ⇒ Symbol
private
Get the default name of this Repository.
Instance Method Summary collapse
-
#adapter ⇒ Adapters::AbstractAdapter
Get the adapter for this repository.
-
#create(resources) ⇒ Integer
Create one or more resource instances in this repository.
-
#delete(collection) ⇒ Integer
Delete one or more resource instances.
-
#identity_map(model) ⇒ IdentityMap
private
Get the identity for a particular model within this repository.
-
#inspect ⇒ String
private
Return a human readable representation of the repository.
-
#read(query) ⇒ Array
Retrieve a collection of results of a query.
-
#scope {|repository| ... } ⇒ Object
private
Executes a block in the scope of this Repository.
-
#update(attributes, collection) ⇒ Integer
Update the attributes of one or more resource instances.
Methods included from Equalizer
Instance Attribute Details
#name ⇒ Object (readonly)
TODO: document
47 48 49 |
# File 'lib/dm-core/repository.rb', line 47 def name @name end |
Class Method Details
.adapters ⇒ Hash(Symbol => Adapters::AbstractAdapter)
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 |
.context ⇒ Array
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 |
.default_name ⇒ Symbol
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
#adapter ⇒ Adapters::AbstractAdapter
Get the adapter for this repository
Lazy loads adapter setup from registered adapters
TODO: create example
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/dm-core/repository.rb', line 62 def adapter # Make adapter instantiation lazy so we can defer repository setup until it's actually # needed. Do not remove this code. @adapter ||= begin raise RepositoryNotSetupError, "Adapter not set: #{@name}. Did you forget to setup?" \ unless self.class.adapters.key?(@name) self.class.adapters[@name] end end |
#create(resources) ⇒ Integer
Create one or more resource instances in this repository.
TODO: create example
124 125 126 |
# File 'lib/dm-core/repository.rb', line 124 def create(resources) adapter.create(resources) end |
#delete(collection) ⇒ Integer
Delete one or more resource instances
TODO: create example
173 174 175 176 |
# File 'lib/dm-core/repository.rb', line 173 def delete(collection) return 0 unless collection.query.valid? adapter.delete(collection) end |
#identity_map(model) ⇒ IdentityMap
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
88 89 90 |
# File 'lib/dm-core/repository.rb', line 88 def identity_map(model) @identity_maps[model.base_model] ||= IdentityMap.new end |
#inspect ⇒ String
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
186 187 188 |
# File 'lib/dm-core/repository.rb', line 186 def inspect "#<#{self.class.name} @name=#{@name}>" end |
#read(query) ⇒ Array
Retrieve a collection of results of a query
TODO: create example
139 140 141 142 |
# File 'lib/dm-core/repository.rb', line 139 def read(query) return [] unless query.valid? query.model.load(adapter.read(query), query) end |
#scope {|repository| ... } ⇒ Object
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
103 104 105 106 107 108 109 110 111 |
# File 'lib/dm-core/repository.rb', line 103 def scope Repository.context << self begin yield self ensure Repository.context.pop end end |
#update(attributes, collection) ⇒ Integer
Update the attributes of one or more resource instances
TODO: create example
157 158 159 160 |
# File 'lib/dm-core/repository.rb', line 157 def update(attributes, collection) return 0 unless collection.query.valid? adapter.update(attributes, collection) end |