Class: Dry::Types::Option
- Inherits:
-
Object
- Object
- Dry::Types::Option
- Includes:
- Decorator, Builder, Printable, Type
- Defined in:
- lib/dry/types/fear/option.rb
Instance Method Summary collapse
- #call_safe(input = Undefined) ⇒ Fear::Option private
- #call_unsafe(input = Undefined) ⇒ Fear::Option private
- #default(value) ⇒ Object
- #default? ⇒ true
- #try(input = Undefined) ⇒ Result::Success
Methods included from Builder
Instance Method Details
#call_safe(input = Undefined) ⇒ Fear::Option
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.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dry/types/fear/option.rb', line 33 def call_safe(input = Undefined) case input when ::Fear::Option input when Undefined Fear.none else Fear.option(type.call_safe(input) { |output = input| return yield(output) }) end end |
#call_unsafe(input = Undefined) ⇒ Fear::Option
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.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dry/types/fear/option.rb', line 17 def call_unsafe(input = Undefined) case input when ::Fear::Option input when Undefined Fear.none else Fear.option(type.call_unsafe(input)) end end |
#default(value) ⇒ Object
73 74 75 76 77 |
# File 'lib/dry/types/fear/option.rb', line 73 def default(value) raise ArgumentError, "nil cannot be used as a default of a maybe type" if value.nil? super end |
#default? ⇒ true
62 63 64 |
# File 'lib/dry/types/fear/option.rb', line 62 def default? true end |
#try(input = Undefined) ⇒ Result::Success
49 50 51 52 53 54 55 56 57 |
# File 'lib/dry/types/fear/option.rb', line 49 def try(input = Undefined) result = type.try(input) if result.success? Result::Success.new(Fear.option(result.input)) else result end end |