Releases: dry-rb/dry-initializer
Support of the `initializer` reloading via `super`
v0.11.0 Bump v0.11.0
ROM integration & support of Ruby 2.4
v0.10.2 Bump v0.10.2
Bug fix
Remove deprecated method `using`
v0.10.0 Update CHANGELOG
Deprecate method `using`
Fixed validation of param/option names
v0.9.2 Bump v0.9.2
Support renaming options
class Foo
include Dry::Initializer::Mixin
option :bar, as: :foo
end
Foo.new(bar: :BAZ).foo # => :BAZ
Ever-tolerance to options
Default initializer is provided by extending the Mixin (in earlier version it was built only by param
or option
invocations.
From the very beginning the method accepts any option (ignores unknown ones)
class MyClass
extend Dry::Initializer::Mixin
end
instance = MyClass.new foo: :bar # undefined options are accepted
instance.respond_to? :foo # ...but ignored
This was made to provide more consistent behavior (in v0.8.0 tolerance to unknown options occurred all of a sudden after the first option was defined)
Support for `dry-struct`-ish syntax of type constraints
In addition to
param :name, type: Dry::Types['strict.string']
it is possible to use second argument instead of type:
option
param :name, Dry::Types['strict.string']
Support for options with "special" names like `option :end`
In this version we switched from key arguments to serialized hash in the initializer:
option :begin
option :end
In previous versions this was translated to
def initialize(begin:, end:)
@begin = begin # WTF?!
@end = end # BOOM!
end
Now the assignment is implemented like this:
def initialize(**__options__)
@begin = __options__.fetch(:begin)
@end = __options__.fetch(:end)
end
As a side effect of the change the initializer becomes tolerant to any unknown option if, and only if some option
was set explicitly.
Methods tolerant_to_unknown_options
and intolerant_to_unknown_options
are deprecated and will be removed in the next version of the gem.