Class: Coach::MiddlewareItem
- Inherits:
-
Object
- Object
- Coach::MiddlewareItem
- Defined in:
- lib/coach/middleware_item.rb
Instance Attribute Summary collapse
-
#middleware ⇒ Object
Returns the value of attribute middleware.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #build_middleware(context, successor) ⇒ Object
-
#config ⇒ Object
Generates config by either cloning our given config (if it’s a hash) else if a lambda value, then will compute the config by calling the lambda with this middlewares parent config.
-
#initialize(middleware, config = {}) ⇒ MiddlewareItem
constructor
A new instance of MiddlewareItem.
-
#set_parent(parent) ⇒ Object
Assigns the parent for this middleware, allowing config inheritance rubocop:disable Naming/AccessorMethodName.
-
#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.
10 11 12 13 |
# File 'lib/coach/middleware_item.rb', line 10 def initialize(middleware, config = {}) @middleware = middleware @config_value = config end |
Instance Attribute Details
#middleware ⇒ Object
Returns the value of attribute middleware.
8 9 10 |
# File 'lib/coach/middleware_item.rb', line 8 def middleware @middleware end |
#parent ⇒ Object
Returns the value of attribute parent.
8 9 10 |
# File 'lib/coach/middleware_item.rb', line 8 def parent @parent end |
Instance Method Details
#build_middleware(context, successor) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/coach/middleware_item.rb', line 15 def build_middleware(context, successor) @middleware. new(context, successor&.instrument, config) end |
#config ⇒ Object
Generates config by either cloning our given config (if it’s a hash) else if a lambda value, then will compute the config by calling the lambda with this middlewares parent config.
40 41 42 |
# File 'lib/coach/middleware_item.rb', line 40 def config @config ||= lambda_config? ? @config_value.call(parent.config) : @config_value.clone end |
#set_parent(parent) ⇒ Object
Assigns the parent for this middleware, allowing config inheritance rubocop:disable Naming/AccessorMethodName
30 31 32 33 34 |
# File 'lib/coach/middleware_item.rb', line 30 def set_parent(parent) @parent = parent self end |
#validate! ⇒ Object
Runs validation against the middleware chain, raising if any unmet dependencies are discovered.
24 25 26 |
# File 'lib/coach/middleware_item.rb', line 24 def validate! MiddlewareValidator.new(middleware).validated_provides! end |