Sha256: de9488c581a88605b12d0d9a5f8da72bd5ad98bccb573010c4f2f0f21fa5319e

Contents?: true

Size: 1.31 KB

Versions: 17

Compression:

Stored size: 1.31 KB

Contents

module ValidatesTimeliness
  module ValidationMethods

    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods

      def validates_time(*attr_names)
        configuration = attr_names.extract_options!
        configuration[:type] = :time
        validates_timeliness_of(attr_names, configuration)
      end
      
      def validates_date(*attr_names)
        configuration = attr_names.extract_options!
        configuration[:type] = :date
        validates_timeliness_of(attr_names, configuration)
      end
      
      def validates_datetime(*attr_names)
        configuration = attr_names.extract_options!
        configuration[:type] = :datetime
        validates_timeliness_of(attr_names, configuration)
      end

      private

      def validates_timeliness_of(attr_names, configuration)
        validator = ValidatesTimeliness::Validator.new(configuration.symbolize_keys)
        
        # bypass handling of allow_nil and allow_blank to validate raw value
        configuration.delete(:allow_nil)
        configuration.delete(:allow_blank)
        validates_each(attr_names, configuration) do |record, attr_name, value|
          validator.call(record, attr_name, value)
        end
      end

    end

  end
end

ActiveRecord::Base.send(:include, ValidatesTimeliness::ValidationMethods)

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
adzap-validates_timeliness-2.0.0 lib/validates_timeliness/validation_methods.rb
adzap-validates_timeliness-2.1.0 lib/validates_timeliness/validation_methods.rb
adzap-validates_timeliness-2.2.0 lib/validates_timeliness/validation_methods.rb
adzap-validates_timeliness-2.2.1 lib/validates_timeliness/validation_methods.rb
adzap-validates_timeliness-2.2.2 lib/validates_timeliness/validation_methods.rb
markos_validates_timeliness-2.3.2.2 lib/validates_timeliness/validation_methods.rb
markos_validates_timeliness-2.3.2.1 lib/validates_timeliness/validation_methods.rb
markos_validates_timeliness-2.3.2 lib/validates_timeliness/validation_methods.rb
validates_timeliness-2.3.2 lib/validates_timeliness/validation_methods.rb
szilm-validates_timeliness-2.3.1 lib/validates_timeliness/validation_methods.rb
validates_timeliness-2.3.1 lib/validates_timeliness/validation_methods.rb
validates_timeliness-2.3.0 lib/validates_timeliness/validation_methods.rb
validates_timeliness-2.2.2 lib/validates_timeliness/validation_methods.rb
validates_timeliness-2.2.1 lib/validates_timeliness/validation_methods.rb
validates_timeliness-2.2.0 lib/validates_timeliness/validation_methods.rb
validates_timeliness-2.1.0 lib/validates_timeliness/validation_methods.rb
validates_timeliness-2.0.0 lib/validates_timeliness/validation_methods.rb