mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
Merge pull request #61 from carlosantoniodasilva/rails-3.2-deprecation-warnings
Remove deprecated InstanceMethods module when using AS::Concern
This commit is contained in:
commit
68b2579ca0
@ -65,15 +65,12 @@ module ValidatesTimeliness
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
def _timeliness_raw_value_for(attr_name)
|
||||||
def _timeliness_raw_value_for(attr_name)
|
@timeliness_cache && @timeliness_cache[attr_name.to_s]
|
||||||
@timeliness_cache && @timeliness_cache[attr_name.to_s]
|
|
||||||
end
|
|
||||||
|
|
||||||
def _clear_timeliness_cache
|
|
||||||
@timeliness_cache = {}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def _clear_timeliness_cache
|
||||||
|
@timeliness_cache = {}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -15,11 +15,11 @@ module ValidatesTimeliness
|
|||||||
|
|
||||||
class TimelinessDateTime
|
class TimelinessDateTime
|
||||||
attr_accessor :year, :month, :day, :hour, :min, :sec
|
attr_accessor :year, :month, :day, :hour, :min, :sec
|
||||||
|
|
||||||
def initialize(year, month, day, hour, min, sec)
|
def initialize(year, month, day, hour, min, sec)
|
||||||
@year, @month, @day, @hour, @min, @sec = year, month, day, hour, min, sec
|
@year, @month, @day, @hour, @min, @sec = year, month, day, hour, min, sec
|
||||||
end
|
end
|
||||||
|
|
||||||
# adapted from activesupport/lib/active_support/core_ext/date_time/calculations.rb, line 36 (3.0.7)
|
# adapted from activesupport/lib/active_support/core_ext/date_time/calculations.rb, line 36 (3.0.7)
|
||||||
def change(options)
|
def change(options)
|
||||||
TimelinessDateTime.new(
|
TimelinessDateTime.new(
|
||||||
@ -30,35 +30,32 @@ module ValidatesTimeliness
|
|||||||
options[:min] || (options[:hour] ? 0 : min),
|
options[:min] || (options[:hour] ? 0 : min),
|
||||||
options[:sec] || ((options[:hour] || options[:min]) ? 0 : sec)
|
options[:sec] || ((options[:hour] || options[:min]) ? 0 : sec)
|
||||||
)
|
)
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module InstanceMethods
|
|
||||||
def datetime_selector_with_timeliness(*args)
|
|
||||||
@timeliness_date_or_time_tag = true
|
|
||||||
datetime_selector_without_timeliness(*args)
|
|
||||||
end
|
|
||||||
|
|
||||||
def value_with_timeliness(object)
|
|
||||||
unless @timeliness_date_or_time_tag && @template_object.params[@object_name]
|
|
||||||
return value_without_timeliness(object)
|
|
||||||
end
|
|
||||||
|
|
||||||
@template_object.params[@object_name]
|
|
||||||
|
|
||||||
pairs = @template_object.params[@object_name].select {|k,v| k =~ /^#{@method_name}\(/ }
|
|
||||||
return value_without_timeliness(object) if pairs.empty?
|
|
||||||
|
|
||||||
values = [nil] * 6
|
|
||||||
pairs.map do |(param, value)|
|
|
||||||
position = param.scan(/\((\d+)\w+\)/).first.first
|
|
||||||
values[position.to_i-1] = value.to_i
|
|
||||||
end
|
|
||||||
|
|
||||||
TimelinessDateTime.new(*values)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def datetime_selector_with_timeliness(*args)
|
||||||
|
@timeliness_date_or_time_tag = true
|
||||||
|
datetime_selector_without_timeliness(*args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def value_with_timeliness(object)
|
||||||
|
unless @timeliness_date_or_time_tag && @template_object.params[@object_name]
|
||||||
|
return value_without_timeliness(object)
|
||||||
|
end
|
||||||
|
|
||||||
|
@template_object.params[@object_name]
|
||||||
|
|
||||||
|
pairs = @template_object.params[@object_name].select {|k,v| k =~ /^#{@method_name}\(/ }
|
||||||
|
return value_without_timeliness(object) if pairs.empty?
|
||||||
|
|
||||||
|
values = [nil] * 6
|
||||||
|
pairs.map do |(param, value)|
|
||||||
|
position = param.scan(/\((\d+)\w+\)/).first.first
|
||||||
|
values[position.to_i-1] = value.to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
TimelinessDateTime.new(*values)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -30,13 +30,10 @@ module ValidatesTimeliness
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
def reload(*args)
|
||||||
def reload(*args)
|
_clear_timeliness_cache
|
||||||
_clear_timeliness_cache
|
super
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user