mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 07:16:41 +00:00
fixe for attribute write and raw value methods
add new generalised method to get raw value without dependence on before_type_cast which may not be supported in ORMs call super to define full ORM write method default
This commit is contained in:
@@ -22,9 +22,16 @@ module ValidatesTimeliness
|
||||
end
|
||||
EOV
|
||||
class_eval(method_body, __FILE__, line)
|
||||
else
|
||||
super
|
||||
end
|
||||
super rescue(NoMethodError)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def _timeliness_raw_value_for(attr_name)
|
||||
@attributes_cache && @attributes_cache["_#{attr_name}_before_type_cast"]
|
||||
end
|
||||
|
||||
end
|
||||
@@ -35,7 +42,7 @@ module ValidatesTimeliness
|
||||
if timeliness_validated_attributes.include?(attr_name)
|
||||
method_body, line = <<-EOV, __LINE__ + 1
|
||||
def #{attr_name}_before_type_cast
|
||||
@attributes_cache && @attributes_cache["_#{attr_name}_before_type_cast"]
|
||||
_timeliness_raw_value_for('#{attr_name}')
|
||||
end
|
||||
EOV
|
||||
class_eval(method_body, __FILE__, line)
|
||||
|
||||
@@ -56,8 +56,7 @@ module ValidatesTimeliness
|
||||
end
|
||||
|
||||
def attribute_raw_value(record, attr_name)
|
||||
before_type_cast = "#{attr_name}_before_type_cast"
|
||||
record.send(before_type_cast) if record.respond_to?(before_type_cast)
|
||||
record._timeliness_raw_value_for(attr_name)
|
||||
end
|
||||
|
||||
def type_cast(value)
|
||||
|
||||
Reference in New Issue
Block a user