Class: GraphqlDevise::MountMethod::OperationPreparers::DefaultOperationPreparer

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

Instance Method Summary collapse

Constructor Details

#initialize(selected_operations:, custom_keys:, model:, preparer:) ⇒ DefaultOperationPreparer

Returns a new instance of DefaultOperationPreparer.



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

def initialize(selected_operations:, custom_keys:, model:, preparer:)
  @selected_operations = selected_operations
  @custom_keys         = custom_keys
  @model               = model
  @preparer            = preparer
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/graphql_devise/mount_method/operation_preparers/default_operation_preparer.rb', line 14

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

  @selected_operations.except(*@custom_keys).each_with_object({}) do |(action, operation_info), result|
    mapped_action = "#{mapping_name}_#{action}"
    operation     = operation_info[:klass]
    options       = operation_info.except(:klass, :deprecation_reason)

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