Class: ZeroRailsAdapter::Crud::Dispatcher
- Inherits:
-
Object
- Object
- ZeroRailsAdapter::Crud::Dispatcher
- Defined in:
- lib/zero_rails_adapter/crud/dispatcher.rb
Constant Summary collapse
- ACTIONS =
{ "create" => :create, "insert" => :create, "update" => :update, "destroy" => :destroy, "delete" => :destroy }.freeze
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #call(mutation) ⇒ Object
-
#initialize(context:) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
Constructor Details
#initialize(context:) ⇒ Dispatcher
Returns a new instance of Dispatcher.
16 17 18 |
# File 'lib/zero_rails_adapter/crud/dispatcher.rb', line 16 def initialize(context:) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
14 15 16 |
# File 'lib/zero_rails_adapter/crud/dispatcher.rb', line 14 def context @context end |
Instance Method Details
#call(mutation) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/zero_rails_adapter/crud/dispatcher.rb', line 20 def call(mutation) resource, action = parse_name(mutation.name) model = resolve_model(resource) attributes = normalize_arguments(mutation.argument) case action when :create create(model, attributes) when :update update(model, attributes) when :destroy destroy(model, attributes) end end |