Module: ValidatesTimeliness::Extensions::DateTimeSelect
- Defined in:
- lib/validates_timeliness/extensions/date_time_select.rb
Defined Under Namespace
Classes: DateTimeValue
Constant Summary collapse
- POSITION =
{ :year => 1, :month => 2, :day => 3, :hour => 4, :min => 5, :sec => 6 }.freeze
Instance Attribute Summary collapse
-
#html_options ⇒ Object
Intercepts the date and time select helpers to reuse the values from the params rather than the parsed value.
-
#method_name ⇒ Object
Intercepts the date and time select helpers to reuse the values from the params rather than the parsed value.
-
#object_name ⇒ Object
Intercepts the date and time select helpers to reuse the values from the params rather than the parsed value.
-
#options ⇒ Object
Intercepts the date and time select helpers to reuse the values from the params rather than the parsed value.
-
#template_object ⇒ Object
Intercepts the date and time select helpers to reuse the values from the params rather than the parsed value.
Instance Method Summary collapse
-
#value(*object) ⇒ Object
Splat args to support Rails 5.0 which expects object, and 5.2 which doesn’t.
Instance Attribute Details
#html_options ⇒ Object
Intercepts the date and time select helpers to reuse the values from the params rather than the parsed value. This allows invalid date/time values to be redisplayed instead of blanks to aid correction by the user. It’s a minor usability improvement which is rarely an issue for the user.
8 9 10 |
# File 'lib/validates_timeliness/extensions/date_time_select.rb', line 8 def @html_options end |
#method_name ⇒ Object
Intercepts the date and time select helpers to reuse the values from the params rather than the parsed value. This allows invalid date/time values to be redisplayed instead of blanks to aid correction by the user. It’s a minor usability improvement which is rarely an issue for the user.
8 9 10 |
# File 'lib/validates_timeliness/extensions/date_time_select.rb', line 8 def method_name @method_name end |
#object_name ⇒ Object
Intercepts the date and time select helpers to reuse the values from the params rather than the parsed value. This allows invalid date/time values to be redisplayed instead of blanks to aid correction by the user. It’s a minor usability improvement which is rarely an issue for the user.
8 9 10 |
# File 'lib/validates_timeliness/extensions/date_time_select.rb', line 8 def object_name @object_name end |
#options ⇒ Object
Intercepts the date and time select helpers to reuse the values from the params rather than the parsed value. This allows invalid date/time values to be redisplayed instead of blanks to aid correction by the user. It’s a minor usability improvement which is rarely an issue for the user.
8 9 10 |
# File 'lib/validates_timeliness/extensions/date_time_select.rb', line 8 def @options end |
#template_object ⇒ Object
Intercepts the date and time select helpers to reuse the values from the params rather than the parsed value. This allows invalid date/time values to be redisplayed instead of blanks to aid correction by the user. It’s a minor usability improvement which is rarely an issue for the user.
8 9 10 |
# File 'lib/validates_timeliness/extensions/date_time_select.rb', line 8 def template_object @template_object end |
Instance Method Details
#value(*object) ⇒ Object
Splat args to support Rails 5.0 which expects object, and 5.2 which doesn’t
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/validates_timeliness/extensions/date_time_select.rb', line 34 def value(*object) return super unless @template_object.params[@object_name] pairs = @template_object.params[@object_name].select {|k,v| k =~ /^#{@method_name}\(/ } return super if pairs.empty? values = {} pairs.each_pair do |key, value| position = key[/\((\d+)\w+\)/, 1] values[POSITION.key(position.to_i)] = value.to_i end DateTimeValue.new(**values) end |