Class: DataMapper::Collection
- Inherits:
-
Object
- Object
- DataMapper::Collection
- Defined in:
- lib/dm-adjust/collection.rb
Instance Method Summary collapse
- #adjust(attributes = {}, reload = false) ⇒ Object
-
#adjust!(attributes = {}, reload = false) ⇒ Object
increment or decrement attributes on a collection.
Instance Method Details
#adjust(attributes = {}, reload = false) ⇒ Object
4 5 6 |
# File 'lib/dm-adjust/collection.rb', line 4 def adjust(attributes = {}, reload = false) raise NotImplementedError, 'adjust *with* validations has not be written yet, try adjust!' end |
#adjust!(attributes = {}, reload = false) ⇒ Object
increment or decrement attributes on a collection
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dm-adjust/collection.rb', line 19 def adjust!(attributes = {}, reload = false) return true if attributes.empty? reload_conditions = if reload model_key = model.key(repository.name) Query.target_conditions(self, model_key, model_key) end adjust_attributes = adjust_attributes(attributes) repository.adjust(adjust_attributes, self) if reload_conditions @query.clear @query.update(:conditions => reload_conditions) self.reload end true end |