mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 07:16:41 +00:00
Fix DateTimeSelect extension for Rails 3.1.0
This commit is contained in:
parent
e7b503ae4f
commit
473da0fa5e
@ -16,16 +16,10 @@ module ValidatesTimeliness
|
|||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
|
|
||||||
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 = year
|
@year, @month, @day, @hour, @min, @sec = year, month, day, hour, min, sec
|
||||||
@month = month
|
|
||||||
@day = day
|
|
||||||
@hour = hour
|
|
||||||
@min = min
|
|
||||||
@sec = 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)
|
||||||
@ -46,13 +40,15 @@ module ValidatesTimeliness
|
|||||||
datetime_selector_without_timeliness(*args)
|
datetime_selector_without_timeliness(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def value(object)
|
def value_with_timeliness(object)
|
||||||
unless @timeliness_date_or_time_tag && @template_object.params[@object_name]
|
unless @timeliness_date_or_time_tag && @template_object.params[@object_name]
|
||||||
return super
|
return value_without_timeliness(object)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@template_object.params[@object_name]
|
||||||
|
|
||||||
pairs = @template_object.params[@object_name].select {|k,v| k =~ /^#{@method_name}\(/ }
|
pairs = @template_object.params[@object_name].select {|k,v| k =~ /^#{@method_name}\(/ }
|
||||||
return super if pairs.empty?
|
return value_without_timeliness(object) if pairs.empty?
|
||||||
|
|
||||||
values = [nil] * 6
|
values = [nil] * 6
|
||||||
pairs.map do |(param, value)|
|
pairs.map do |(param, value)|
|
||||||
|
|||||||
@ -31,7 +31,7 @@ module TestModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize(attributes = nil)
|
def initialize(attributes = nil)
|
||||||
@attributes = self.class.model_attributes.inject({}) do |hash, column|
|
@attributes = self.class.model_attributes.keys.inject({}) do |hash, column|
|
||||||
hash[column.to_s] = nil
|
hash[column.to_s] = nil
|
||||||
hash
|
hash
|
||||||
end
|
end
|
||||||
@ -39,7 +39,7 @@ module TestModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def attributes
|
def attributes
|
||||||
@attributes.keys
|
@attributes
|
||||||
end
|
end
|
||||||
|
|
||||||
def attributes=(new_attributes={})
|
def attributes=(new_attributes={})
|
||||||
@ -49,14 +49,12 @@ module TestModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(method_id, *args, &block)
|
def method_missing(method_id, *args, &block)
|
||||||
if !self.class.attribute_methods_generated?
|
if match_attribute_method?(method_id.to_s)
|
||||||
self.class.define_attribute_methods self.class.model_attributes.keys.map(&:to_s)
|
self.class.define_attribute_methods self.class.model_attributes.keys
|
||||||
method_name = method_id.to_s
|
|
||||||
send(method_id, *args, &block)
|
send(method_id, *args, &block)
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user