Class: Dingding::Notifier::PayloadMiddleware::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/dingding-notifier/payload_middleware/stack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#notifierObject (readonly)

Returns the value of attribute notifier.



7
8
9
# File 'lib/dingding-notifier/payload_middleware/stack.rb', line 7

def notifier
  @notifier
end

#stackObject (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