mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
Restore usage of DateTime substitute value object
Remove initialize override. Not sure why what was added.
This commit is contained in:
parent
4fef42ac24
commit
941055c16e
@ -11,9 +11,23 @@ module ValidatesTimeliness
|
|||||||
:year => 1, :month => 2, :day => 3, :hour => 4, :min => 5, :sec => 6
|
:year => 1, :month => 2, :day => 3, :hour => 4, :min => 5, :sec => 6
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
def initialize(object_name, method_name, template_object, options, html_options)
|
class DateTimeValue
|
||||||
@object_name, @method_name = object_name.to_s.dup, method_name.to_s.dup
|
attr_accessor :year, :month, :day, :hour, :min, :sec
|
||||||
@template_object, @options, @html_options = template_object, options, html_options
|
|
||||||
|
def initialize(year:, month:, day: nil, hour: nil, min: nil, sec: nil)
|
||||||
|
@year, @month, @day, @hour, @min, @sec = year, month, day, hour, min, sec
|
||||||
|
end
|
||||||
|
|
||||||
|
def change(options)
|
||||||
|
self.class.new(
|
||||||
|
year: options.fetch(:year, year),
|
||||||
|
month: options.fetch(:month, month),
|
||||||
|
day: options.fetch(:day, day),
|
||||||
|
hour: options.fetch(:hour, hour),
|
||||||
|
min: options.fetch(:min) { options[:hour] ? 0 : min },
|
||||||
|
sec: options.fetch(:sec) { options[:hour] || options[:min] ? 0 : sec }
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Splat args to support Rails 5.0 which expects object, and 5.2 which doesn't
|
# Splat args to support Rails 5.0 which expects object, and 5.2 which doesn't
|
||||||
@ -29,7 +43,7 @@ module ValidatesTimeliness
|
|||||||
values[POSITION.key(position.to_i)] = value.to_i
|
values[POSITION.key(position.to_i)] = value.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
values
|
DateTimeValue.new(values)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user