Class: Dry::Effects::Stack
- Inherits:
-
Object
- Object
- Dry::Effects::Stack
- Extended by:
- Initializer
- Includes:
- Enumerable
- Defined in:
- lib/dry/effects/stack.rb
Instance Method Summary collapse
- #call(effect) ⇒ Object
- #dup ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #provider(effect) ⇒ Object
- #push(provider) ⇒ Object
- #size ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Methods included from Initializer
Instance Method Details
#call(effect) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dry/effects/stack.rb', line 12 def call(effect) if effect.is_a?(Effect) && (provider = provider(effect)) if effect.keywords.empty? provider.public_send(effect.name, *effect.payload) else provider.public_send(effect.name, *effect.payload, **effect.keywords) end else yield end rescue ::Exception => e # rubocop:disable Lint/RescueException Instructions::Raise.new(e) end |
#dup ⇒ Object
49 50 51 |
# File 'lib/dry/effects/stack.rb', line 49 def dup Stack.new(map(&:dup)) end |
#each(&block) ⇒ Object
37 38 39 |
# File 'lib/dry/effects/stack.rb', line 37 def each(&block) providers.each(&block) end |
#empty? ⇒ Boolean
45 46 47 |
# File 'lib/dry/effects/stack.rb', line 45 def empty? providers.empty? end |
#provider(effect) ⇒ Object
33 34 35 |
# File 'lib/dry/effects/stack.rb', line 33 def provider(effect) find { _1.provide?(effect) } end |
#push(provider) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/dry/effects/stack.rb', line 26 def push(provider) providers.unshift(provider) yield ensure providers.shift end |
#size ⇒ Object
41 42 43 |
# File 'lib/dry/effects/stack.rb', line 41 def size providers.size end |
#to_s ⇒ Object Also known as: inspect
53 54 55 56 57 58 59 60 61 |
# File 'lib/dry/effects/stack.rb', line 53 def to_s if empty? "#<Dry::Effects::Stack>" else stack = map(&:represent).reverse.join("->") "#<Dry::Effects::Stack #{stack}>" end end |