Class: Dry::Data::Default

Inherits:
Object
  • Object
show all
Includes:
Decorator, TypeBuilder
Defined in:
lib/dry/data/default.rb

Instance Attribute Summary collapse

Attributes included from Decorator

#options, #type

Instance Method Summary collapse

Methods included from TypeBuilder

#constrained, #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.



11
12
13
14
# File 'lib/dry/data/default.rb', line 11

def initialize(type, options)
  super
  @value = options.fetch(:value)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Dry::Data::Decorator

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



9
10
11
# File 'lib/dry/data/default.rb', line 9

def value
  @value
end

Instance Method Details

#call(input) ⇒ Object Also known as: []



16
17
18
# File 'lib/dry/data/default.rb', line 16

def call(input)
  input.nil? ? value : type[input]
end