Class: Dry::Effects::Providers::Reader
- Inherits:
-
Object
- Object
- Dry::Effects::Providers::Reader
- 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
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
-
#call(state) ⇒ Object
private
Yield the block with the handler installed.
-
#initialize ⇒ Reader
constructor
A new instance of Reader.
- #provide?(effect) ⇒ Boolean
- #read ⇒ Object
- #represent ⇒ String
Constructor Details
#initialize ⇒ Reader
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
#state ⇒ Object (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
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 |
#read ⇒ Object
31 32 33 |
# File 'lib/dry/effects/providers/reader.rb', line 31 def read state end |
#represent ⇒ 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 |