Releases: dry-rb/dry-initializer
Releases · dry-rb/dry-initializer
v3.1.1
Changed
- Improved error messages were rolled back, they created an implicit dependency on dry-types (@flash-gordon)
v3.1.0
Changed
- Improved error messages on type mismatch (@swerling)
- [BREAKING] Minimal supported Ruby version is 2.7 (@flash-gordon)
v3.0.4
Fix underscored names of param/option-s
v3.0.1 Fix validation of underscored names
Support of wrapped and nested types
class Test
extend Dry::Initializer
# Wrapped type
option :foo, [proc(&:to_s)]
# Nested type
option :bar do
option :baz, proc(&:to_s)
end
# Both wrapped and nested type
option :qux, [] do
option :sax, proc(&:to_s)
end
end
test = Test.new foo: 4, bar: { baz: 5 }, qux: { sax: 6 }
# Wrapped type wraps a coerced value to array
test.foo # => ["4"]
# Nested type builds the nested structure
test.bar.baz # => "5"
# Their composition wraps the result of nesting
test.qux.first.sax # => 6
Fix coercion of `nil`
v2.6.0 Bump v2.6.0
Switch operands to test for undefined attrs
v2.5.0 Bump v.2.5.0
Add dispatchers for extending syntax
v2.4.0 Bump v2.4.0
Type coercer can take second argument for the initialized instance
This allows to wrap assigned value to the object that refers back
to the initializer instance. More verbose example:
class Location < String
attr_reader :parameter # refers back to its parameter
def initialize(name, parameter)
super(name)
@parameter = parameter
end
end
class Parameter
extend Dry::Initializer
param :name
param :location, ->(value, param) { Location.new(value, param) }
end
offset = Parameter.new "offset", location: "query"
offset.name # => "offset"
offset.location # => "query"
offset.location.parameter == offset # true
Add option `:desc` to param/option, and `#inch` to the initializer's config
v2.2.0 Bump v2.2.0