mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
Remove old version checks
This commit is contained in:
parent
076714d648
commit
a1f42fce28
@ -14,27 +14,18 @@ module ValidatesTimeliness
|
||||
timeliness_column_for_attribute(attr_name).type
|
||||
end
|
||||
|
||||
if ::ActiveModel.version >= Gem::Version.new('4.2')
|
||||
def timeliness_column_for_attribute(attr_name)
|
||||
columns_hash.fetch(attr_name.to_s) do |key|
|
||||
validation_type = _validators[key.to_sym].find {|v| v.kind == :timeliness }.type.to_s
|
||||
::ActiveRecord::ConnectionAdapters::Column.new(key, nil, lookup_cast_type(validation_type), validation_type)
|
||||
end
|
||||
def timeliness_column_for_attribute(attr_name)
|
||||
columns_hash.fetch(attr_name.to_s) do |key|
|
||||
validation_type = _validators[key.to_sym].find {|v| v.kind == :timeliness }.type.to_s
|
||||
::ActiveRecord::ConnectionAdapters::Column.new(key, nil, lookup_cast_type(validation_type), validation_type)
|
||||
end
|
||||
end
|
||||
|
||||
def lookup_cast_type(sql_type)
|
||||
case sql_type
|
||||
when 'datetime' then ::ActiveRecord::Type::DateTime.new
|
||||
when 'date' then ::ActiveRecord::Type::Date.new
|
||||
when 'time' then ::ActiveRecord::Type::Time.new
|
||||
end
|
||||
end
|
||||
else
|
||||
def timeliness_column_for_attribute(attr_name)
|
||||
columns_hash.fetch(attr_name.to_s) do |key|
|
||||
validation_type = _validators[key.to_sym].find {|v| v.kind == :timeliness }.type.to_s
|
||||
::ActiveRecord::ConnectionAdapters::Column.new(key, nil, validation_type)
|
||||
end
|
||||
def lookup_cast_type(sql_type)
|
||||
case sql_type
|
||||
when 'datetime' then ::ActiveRecord::Type::DateTime.new
|
||||
when 'date' then ::ActiveRecord::Type::Date.new
|
||||
when 'time' then ::ActiveRecord::Type::Time.new
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -55,11 +55,6 @@ module ValidatesTimeliness
|
||||
end
|
||||
end
|
||||
|
||||
# Rails 4.0 compatibility for old #setup method with class as arg
|
||||
if Gem::Version.new(ActiveModel::VERSION::STRING) <= Gem::Version.new('4.1')
|
||||
alias_method(:setup, :setup_timeliness_validated_attributes)
|
||||
end
|
||||
|
||||
def validate_each(record, attr_name, value)
|
||||
raw_value = attribute_raw_value(record, attr_name) || value
|
||||
return if (@allow_nil && raw_value.nil?) || (@allow_blank && raw_value.blank?)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user