dry-bot on master
[devtools] sync (compare)
flash-gordon on master
It's 2021 everyone! (compare)
flash-gordon on v1.5.0
dry-bot on master
[devtools] sync (compare)
flash-gordon on master
Set release date (compare)
flash-gordon on master
Add docs for fallbacks and cust… (compare)
dry-bot on master
[devtools] sync (compare)
flash-gordon on master
Update changelog.yml (compare)
Foo
is loaded first than Zoo
, then if I define like the standar way, it would be trigger an error that said Zoo
is undefined or something because Zoo
is not loaded yet, except I define require_relative 'zoo'
on top of foo.rb
file and I want to avoid this.
Zoo
in your case) to the top of my struct class files is exactly what I do in my apps.
require "dry/validation"
require "time_math"
schema = Dry::Validation.Schema do
configure do
def self.messages
super.merge(en: {errors: {ends_at_within_two_weeks_of_starts_at: 'must be within two weeks of start time'}})
end
end
required(:starts_at).filled(:time?)
required(:ends_at).filled(:time?)
validate(ends_at_within_two_weeks_of_starts_at: [:starts_at, :ends_at]) do |starts_at, ends_at|
two_weeks = 2 * 7 * 24 * 60
(ends_at - starts_at) <= two_weeks
end
end
valid_input = {
starts_at: TimeMath.day.decrease(Time.now, 10),
ends_at: Time.now,
}
schema.(valid_input).messages
# => {}
invalid_input = {
starts_at: TimeMath.day.decrease(Time.now, 20),
ends_at: Time.now,
}
schema.(invalid_input).messages
# => {:ends_at_within_two_weeks_of_starts_at=>["must be within two weeks of start time"]}