Class: GraphqlRails::Controller::ActionHook

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql_rails/controller/action_hook.rb

Overview

stores information about controller hooks like before_action, after_action, etc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, only: [], except: [], &action_proc) ⇒ ActionHook

Returns a new instance of ActionHook.



9
10
11
12
13
14
# File 'lib/graphql_rails/controller/action_hook.rb', line 9

def initialize(name: nil, only: [], except: [], &action_proc)
  @name = name
  @action_proc = action_proc
  @only_actions = Array(only).map(&:to_sym)
  @except_actions = Array(except).map(&:to_sym)
end

Instance Attribute Details

#action_procObject (readonly)

Returns the value of attribute action_proc.



7
8
9
# File 'lib/graphql_rails/controller/action_hook.rb', line 7

def action_proc
  @action_proc
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/graphql_rails/controller/action_hook.rb', line 7

def name
  @name
end

Instance Method Details

#anonymous?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/graphql_rails/controller/action_hook.rb', line 26

def anonymous?
  !!action_proc # rubocop:disable Style/DoubleNegation
end

#applicable_for?(action_name) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
# File 'lib/graphql_rails/controller/action_hook.rb', line 16

def applicable_for?(action_name)
  if only_actions.any?
    only_actions.include?(action_name.to_sym)
  elsif except_actions.any?
    !except_actions.include?(action_name.to_sym)
  else
    true
  end
end