Module: Cuprum::Rails::Controllers::ClassMethods::Middleware

Defined in:
lib/cuprum/rails/controllers/class_methods/middleware.rb

Overview

Provides a DSL for defining controller middleware.

Instance Method Summary collapse

Instance Method Details

#middlewareArray<Cuprum::Rails::Controllers::Middleware> #middleware(command, except: [], only: {]}) ⇒ Object

Overloads:

  • #middlewareArray<Cuprum::Rails::Controllers::Middleware>

    Returns the configured middleware for the controller.

    Returns:

  • #middleware(command, except: [], only: {]}) ⇒ Object

    Defines middleware for the controller.

    Parameters:

    • command (Class, Cuprum::Command)

      The middleware command. Middleware commands must take two parameters: a next_command argument, and a request: keyword.

    • except (Array<String, Symbol>) (defaults to: [])

      Action names to exclude. The middleware will not be applied to actions on this list.

    • only (Array<String, Symbol>) (defaults to: {]})

      Action names to include If this is not empty, the middleware will only be applied to actions on this list.

    See Also:

    • Middleware


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cuprum/rails/controllers/class_methods/middleware.rb', line 26

def middleware(command = nil, except: [], only: [])
  unless command.nil?
    own_middleware <<
      build_middleware(command: command, except: except, only: only)
  end

  ancestors
    .select { |ancestor| ancestor.respond_to?(:own_middleware) }
    .reverse_each
    .map(&:own_middleware)
    .reduce(&:+)
end

#own_middlewareObject



40
41
42
# File 'lib/cuprum/rails/controllers/class_methods/middleware.rb', line 40

def own_middleware
  @own_middleware ||= []
end