Releases: dry-rb/dry-initializer
Releases · dry-rb/dry-initializer
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.
Add `#using` method for shared options
Instead of
param :foo, reader: :private
option :bar, reader: :private
Use
using reader: :private do
param :foo
option :bar
end
Support for `private` and `protected` attibute readers
param :id # public reader (default)
param :name, reader: :private
param :phone, reader: :protected
param :email, reader: false # no reader
param :age, reader: public
param :gender, reader: true # public as well
Support optional params and options
class User
extend Dry::Initializer
param :name, type: Dry::Types['strict.string']
param :email, type: Dry::Types['strict.string'], default: proc { nil }
param :phone, type: Dry::Types['strict.string'], optional: true
end
user = User.new "Andrew"
user.name # => "Andrew"
user.email # => nil (default)
user.phone # => Dry::Types::UNDEFINED (new feature)
Support dry-types only as type constraints
0.4.0 Bump v0.4.0 (change types constraints)
Deprecate non-dry-types as type constraints
0.3.3 Bump v0.3.3 (deprecation warnings)
Bug fix
Support for tolerance to unknown options
Class helpers tolerant_to_unknown_options
and intolerant_to_unknown_options
allows switching on/off a regime where undeclared options are ignored without error.
Update Mixin interface for adding plugins
Use Mixin#register_initializer_plugin
for adding plugins:
mixin.register_initializer_plugin NewPlugin
instead of:
mixin.initializer_builder.register NewPlugin