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
36 37 38 39 40 41 42 43 44 |
# File 'lib/dry/effects/providers/reader.rb', line 36 def call(state) case state when state_type @state = state yield else raise Errors::InvalidValueError.new(state, scope) end end |
#provide?(effect) ⇒ Boolean
58 59 60 |
# File 'lib/dry/effects/providers/reader.rb', line 58 def provide?(effect) effect.type.equal?(:state) && effect.name.equal?(:read) && scope.equal?(effect.scope) end |
#read ⇒ Object
31 |
# File 'lib/dry/effects/providers/reader.rb', line 31 def read = state |
#represent ⇒ String
48 49 50 51 52 53 54 |
# File 'lib/dry/effects/providers/reader.rb', line 48 def represent if Undefined.equal?(state) "#{type}[#{scope} not set]" else "#{type}[#{scope} set]" end end |