Class: Coach::MiddlewareItem
- Inherits:
-
Object
- Object
- Coach::MiddlewareItem
- Defined in:
- lib/coach/middleware_item.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#middleware ⇒ Object
Returns the value of attribute middleware.
Instance Method Summary collapse
- #build_middleware(context, successor) ⇒ Object
-
#initialize(middleware, config = {}) ⇒ MiddlewareItem
constructor
A new instance of MiddlewareItem.
-
#use_with_context?(context) ⇒ Boolean
Requires tweaking to make it run methods by symbol on the class from which the ‘uses` call is made.
-
#validate! ⇒ Object
Runs validation against the middleware chain, raising if any unmet dependencies are discovered.
Constructor Details
#initialize(middleware, config = {}) ⇒ MiddlewareItem
Returns a new instance of MiddlewareItem.
8 9 10 11 |
# File 'lib/coach/middleware_item.rb', line 8 def initialize(middleware, config = {}) @middleware = middleware @config = config end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/coach/middleware_item.rb', line 6 def config @config end |
#middleware ⇒ Object
Returns the value of attribute middleware.
6 7 8 |
# File 'lib/coach/middleware_item.rb', line 6 def middleware @middleware end |
Instance Method Details
#build_middleware(context, successor) ⇒ Object
13 14 15 |
# File 'lib/coach/middleware_item.rb', line 13 def build_middleware(context, successor) @middleware.new(context, successor && successor.instrument, @config) end |
#use_with_context?(context) ⇒ Boolean
Requires tweaking to make it run methods by symbol on the class from which the ‘uses` call is made.
19 20 21 22 23 |
# File 'lib/coach/middleware_item.rb', line 19 def use_with_context?(context) return true if @config[:if].nil? return @config[:if].call(context) if @config[:if].respond_to?(:call) middleware.send(@config[:if], context) end |
#validate! ⇒ Object
Runs validation against the middleware chain, raising if any unmet dependencies are discovered.
27 28 29 |
# File 'lib/coach/middleware_item.rb', line 27 def validate! MiddlewareValidator.new(middleware).validated_provides! end |