Class: Dry::Effects::Providers::Resolve
- Inherits:
-
Object
- Object
- Dry::Effects::Providers::Resolve
- Defined in:
- lib/dry/effects/providers/resolve.rb
Constant Summary collapse
- Locate =
Effect.new(type: :resolve, name: :locate)
Instance Attribute Summary collapse
-
#dynamic ⇒ Object
readonly
Returns the value of attribute dynamic.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
Instance Method Summary collapse
-
#call(dynamic = EMPTY_HASH, options = EMPTY_HASH) ⇒ Object
private
Yield the block with the handler installed.
-
#initialize ⇒ Resolve
constructor
A new instance of Resolve.
- #key?(key) ⇒ Boolean
-
#locate ⇒ Provider
private
Locate handler in the stack.
- #provide?(effect) ⇒ Boolean
- #represent ⇒ String
- #represent_container(container) ⇒ String private
- #resolve(key) ⇒ Object
Constructor Details
#initialize ⇒ Resolve
Returns a new instance of Resolve.
21 22 23 24 |
# File 'lib/dry/effects/providers/resolve.rb', line 21 def initialize(*) super @dynamic = EMPTY_HASH end |
Instance Attribute Details
#dynamic ⇒ Object (readonly)
Returns the value of attribute dynamic.
19 20 21 |
# File 'lib/dry/effects/providers/resolve.rb', line 19 def dynamic @dynamic end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
17 18 19 |
# File 'lib/dry/effects/providers/resolve.rb', line 17 def parent @parent end |
Class Method Details
.handle_method(as: Undefined) ⇒ Object
7 8 9 |
# File 'lib/dry/effects/providers/resolve.rb', line 7 def self.handle_method(*, as: Undefined, **) Undefined.default(as, :provide) end |
Instance Method Details
#call(dynamic = EMPTY_HASH, options = EMPTY_HASH) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Yield the block with the handler installed
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dry/effects/providers/resolve.rb', line 49 def call(dynamic = EMPTY_HASH, = EMPTY_HASH) @dynamic = dynamic if .fetch(:overridable, false) @parent = ::Dry::Effects.yield(Locate) { nil } else @parent = nil end yield ensure @dynamic = EMPTY_HASH end |
#key?(key) ⇒ Boolean
77 78 79 |
# File 'lib/dry/effects/providers/resolve.rb', line 77 def key?(key) static.key?(key) || dynamic.key?(key) || parent&.key?(key) end |
#locate ⇒ Provider
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Locate handler in the stack
42 43 44 |
# File 'lib/dry/effects/providers/resolve.rb', line 42 def locate self end |
#provide?(effect) ⇒ Boolean
66 67 68 69 70 71 72 |
# File 'lib/dry/effects/providers/resolve.rb', line 66 def provide?(effect) if super !effect.name.equal?(:resolve) || key?(effect.payload[0]) else false end end |
#represent ⇒ String
83 84 85 86 |
# File 'lib/dry/effects/providers/resolve.rb', line 83 def represent containers = [represent_container(static), represent_container(dynamic)].compact.join("+") "resolve[#{containers.empty? ? "empty" : containers}]" end |
#represent_container(container) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/dry/effects/providers/resolve.rb', line 90 def represent_container(container) case container when ::Hash container.empty? ? nil : "hash" when ::Class container.name || container.to_s else container.to_s end end |
#resolve(key) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dry/effects/providers/resolve.rb', line 26 def resolve(key) if parent&.key?(key) parent.resolve(key) elsif dynamic.key?(key) dynamic[key] elsif static.key?(key) static[key] else Instructions.Raise(Errors::ResolutionError.new(key)) end end |