Class: Dry::Types::Default
- Inherits:
-
Object
- Object
- Dry::Types::Default
- Defined in:
- lib/dry/types/default.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Callable
Instance Attribute Summary collapse
-
#value ⇒ Object
(also: #evaluate)
readonly
Returns the value of attribute value.
Attributes included from Decorator
Attributes included from Options
Class Method Summary collapse
Instance Method Summary collapse
- #call(input) ⇒ Object (also: #[])
- #constrained(*args) ⇒ Object
- #default? ⇒ Boolean
-
#initialize(type, value) ⇒ Default
constructor
A new instance of Default.
- #try(input) ⇒ Object
Methods included from Builder
#constrained_type, #constructor, #default, #enum, #maybe, #optional, #safe, #|
Methods included from Decorator
#constrained?, #constructor, #respond_to_missing?, #valid?
Methods included from Options
Constructor Details
#initialize(type, value) ⇒ Default
Returns a new instance of Default.
30 31 32 33 |
# File 'lib/dry/types/default.rb', line 30 def initialize(type, value, *) super @value = value end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Dry::Types::Decorator
Instance Attribute Details
#value ⇒ Object (readonly) Also known as: evaluate
Returns the value of attribute value.
18 19 20 |
# File 'lib/dry/types/default.rb', line 18 def value @value end |
Class Method Details
.[](value) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/dry/types/default.rb', line 22 def self.[](value) if value.respond_to?(:call) Callable else self end end |
Instance Method Details
#call(input) ⇒ Object Also known as: []
47 48 49 50 51 52 53 54 |
# File 'lib/dry/types/default.rb', line 47 def call(input) if input.nil? evaluate else output = type[input] output.nil? ? evaluate : output end end |
#constrained(*args) ⇒ Object
35 36 37 |
# File 'lib/dry/types/default.rb', line 35 def constrained(*args) type.constrained(*args).default(value) end |
#default? ⇒ Boolean
39 40 41 |
# File 'lib/dry/types/default.rb', line 39 def default? true end |
#try(input) ⇒ Object
43 44 45 |
# File 'lib/dry/types/default.rb', line 43 def try(input) success(call(input)) end |