mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-23 06:16:44 +00:00
Refactor timeliness method definition
This commit is contained in:
parent
48fd72ae5b
commit
8c1ba048df
@ -30,11 +30,15 @@ module ValidatesTimeliness
|
|||||||
def define_timeliness_methods(before_type_cast=false)
|
def define_timeliness_methods(before_type_cast=false)
|
||||||
return if timeliness_validated_attributes.blank?
|
return if timeliness_validated_attributes.blank?
|
||||||
timeliness_validated_attributes.each do |attr_name|
|
timeliness_validated_attributes.each do |attr_name|
|
||||||
define_timeliness_write_method(attr_name)
|
define_attribute_timeliness_methods(attr_name, before_type_cast)
|
||||||
define_timeliness_before_type_cast_method(attr_name) if before_type_cast
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def define_attribute_timeliness_methods(attr_name, before_type_cast=false)
|
||||||
|
define_timeliness_write_method(attr_name)
|
||||||
|
define_timeliness_before_type_cast_method(attr_name) if before_type_cast
|
||||||
|
end
|
||||||
|
|
||||||
def define_timeliness_write_method(attr_name)
|
def define_timeliness_write_method(attr_name)
|
||||||
method_body, line = <<-EOV, __LINE__ + 1
|
method_body, line = <<-EOV, __LINE__ + 1
|
||||||
def #{attr_name}=(value)
|
def #{attr_name}=(value)
|
||||||
|
|||||||
@ -17,6 +17,17 @@ module ValidatesTimeliness
|
|||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
public
|
||||||
|
|
||||||
|
def timeliness_attribute_timezone_aware?(attr_name)
|
||||||
|
attr_name = attr_name.to_s
|
||||||
|
create_time_zone_conversion_attribute?(attr_name, columns_hash[attr_name])
|
||||||
|
end
|
||||||
|
|
||||||
|
def timeliness_attribute_type(attr_name)
|
||||||
|
columns_hash[attr_name.to_s].type
|
||||||
|
end
|
||||||
|
|
||||||
def define_attribute_methods
|
def define_attribute_methods
|
||||||
super.tap do |attribute_methods_generated|
|
super.tap do |attribute_methods_generated|
|
||||||
use_before_type_cast = ValidatesTimeliness::ORM::ActiveRecord.use_plugin_cache?
|
use_before_type_cast = ValidatesTimeliness::ORM::ActiveRecord.use_plugin_cache?
|
||||||
@ -24,16 +35,14 @@ module ValidatesTimeliness
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def define_timeliness_methods(before_type_cast=false)
|
protected
|
||||||
return if timeliness_validated_attributes.blank?
|
|
||||||
|
|
||||||
timeliness_validated_attributes.each do |attr_name|
|
def define_attribute_timeliness_methods(attr_name, before_type_cast=false)
|
||||||
if before_type_cast
|
if before_type_cast
|
||||||
define_timeliness_write_method(attr_name)
|
define_timeliness_write_method(attr_name)
|
||||||
define_timeliness_before_type_cast_method(attr_name)
|
define_timeliness_before_type_cast_method(attr_name)
|
||||||
elsif ValidatesTimeliness.use_plugin_parser
|
elsif ValidatesTimeliness.use_plugin_parser
|
||||||
define_timeliness_write_method_without_cache(attr_name)
|
define_timeliness_write_method_without_cache(attr_name)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -49,15 +58,6 @@ module ValidatesTimeliness
|
|||||||
generated_timeliness_methods.module_eval(method_body, __FILE__, line)
|
generated_timeliness_methods.module_eval(method_body, __FILE__, line)
|
||||||
end
|
end
|
||||||
|
|
||||||
def timeliness_attribute_timezone_aware?(attr_name)
|
|
||||||
attr_name = attr_name.to_s
|
|
||||||
create_time_zone_conversion_attribute?(attr_name, columns_hash[attr_name])
|
|
||||||
end
|
|
||||||
|
|
||||||
def timeliness_attribute_type(attr_name)
|
|
||||||
columns_hash[attr_name.to_s].type
|
|
||||||
end
|
|
||||||
|
|
||||||
def timeliness_type_cast_code(attr_name, var_name)
|
def timeliness_type_cast_code(attr_name, var_name)
|
||||||
type = timeliness_attribute_type(attr_name)
|
type = timeliness_attribute_type(attr_name)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user