Class: DataMapper::Collection

### Home Classes Methods

### In Files

- lib/dm-adjust/collection.rb

### Parent

Object

### Methods

- #adjust
- #adjust!

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- DataMapper
- DataMapper::Adapters
- DataMapper::Adapters::DataObjectsAdapterAdjust
- DataMapper::Adapters::DataObjectsAdapterAdjust::SQL
- DataMapper::Adapters::InMemoryAdapterAdjust
- DataMapper::Adapters::YamlAdapterAdjust
- DataMapper::Collection
- DataMapper::Model
- DataMapper::Repository
- DataMapper::Resource

No matching classes.

# DataMapper::Collection

### Public Instance Methods

adjust(attributes = {}, reload = false) click to toggle source

    # 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) click to toggle source

increment or decrement attributes on a collection

@example [Usage]

    * People.all.adjust(:salary => +1000)
    * Children.all(:age.gte => 18).adjust(:allowance => -100)

@param attributes <Hash> A hash of attributes to adjust, and their adjustment @param reload <FalseClass,TrueClass> If true, affected objects will be reloaded

@api public

    # 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.