Class: Dingding::Notifier::PayloadMiddleware::Stack
- Inherits:
-
Object
- Object
- Dingding::Notifier::PayloadMiddleware::Stack
- Defined in:
- lib/dingding-notifier/payload_middleware/stack.rb
Instance Attribute Summary collapse
-
#notifier ⇒ Object
readonly
Returns the value of attribute notifier.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #call(payload = {}) ⇒ Object
-
#initialize(notifier) ⇒ Stack
constructor
A new instance of Stack.
- #set(*middlewares) ⇒ Object
Constructor Details
#initialize(notifier) ⇒ Stack
Returns a new instance of Stack.
10 11 12 13 |
# File 'lib/dingding-notifier/payload_middleware/stack.rb', line 10 def initialize notifier @notifier = notifier @stack = [] end |
Instance Attribute Details
#notifier ⇒ Object (readonly)
Returns the value of attribute notifier.
7 8 9 |
# File 'lib/dingding-notifier/payload_middleware/stack.rb', line 7 def notifier @notifier end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
7 8 9 |
# File 'lib/dingding-notifier/payload_middleware/stack.rb', line 7 def stack @stack end |
Instance Method Details
#call(payload = {}) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/dingding-notifier/payload_middleware/stack.rb', line 28 def call payload={} result = stack.inject payload do |pld, middleware| middleware.call(pld) end result end |
#set(*middlewares) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dingding-notifier/payload_middleware/stack.rb', line 15 def set *middlewares middlewares = if middlewares.length == 1 && middlewares.first.is_a?(Hash) middlewares.first else middlewares.flatten end @stack = middlewares.map do |key, opts| PayloadMiddleware.registry.fetch(key).new(*[notifier, opts].compact) end end |