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
Class Method Summary collapse
Instance Method Summary collapse
- #call(input) ⇒ Object (also: #[])
-
#initialize(type, options) ⇒ Default
constructor
A new instance of Default.
Methods included from Builder
#constrained, #constructor, #default, #enum, #optional, #safe, #|
Methods included from Decorator
#constructor, #respond_to_missing?, #valid?, #with
Constructor Details
#initialize(type, options) ⇒ Default
Returns a new instance of Default.
27 28 29 30 |
# File 'lib/dry/types/default.rb', line 27 def initialize(type, ) super @value = .fetch(: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.
15 16 17 |
# File 'lib/dry/types/default.rb', line 15 def value @value end |
Class Method Details
.[](value) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/dry/types/default.rb', line 19 def self.[](value) if value.respond_to?(:call) Callable else self end end |
Instance Method Details
#call(input) ⇒ Object Also known as: []
32 33 34 35 36 37 38 39 |
# File 'lib/dry/types/default.rb', line 32 def call(input) if input.nil? evaluate else output = type[input] output.nil? ? evaluate : output end end |