Module: Graphiti::ActiveGraph::Resource::Persistence

Defined in:
lib/graphiti/active_graph/resource/persistence.rb

Instance Method Summary collapse

Instance Method Details

#update(update_params, meta = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/graphiti/active_graph/resource/persistence.rb', line 4

def update(update_params, meta = nil)
  model_instance = nil
  id = update_params[:id]
  update_params = update_params.except(:id)

  run_callbacks :persistence, :update, update_params, meta do
    run_callbacks :attributes, :update, update_params, meta do |params|
      model_instance = id ? model.find(id) : self.class._find(id: id).data
      call_with_meta(:assign_attributes, model_instance, params, meta)
      model_instance
    end

    run_callbacks :save, :update, model_instance, meta do
      model_instance = call_with_meta(:save, model_instance, meta)
    end
  end

  model_instance
end