Module: Datamappify::Repository::QueryMethods
- Defined in:
- lib/datamappify/repository/query_methods.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#all ⇒ Array<Entity>
Returns a collection of all the entities in the repository.
- #count ⇒ Integer
- #create(entity) ⇒ Entity, false
- #create!(entity) ⇒ Entity
- #destroy(entity) ⇒ void, false
- #destroy!(entity) ⇒ void
-
#exists?(entity) ⇒ Boolean
Does the entity exist already in the repository?.
- #find(criteria) ⇒ Entity?
-
#query_options ⇒ Hash
private
Some default, required objects passed into each query method.
- #save(entity) ⇒ Entity, false
- #save!(entity) ⇒ Entity
- #update(entity) ⇒ Entity, false
- #update!(entity) ⇒ Entity
Class Method Details
.included(klass) ⇒ Object
8 9 10 11 12 |
# File 'lib/datamappify/repository/query_methods.rb', line 8 def self.included(klass) klass.class_eval do include QueryMethod::Callbacks end end |
Instance Method Details
#all ⇒ Array<Entity>
Returns a collection of all the entities in the repository
38 39 40 |
# File 'lib/datamappify/repository/query_methods.rb', line 38 def all QueryMethod::FindMultiple.new(, {}).perform end |
#count ⇒ Integer
116 117 118 |
# File 'lib/datamappify/repository/query_methods.rb', line 116 def count QueryMethod::Count.new().perform end |
#create(entity) ⇒ Entity, false
46 47 48 49 50 |
# File 'lib/datamappify/repository/query_methods.rb', line 46 def create(entity) run_callbacks entity, :save, :create do QueryMethod::Create.new(, entity).perform end end |
#create!(entity) ⇒ Entity
57 58 59 |
# File 'lib/datamappify/repository/query_methods.rb', line 57 def create!(entity) create(entity) || raise(Data::EntityNotSaved) end |
#destroy(entity) ⇒ void, false
100 101 102 103 104 |
# File 'lib/datamappify/repository/query_methods.rb', line 100 def destroy(entity) run_callbacks entity, :destroy do QueryMethod::Destroy.new(, entity).perform end end |
#destroy!(entity) ⇒ void
This method returns an undefined value.
111 112 113 |
# File 'lib/datamappify/repository/query_methods.rb', line 111 def destroy!(entity) destroy(entity) || raise(Data::EntityNotDestroyed) end |
#exists?(entity) ⇒ Boolean
Does the entity exist already in the repository?
19 20 21 |
# File 'lib/datamappify/repository/query_methods.rb', line 19 def exists?(entity) QueryMethod::Exists.new(, entity).perform end |
#find(criteria) ⇒ Entity?
27 28 29 30 31 32 33 |
# File 'lib/datamappify/repository/query_methods.rb', line 27 def find(criteria) if criteria.is_a?(Integer) QueryMethod::Find.new(, criteria).perform else QueryMethod::FindMultiple.new(, criteria).perform end end |
#query_options ⇒ Hash (private)
Some default, required objects passed into each query method
125 126 127 128 129 130 131 |
# File 'lib/datamappify/repository/query_methods.rb', line 125 def { :data_mapper => data_mapper, :states => states, :lazy_load? => lazy_load? } end |
#save(entity) ⇒ Entity, false
84 85 86 |
# File 'lib/datamappify/repository/query_methods.rb', line 84 def save(entity) exists?(entity) ? update(entity) : create(entity) end |
#save!(entity) ⇒ Entity
93 94 95 |
# File 'lib/datamappify/repository/query_methods.rb', line 93 def save!(entity) exists?(entity) ? update!(entity) : create!(entity) end |
#update(entity) ⇒ Entity, false
65 66 67 68 69 |
# File 'lib/datamappify/repository/query_methods.rb', line 65 def update(entity) run_callbacks entity, :save, :update do QueryMethod::Update.new(, entity).perform end end |
#update!(entity) ⇒ Entity
76 77 78 |
# File 'lib/datamappify/repository/query_methods.rb', line 76 def update!(entity) update(entity) || raise(Data::EntityNotSaved) end |