Class: Dry::Effects::Providers::Reader

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

Constant Summary collapse

Any =
::Object.new.tap { |any|
  def any.===(_)
    true
  end
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReader

Returns a new instance of Reader.



25
26
27
28
29
# File 'lib/dry/effects/providers/reader.rb', line 25

def initialize(*, **)
  super

  @state = Undefined
end

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



19
20
21
# File 'lib/dry/effects/providers/reader.rb', line 19

def state
  @state
end

Class Method Details

.handle_method(scope, as: Undefined) ⇒ Object



7
8
9
# File 'lib/dry/effects/providers/reader.rb', line 7

def self.handle_method(scope, as: Undefined, **)
  Undefined.default(as) { :"with_#{scope}" }
end

Instance Method Details

#call(state) ⇒ 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



38
39
40
41
42
43
44
45
46
# File 'lib/dry/effects/providers/reader.rb', line 38

def call(state)
  case state
  when state_type
    @state = state
    yield
  else
    raise Errors::InvalidValueError.new(state, scope)
  end
end

#provide?(effect) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/dry/effects/providers/reader.rb', line 60

def provide?(effect)
  effect.type.equal?(:state) && effect.name.equal?(:read) && scope.equal?(effect.scope)
end

#readObject



31
32
33
# File 'lib/dry/effects/providers/reader.rb', line 31

def read
  state
end

#representString

Returns:

  • (String)


50
51
52
53
54
55
56
# File 'lib/dry/effects/providers/reader.rb', line 50

def represent
  if Undefined.equal?(state)
    "#{type}[#{scope} not set]"
  else
    "#{type}[#{scope} set]"
  end
end