- Allow
optional
attribute to be left undefined (@nepalez)
- Support of modules and case equality as type constraints (@nepalez)
- Add deprecation warnings about modules and case equality as type constraints (@nepalez)
- Add explicit requirement for ruby 'set' (@rickenharp)
- Support for tolerance to unknown options (@nepalez)
Breaks interface for adding new plugins. Register new plugin via:
def self.extended(klass)
klass.register_initializer_plugin NewPlugin
end
instead of:
def self.extended(klass)
klass.initializer_builder.register NewPlugin
end
While the private method ##initializer_builder is still accessible its method #register doesn't mutate the builder instance.
- Made Mixin##initializer_builder method private (@nepalez)
- Add Mixin#register_initializer_plugin(plugin) method (@nepalez)
- Prevent plugin's registry from polluting superclass (@nepalez)
- Make all instances (Builder and Signature) immutable (@nepalez)
- Decouple mixin from a builder to prevent pollution (@nepalez)
- Ensure default value block can use private variables (@jeremyf)
- Fix polluting superclass with declarations from subclass (@nepalez)
- Make all instances (Builder and Signature) immutable (@nepalez)
- Decouple mixin from a builder to prevent pollution (@nepalez)
- Ensure default value block can use private variables (@jeremyf)
The gem internals has been rewritten heavily to make the gem pluggable and fix bugs in "container style". Type constraints were extracted to a plugin that should be added explicitly.
Small extensions were added to type constraints to support constraint by any
object, and apply value coercion via dry-types
.
Default assignments became slower (while plain type constraint are not)!
-
Make dry-types constraint to coerce variables (@nepalez)
# This will coerce `name: :foo` to `"foo"` option :name, type: Dry::Types::Coercible::String
-
Stop supporing proc type constraint (@nepalez)
option :name, type: ->(v) { String === v } # this does NOT work any more
later it will be implemented via coercion plugin (not added by default):
require 'dry/initializer/coercion' class MyClass extend Dry::Initializer::Mixin extend Dry::Initializer::Coercion option :name, coercer: ->(v) { (String === v) ? v.to_sym : fail } end
-
Support type constraint via every object's case equality (@nepalez)
option :name, type: /foo/ option :name, type: (1..14)
-
Support defaults and type constraints for the "container" syntax (@nepalez)
-
Support adding extensions via plugin system (@nepalez)
-
Private method
##__after_initialize__
is added by theMixin
along with#initialize
(@nepalez)The previous implementation required defaults and types to be stored in the class method
.initializer_builder
. That made "container" syntax to support neither defaults nor types.Now the
#initializer
is still defined viainstance_eval(code)
for efficiency. Some operations (like default assignments, coercions, dry-type constraints etc.) cannot be implemented in this way. They are made inside##__after_initialize__
callback, that is biult viadefault_method(&block)
using instance evals.
include Dry::Initializer.define -> do .. end
syntax (@flash-gordon)
Class DSL splitted to mixin and container versions (thanks to @AMHOL for the idea). Backward compatibility is broken.
- Use
extend Dry::Initializer::Mixin
instead ofextend Dry::Initializer
(@nepalez)
- Use
include Dry::Initializer.define(&block)
as an alternative to extending the class (@nepalez)
First public release