Sha256: e3565fe1faa5bce45db183acba9194c2d35ff97e77c92080caecf3fccb5cff06

Contents?: true

Size: 967 Bytes

Versions: 26

Compression:

Stored size: 967 Bytes

Contents

module Shoulda
  module Matchers
    module ActiveModel
      module NumericalityMatchers
        # @private
        class EvenNumberMatcher < NumericTypeMatcher
          NON_EVEN_NUMBER_VALUE = 1

          def simple_description
            description = ''

            if expects_strict?
              description << 'strictly '
            end

            description +
              "disallow :#{attribute} from being an odd number"
          end

          def allowed_type_adjective
            'even'
          end

          def diff_to_compare
            2
          end

          protected

          def wrap_disallow_value_matcher(matcher)
            matcher.with_message(:even)
          end

          def disallowed_value
            if @numeric_type_matcher.given_numeric_column?
              NON_EVEN_NUMBER_VALUE
            else
              NON_EVEN_NUMBER_VALUE.to_s
            end
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
shoulda-matchers-6.4.0 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-6.3.1 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-6.3.0 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-6.2.0 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-6.1.0 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-6.0.0 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-5.3.0 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-5.2.0 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-5.1.0 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-5.0.0 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-5.0.0.rc1 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-4.5.1 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-4.5.0 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-4.4.1 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-4.4.0 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-4.3.0 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-4.2.0 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-4.1.2 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-4.1.1 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb
shoulda-matchers-4.1.0 lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb