Sha256: 5dcbb738af946272f27cc31ef0a35539751c98d2f5cf14b95b14dedee4f468e3

Contents?: true

Size: 891 Bytes

Versions: 23

Compression:

Stored size: 891 Bytes

Contents

# frozen_string_literal: true

module GraphqlRails
  class Controller
    # stores information about controller hooks like before_action, after_action, etc.
    class ActionHook
      attr_reader :name, :action_proc

      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

      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

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

      private

      attr_reader :only_actions, :except_actions
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
graphql_rails-3.0.0 lib/graphql_rails/controller/action_hook.rb
graphql_rails-2.4.0 lib/graphql_rails/controller/action_hook.rb
graphql_rails-2.3.0 lib/graphql_rails/controller/action_hook.rb
graphql_rails-2.2.0 lib/graphql_rails/controller/action_hook.rb
graphql_rails-2.1.0 lib/graphql_rails/controller/action_hook.rb
graphql_rails-2.0.0 lib/graphql_rails/controller/action_hook.rb
graphql_rails-1.2.6 lib/graphql_rails/controller/action_hook.rb
graphql_rails-1.2.4 lib/graphql_rails/controller/action_hook.rb
graphql_rails-1.2.3 lib/graphql_rails/controller/action_hook.rb
graphql_rails-1.2.2 lib/graphql_rails/controller/action_hook.rb
graphql_rails-1.2.1 lib/graphql_rails/controller/action_hook.rb
graphql_rails-1.2.0 lib/graphql_rails/controller/action_hook.rb
graphql_rails-1.1.0 lib/graphql_rails/controller/action_hook.rb
graphql_rails-1.0.0 lib/graphql_rails/controller/action_hook.rb
graphql_rails-0.8.0 lib/graphql_rails/controller/action_hook.rb
graphql_rails-0.7.0 lib/graphql_rails/controller/action_hook.rb
graphql_rails-0.6.0 lib/graphql_rails/controller/action_hook.rb
graphql_rails-0.5.2 lib/graphql_rails/controller/action_hook.rb
graphql_rails-0.5.1 lib/graphql_rails/controller/action_hook.rb
graphql_rails-0.5.0 lib/graphql_rails/controller/action_hook.rb