Module: Resourced::ActiveRecord::Actions

Defined in:
lib/resourced/active_record/actions.rb

Instance Method Summary collapse

Instance Method Details

#buildObject



5
6
7
# File 'lib/resourced/active_record/actions.rb', line 5

def build
  model.new(@attributes)
end

#updateObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/resourced/active_record/actions.rb', line 9

def update
  body = @attributes.reject { |k,_| k == :id }

  collection = if attributes[key]
    [model.find(attributes[key])]
  else
    all
  end

  collection.map do |obj|
    obj.assign_attributes(body)
    obj
  end
end

#update!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/resourced/active_record/actions.rb', line 24

def update!
  body = @attributes.reject { |k,_| k == :id }

  collection = if @attributes[key]
    [model.find(@attributes[key])]
  else
    all
  end

  collection.map do |obj|
    obj.update_attributes(body)
  end
end