Class: Dry::Monads::Extensions::PrettyPrint::LazyPrintValue Private
- Inherits:
-
Module
- Object
- Module
- Dry::Monads::Extensions::PrettyPrint::LazyPrintValue
- Defined in:
- lib/dry/monads/extensions/pretty_print.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
-
#initialize(constructor, success_prefix: "value=", error_prefix: "error=") ⇒ LazyPrintValue
constructor
private
A new instance of LazyPrintValue.
Constructor Details
#initialize(constructor, success_prefix: "value=", error_prefix: "error=") ⇒ LazyPrintValue
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.
Returns a new instance of LazyPrintValue.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/dry/monads/extensions/pretty_print.rb', line 28 def initialize(constructor, success_prefix: "value=", error_prefix: "error=") super() define_method(:pretty_print) do |pp| if promise.fulfilled? value = promise.value if Unit.equal?(value) if success_prefix.empty? pp.text "#{constructor}()" else pp.text "#{constructor}(#{success_prefix}())" end else pp.text "#{constructor}(#{success_prefix}" pp.group(1) do pp.breakable("") pp.pp(value) end pp.text ")" end elsif promise.rejected? pp.text "#{constructor}(#{error_prefix}#{promise.reason.inspect})" else pp.text "#{constructor}(?)" end end end |