Skip to content

Instantly share code, notes, and snippets.

@katafrakt
Last active February 4, 2020 11:26
Show Gist options
  • Select an option

  • Save katafrakt/d328a37f3937d32fce3c26198ac733d9 to your computer and use it in GitHub Desktop.

Select an option

Save katafrakt/d328a37f3937d32fce3c26198ac733d9 to your computer and use it in GitHub Desktop.

Revisions

  1. katafrakt revised this gist Feb 4, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion validation.rb
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    class ReservationValidation
    include Hanami::Validations

    predicate :before? do |current, other|
    predicate :before? do |other, current|
    current < other
    end

  2. katafrakt revised this gist Feb 3, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion validation.rb
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    class ReservationValidation
    include Hanami::Validations

    predicate :before?, message: '' do |current, other|
    predicate :before? do |current, other|
    current < other
    end

  3. katafrakt created this gist Feb 3, 2020.
    27 changes: 27 additions & 0 deletions validation.rb
    Original 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