Dry::Validation.Form
vs Dry::Validation.Schema
? I was intrigued by this recent post (http://cucumbersome.net/2016/09/06/rails-form-objects-with-dry-rb.html) and can see that he's not using Validation.Form
but the Dry docs do. Can anyone give more context?
App.finalize 'persistence' do |persistence|
init do
p "Init stage"
end
end
Dry::Validation.Form
, the difference is that (because dry-validation currently handles coercions and validations) Dry::Validation.Form
provides form specific
coercions, i.e. 0 => false
, 1 => true
for booleans, whereas Dry::Validation.Schema
provides more generic coercions, see: http://dry-rb.org/gems/dry-validation/input-preprocessing/
gemfile(true) do
gem 'dry-validation'
end
schema = Dry::Validation.Form do
required(:email).filled(:str?)
required(:age).filled(:int?, gt?: 18)
end
schema.call(email: 'test', age: 18, blah: 'blag').to_h
# => {:email=>"test", :age=>18}
[23] pry(main)> ArticleSchema.call({blah: "sdf"}).to_h
=> {:blah=>"sdf"}
App.finalize!
or explicitly boot persistence (App.boot('persistence')
anywhere?
boot!
App.finalize!
booter.finalize!
is run I investigated it
call
method is invoked then finalizers
hash is empty
container
and finalizer
variables are nil
ComicsScraper.namespace(:persistence) do |persistence|
persistence.finalize(:rom) do
init do
end
start do
end
end
end
finalizers
hash contains this value: {:rom=>[ComicsScraper, #<Proc:0x007f9cb4205870@/Users/wafcio/projects/comics/scraper/system/boot/persistence.rb:2>]}
call
method is invoked with :persistence
argument, so it looks :persistence
key in finalizers
hash.
ComicsScraper.namespace
=> ComicsScraper.finalize
ComicsScraper.finalize!
I run it
Yeah but this:
ComicsScraper.namespace(:persistence) do |persistence|
persistence.finalize(:rom) do
init do
end
start do
end
end
end
Should be:
ComicsScraper.finalize(:persistence) do |container|
container.register(:rom) do
init do
end
start do
end
end
end
container.register
should be called in the init
block
# system/boot/db.rb
Application.finalize(:db) do |container|
init do
require 'some/3rd/party/db'
container.register(:db, DB.configure(ENV['DB_URL']))
end
start do
db.establish_connection
end
stop do
db.close_connection
end
end
:rom
component, but that registers persistence.rom
in the container
dry-validation
?
rom-sql
since there are custom types built for postgres (for example)