Method: Rails::GraphQL::Callback#initialize

Defined in:
lib/rails/graphql/callback.rb

#initialize(target, event_name, *args, **xargs, &block) ⇒ Callback

Returns a new instance of Callback.

Raises:

  • (::ArgumentError)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rails/graphql/callback.rb', line 23

def initialize(target, event_name, *args, **xargs, &block)
  raise ::ArgumentError, (+<<~MSG).squish if block.nil? && !args.first.present?
    Either provide a block or a method name when setting a #{event_name}
    callback on #{target.inspect}.
  MSG

  if block.nil?
    block = args.shift
    valid_format = block.is_a?(Symbol) || block.is_a?(Proc)
    raise ::ArgumentError, (+<<~MSG).squish unless valid_format
      The given #{block.class.name} class is not a valid callback.
    MSG
  end

  @target = target
  @event_name = event_name

  @exclusive = xargs.delete(EXCLUSIVE_ARGUMENT)
  @exclusive = target.try(:default_exclusive?, event_name) if @exclusive.nil?
  @exclusive = true if @exclusive.nil?

  @pre_args = args
  @pre_xargs = xargs.slice!(*event_filters.keys)
  @filters = xargs

  @block = block
end