Class: ZeroRailsAdapter::Crud::Dispatcher

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#contextObject (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