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
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dry/effects/providers/resolve.rb', line 47 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
75 76 77 |
# File 'lib/dry/effects/providers/resolve.rb', line 75 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 |
# File 'lib/dry/effects/providers/resolve.rb', line 42 def locate = self |
#provide?(effect) ⇒ Boolean
64 65 66 67 68 69 70 |
# File 'lib/dry/effects/providers/resolve.rb', line 64 def provide?(effect) if super !effect.name.equal?(:resolve) || key?(effect.payload[0]) else false end end |
#represent ⇒ String
81 82 83 84 |
# File 'lib/dry/effects/providers/resolve.rb', line 81 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.
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/dry/effects/providers/resolve.rb', line 88 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 |