Class: GraphqlDevise::MountMethod::OperationPreparers::CustomOperationPreparer

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql_devise/mount_method/operation_preparers/custom_operation_preparer.rb

Instance Method Summary collapse

Constructor Details

#initialize(selected_keys:, custom_operations:, model:) ⇒ CustomOperationPreparer

Returns a new instance of CustomOperationPreparer.



7
8
9
10
11
# File 'lib/graphql_devise/mount_method/operation_preparers/custom_operation_preparer.rb', line 7

def initialize(selected_keys:, custom_operations:, model:)
  @selected_keys     = selected_keys
  @custom_operations = custom_operations
  @model             = model
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/graphql_devise/mount_method/operation_preparers/custom_operation_preparer.rb', line 13

def call
  mapping_name = ::GraphqlDevise.to_mapping_name(@model)

  @custom_operations.slice(*@selected_keys).each_with_object({}) do |(action, operation), result|
    mapped_action = "#{mapping_name}_#{action}"

    result[mapped_action.to_sym] = [
      OperationPreparers::GqlNameSetter.new(mapped_action),
      OperationPreparers::ResourceKlassSetter.new(@model)
    ].reduce(operation) { |prepared_operation, preparer| preparer.call(prepared_operation) }
  end
end