Last active
February 4, 2020 11:26
-
-
Save katafrakt/d328a37f3937d32fce3c26198ac733d9 to your computer and use it in GitHub Desktop.
Revisions
-
katafrakt revised this gist
Feb 4, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ class ReservationValidation include Hanami::Validations predicate :before? do |other, current| current < other end -
katafrakt revised this gist
Feb 3, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ class ReservationValidation include Hanami::Validations predicate :before? do |current, other| current < other end -
katafrakt created this gist
Feb 3, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ require 'hanami/validations' class ReservationValidation include Hanami::Validations predicate :before?, message: '' do |current, other| 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