Class: Cuprum::Rails::Controllers::Middleware
- Inherits:
-
Object
- Object
- Cuprum::Rails::Controllers::Middleware
- Defined in:
- lib/cuprum/rails/controllers/middleware.rb
Overview
A configured middleware option for a controller.
Instance Attribute Summary collapse
-
#command ⇒ Cuprum::Middleware
readonly
The middleware command to wrap the action or actions.
-
#except ⇒ Array<Symbol>
readonly
A list of action names; the middleware will not be applied to actions on the list.
-
#only ⇒ Array<Symbol>
readonly
A list of action names; the middleware will be applied only to actions on the list.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(command:, except: [], only: []) ⇒ Middleware
constructor
A new instance of Middleware.
-
#matches?(action_name) ⇒ true, false
(also: #match?)
Checks if the middleware will be applied to the named action.
Constructor Details
#initialize(command:, except: [], only: []) ⇒ Middleware
Returns a new instance of Middleware.
16 17 18 19 20 |
# File 'lib/cuprum/rails/controllers/middleware.rb', line 16 def initialize(command:, except: [], only: []) @command = command @except = Set.new(except.map(&:intern)) @only = Set.new(only.map(&:intern)) end |
Instance Attribute Details
#command ⇒ Cuprum::Middleware (readonly)
Returns the middleware command to wrap the action or actions.
24 25 26 |
# File 'lib/cuprum/rails/controllers/middleware.rb', line 24 def command @command end |
#except ⇒ Array<Symbol> (readonly)
Returns a list of action names; the middleware will not be applied to actions on the list.
28 29 30 |
# File 'lib/cuprum/rails/controllers/middleware.rb', line 28 def except @except end |
#only ⇒ Array<Symbol> (readonly)
Returns a list of action names; the middleware will be applied only to actions on the list.
32 33 34 |
# File 'lib/cuprum/rails/controllers/middleware.rb', line 32 def only @only end |
Instance Method Details
#==(other) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/cuprum/rails/controllers/middleware.rb', line 35 def ==(other) other.is_a?(Cuprum::Rails::Controllers::Middleware) && other.command == command && other.except == except && other.only == only end |
#matches?(action_name) ⇒ true, false Also known as: match?
Checks if the middleware will be applied to the named action.
If the middleware defines any :except actions, returns false if the action name is in the set. If the middleware defines any :only actions, returns false unless the action name is in the set. Otherwise, returns true.
51 52 53 54 55 56 |
# File 'lib/cuprum/rails/controllers/middleware.rb', line 51 def matches?(action_name) return false unless except.empty? || except.exclude?(action_name) return false unless only.empty? || only.include?(action_name) true end |