Class: Spree::AgentTools::UpdateResource
- Inherits:
-
ResourceWrite
- Object
- Spree::AgentTool
- ResourceWrite
- Spree::AgentTools::UpdateResource
- Defined in:
- app/tools/spree/agent_tools/update_resource.rb
Overview
Changes a record, through the Admin API's own update operation — which runs whatever workflow the controller declares, so this is the same write the dashboard performs.
Constant Summary
Constants inherited from Spree::AgentTool
Spree::AgentTool::PARENT_ID_DESCRIPTION
Instance Attribute Summary
Attributes inherited from Spree::AgentTool
Instance Method Summary collapse
Methods inherited from ResourceWrite
Methods inherited from Spree::AgentTool
additive!, audience, description, destructive?, #initialize, input_schema, mutating!, mutating?, param, params, permission, #permitted?, tool_name, #unknown_resource
Constructor Details
This class inherits a constructor from Spree::AgentTool
Instance Method Details
#call(resource:, id:, attributes: {}, parent_id: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/tools/spree/agent_tools/update_resource.rb', line 19 def call(resource:, id:, attributes: {}, parent_id: nil) entry, refusal = writable_entry(resource, :update) return refusal if refusal body, rejection = body_for(entry, attributes) return rejection if rejection path, missing = write_path(entry, :update, id: id, parent_id: parent_id) return missing if missing response = dispatch.call(method: :patch, path: path, body: body) result_for(response, entry, summary: summary(resource: resource, id: id, attributes: attributes)) end |
#summary(arguments) ⇒ Object
34 35 36 37 38 39 |
# File 'app/tools/spree/agent_tools/update_resource.rb', line 34 def summary(arguments) changed = arguments[:attributes].to_h.keys.map { |key| key.to_s.tr('_', ' ') } "Update #{arguments[:resource].to_s.singularize.tr('_', ' ')} #{arguments[:id]}" \ "#{": #{changed.to_sentence}" if changed.any?}" end |