Sha256: b50833971246cdd7ec20166a14ee112c05948803a55eaf4dcc3e48ba53b9ac0c

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module ValidatesTimeliness
  module HelperMethods
    extend ActiveSupport::Concern

    included do
      include ValidationMethods
      extend ValidationMethods
      class_inheritable_hash :timeliness_validated_attributes
      self.timeliness_validated_attributes = {}
    end

    module ValidationMethods
      def validates_date(*attr_names)
        timeliness_validation_for attr_names, :date
      end

      def validates_time(*attr_names)
        timeliness_validation_for attr_names, :time
      end

      def validates_datetime(*attr_names)
        timeliness_validation_for attr_names, :datetime
      end

      def timeliness_validation_for(attr_names, type)
        options = _merge_attributes(attr_names)
        options[:type] = type
        attributes = attr_names.inject({}) {|validated, attr_name|
          attr_name = attr_name.to_s
          validated[attr_name] = type
          validated
        }
        self.timeliness_validated_attributes = attributes
        validates_with Validator, options
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
validates_timeliness-3.0.0.beta.3 lib/validates_timeliness/helper_methods.rb
validates_timeliness-3.0.0.beta.2 lib/validates_timeliness/helper_methods.rb