Sha256: feb3ac15639964bb0969bce74b8a1b313d3390e893c2bd5dae97b03debc24184

Contents?: true

Size: 452 Bytes

Versions: 5

Compression:

Stored size: 452 Bytes

Contents

module ActiveModel
  module Validations
    class YearValidator < ActiveModel::EachValidator
      def validate_each(record, attribute, value)
        return if value.blank?
        unless (min .. max).include? value
          record.errors.add attribute, :year_invalid, min: min, max: max
        end
      end

    private
      def min
        options[:min] || 1700
      end

      def max
        options[:max] || 2200
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activemodel-validators-3.0.1 lib/activemodel-validators/year_validator.rb
activemodel-validators-3.0.0 lib/activemodel-validators/year_validator.rb
activemodel-validators-2.0.0 lib/activemodel-validators/year_validator.rb
activemodel-validators-1.2.0 lib/activemodel-validators/year_validator.rb
activemodel-validators-1.1.0 lib/activemodel-validators/year_validator.rb