Class: Dry::Effects::Providers::Env
- Inherits:
-
Object
- Object
- Dry::Effects::Providers::Env
- Defined in:
- lib/dry/effects/providers/env.rb
Constant Summary collapse
- Locate =
Effect.new(type: :env, name: :locate)
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#call(values = EMPTY_HASH, options = EMPTY_HASH) ⇒ Object
private
Yield the block with the handler installed.
- #key?(key) ⇒ Boolean
-
#locate ⇒ Provider
private
Locate handler in the stack.
- #provide?(effect) ⇒ Boolean
- #read(key) ⇒ Object
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
13 14 15 |
# File 'lib/dry/effects/providers/env.rb', line 13 def parent @parent end |
Instance Method Details
#call(values = 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
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dry/effects/providers/env.rb', line 41 def call(values = EMPTY_HASH, = EMPTY_HASH) unless values.empty? @values = @values.merge(values) end if .fetch(:overridable, false) @parent = ::Dry::Effects.yield(Locate) { EMPTY_HASH } else @parent = EMPTY_HASH end yield end |
#key?(key) ⇒ Boolean
66 67 68 |
# File 'lib/dry/effects/providers/env.rb', line 66 def key?(key) values.key?(key) || (key.is_a?(::String) && ::ENV.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
34 35 36 |
# File 'lib/dry/effects/providers/env.rb', line 34 def locate self end |
#provide?(effect) ⇒ Boolean
58 59 60 61 62 63 64 |
# File 'lib/dry/effects/providers/env.rb', line 58 def provide?(effect) if super !effect.name.equal?(:read) || key?(effect.payload[0]) else false end end |
#read(key) ⇒ Object
15 16 17 |
# File 'lib/dry/effects/providers/env.rb', line 15 def read(key) parent.fetch(key) { fetch(key) } end |