Sha256: 3558b00970f6448345282ad65c30dfa23cbdc4f611e97d265d6f29156a59c901
Contents?: true
Size: 1.26 KB
Versions: 1
Compression:
Stored size: 1.26 KB
Contents
module ValidatesTimeliness module AttributeMethods extend ActiveSupport::Concern included do class_attribute :timeliness_validated_attributes self.timeliness_validated_attributes = [] end end end ActiveModel::Type::Date.class_eval do # Module.new do |m| def cast_value(value) return super unless ValidatesTimeliness.use_plugin_parser if value.is_a?(::String) return if value.empty? value = Timeliness::Parser.parse(value, :date) value.to_date if value elsif value.respond_to?(:to_date) value.to_date else value end end # end.tap { |mod| include mod } end ActiveModel::Type::Time.class_eval do def user_input_in_time_zone(value) if value.is_a?(String) && ValidatesTimeliness.use_plugin_parser dummy_time_value = value.sub(/\A(\d\d\d\d-\d\d-\d\d |)/, Date.current.to_s + ' ') Timeliness::Parser.parse(dummy_time_value, :datetime, zone: :current) else value.in_time_zone end end end ActiveModel::Type::DateTime.class_eval do def user_input_in_time_zone(value) if value.is_a?(String) && ValidatesTimeliness.use_plugin_parser Timeliness::Parser.parse(value, :datetime, zone: :current) else value.in_time_zone end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
validates_timeliness-5.0.0.alpha1 | lib/validates_timeliness/attribute_methods.rb |