Class: EndpointFlux::Config::Middleware
- Inherits:
-
Object
- Object
- EndpointFlux::Config::Middleware
- Defined in:
- lib/endpoint_flux/config/middleware.rb
Instance Attribute Summary collapse
-
#handler ⇒ Object
Returns the value of attribute handler.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(klass = nil, options = {}, &block) ⇒ Middleware
constructor
A new instance of Middleware.
- #run(attrs) ⇒ Object
Constructor Details
#initialize(klass = nil, options = {}, &block) ⇒ Middleware
Returns a new instance of Middleware.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/endpoint_flux/config/middleware.rb', line 6 def initialize(klass = nil, = {}, &block) if klass unless klass.methods.include?(:perform) raise "The [#{klass}] class should define perform class method" end else raise 'You must provide block or existing klass' unless block_given? end @klass = klass = @handler = block end |
Instance Attribute Details
#handler ⇒ Object
Returns the value of attribute handler.
4 5 6 |
# File 'lib/endpoint_flux/config/middleware.rb', line 4 def handler @handler end |
#klass ⇒ Object
Returns the value of attribute klass.
4 5 6 |
# File 'lib/endpoint_flux/config/middleware.rb', line 4 def klass @klass end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/endpoint_flux/config/middleware.rb', line 4 def end |
Instance Method Details
#==(other) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/endpoint_flux/config/middleware.rb', line 30 def ==(other) return true if klass && klass == other.klass return true if handler && handler == other.handler false end |
#run(attrs) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/endpoint_flux/config/middleware.rb', line 20 def run(attrs) if klass klass.perform(*attrs, , &handler) elsif handler handler.call(*attrs, ) else raise "Unknown middleware type [#{inspect}]" end end |