Module: DataMapper::Resource

Defined in:
lib/dm-adjust/resource.rb

Instance Method Summary collapse

Instance Method Details

#adjust(attributes = {}, reload = false) ⇒ Object

Raises:

  • (NotImplementedError)


3
4
5
# File 'lib/dm-adjust/resource.rb', line 3

def adjust(attributes = {}, reload = false)
  raise NotImplementedError, 'adjust *with* validations has not be written yet, try adjust!'
end

#adjust!(attributes = {}, reload = false) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dm-adjust/resource.rb', line 7

def adjust!(attributes = {}, reload = false)
  return true if attributes.empty?

  adjust_attributes = {}

  model.properties(repository.name).slice(*attributes.keys).each do |property|
    adjust_attributes[property] = attributes[property.name] if property
  end

  repository.adapter.adjust(adjust_attributes, to_query)

  collection.reload(:fields => adjust_attributes.keys) if reload

  true
end