Class: Dry::Effects::Providers::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/effects/providers/env.rb

Constant Summary collapse

Locate =
Effect.new(type: :env, name: :locate)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parentObject (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, options = EMPTY_HASH)
  unless values.empty?
    @values = @values.merge(values)
  end

  if options.fetch(:overridable, false)
    @parent = ::Dry::Effects.yield(Locate) { EMPTY_HASH }
  else
    @parent = EMPTY_HASH
  end

  yield
end

#key?(key) ⇒ Boolean

Returns:

  • (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

#locateProvider

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

Returns:



34
35
36
# File 'lib/dry/effects/providers/env.rb', line 34

def locate
  self
end

#provide?(effect) ⇒ Boolean

Parameters:

Returns:

  • (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