Module: Graphiti::Resource::Persistence
- Extended by:
- ActiveSupport::Concern
- Included in:
- Graphiti::Resource
- Defined in:
- lib/graphiti/resource/persistence.rb
Instance Method Summary collapse
- #assign_attributes(model_instance, update_params, meta = nil) ⇒ Object
- #build(model, meta = nil) ⇒ Object
- #create(create_params, meta = nil) ⇒ Object
- #delete(model_instance, meta = nil) ⇒ Object
- #destroy(id, meta = nil) ⇒ Object
- #save(model_instance, meta = nil) ⇒ Object
- #update(update_params, meta = nil) ⇒ Object
Instance Method Details
#assign_attributes(model_instance, update_params, meta = nil) ⇒ Object
122 123 124 |
# File 'lib/graphiti/resource/persistence.rb', line 122 def assign_attributes(model_instance, update_params, = nil) adapter.assign_attributes(model_instance, update_params) end |
#build(model, meta = nil) ⇒ Object
118 119 120 |
# File 'lib/graphiti/resource/persistence.rb', line 118 def build(model, = nil) adapter.build(model) end |
#create(create_params, meta = nil) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/graphiti/resource/persistence.rb', line 72 def create(create_params, = nil) model_instance = nil run_callbacks :persistence, :create, create_params, do run_callbacks :attributes, :create, create_params, do |params| model_instance = (:build, model, ) (:assign_attributes, model_instance, params, ) model_instance end run_callbacks :save, :create, model_instance, do model_instance = (:save, model_instance, ) end model_instance end end |
#delete(model_instance, meta = nil) ⇒ Object
130 131 132 |
# File 'lib/graphiti/resource/persistence.rb', line 130 def delete(model_instance, = nil) adapter.destroy(model_instance) end |
#destroy(id, meta = nil) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/graphiti/resource/persistence.rb', line 110 def destroy(id, = nil) model_instance = self.class._find(id: id).data run_callbacks :destroy, :destroy, model_instance, do (:delete, model_instance, ) end model_instance end |
#save(model_instance, meta = nil) ⇒ Object
126 127 128 |
# File 'lib/graphiti/resource/persistence.rb', line 126 def save(model_instance, = nil) adapter.save(model_instance) end |
#update(update_params, meta = nil) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/graphiti/resource/persistence.rb', line 90 def update(update_params, = nil) model_instance = nil id = update_params[:id] update_params = update_params.except(:id) run_callbacks :persistence, :update, update_params, do run_callbacks :attributes, :update, update_params, do |params| model_instance = self.class._find(id: id).data (:assign_attributes, model_instance, params, ) model_instance end run_callbacks :save, :update, model_instance, do model_instance = (:save, model_instance, ) end end model_instance end |