Last active
February 4, 2020 11:26
-
-
Save katafrakt/d328a37f3937d32fce3c26198ac733d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'hanami/validations' | |
class ReservationValidation | |
include Hanami::Validations | |
predicate :before? do |other, current| | |
current < other | |
end | |
validations do | |
required(:check_in).filled | |
required(:check_out).filled | |
rule valid_dates: [:check_in, :check_out] do |check_in, check_out| | |
check_in.before?(check_out) | |
end | |
end | |
end | |
date1 = Date.new(2020,1,20) | |
date2 = Date.new(2010,2,1) | |
ReservationValidation.new(check_in: date1, check_out: date2).validate.success? | |
# => true | |
ReservationValidation.new(check_in: date2, check_out: date1).validate.success? | |
# => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment