flash-gordon on master
Halt with mutable backtrace Ex… Merge pull request #116 from jo… (compare)
AS::Dependencies
so it knows about constants loaded by the system
super
without ()
would forward arguments if defined as *args
irb
class MyClass
extend Dry::Initializer::Mixin
param :foo
param :bar
def initialize(*args)
# do some custom initialization stuff here
super # calling super without () will forward all arguments
end
end
@keeperhood yes it would. My example displays that you principally can add new arguments of the initializer that does not defined by dry-initializer
. But this time you should know what arguments to send to super
explicitly.
What Dry::Initializer::Mixin
does is provides a module with #initialize
method defined, and then includes the module to the class. If you wish not to pollute your class scope with helpers (like param
and option
), you can make this inclusion explicitly:
class MyClass
include Dry::Initializer.define -> do
param :foo
param :bar
end
end
In any case what you get is the module with initialize
method in a sequence of class ancestors. Then you can work with it via super
in a common ruby way.
module Web
module Blog
module Schemas
module Posts
Update = Dry::Validation.Form do
required(:id, :int).value(:int?)
required(:post).schema do
required(:title, :str).value(:str?)
required(:content, :str).value(:str?)
end
end
end
end
end
end
module Blog
module Validators
module Posts
Update = Dry::Validation.Schema do
required(:id)
required(:title).filled(min_size?: 3)
required(:content).filled(min_size?: 100)
end
end
end
end
require 'dry-validation'
module Blog
module Validators
module Posts
Update = Dry::Validation.Schema do
required(:id)
end
end
end
end
Blog::Validators::Posts::Update.({})
# => #<Dry::Validation::Result output={} messages={}>
.filled
is valid