Class: ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter
- Inherits:
-
Type::Value
- Object
- ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter
- Defined in:
- lib/active_record/attribute_methods/time_zone_conversion.rb
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.new(subtype) ⇒ Object
9 10 11 |
# File 'lib/active_record/attribute_methods/time_zone_conversion.rb', line 9 def self.new(subtype) self === subtype ? subtype : super end |
Instance Method Details
#==(other) ⇒ Object
39 40 41 |
# File 'lib/active_record/attribute_methods/time_zone_conversion.rb', line 39 def ==(other) other.is_a?(self.class) && __getobj__ == other.__getobj__ end |
#cast(value) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_record/attribute_methods/time_zone_conversion.rb', line 17 def cast(value) return if value.nil? if value.is_a?(Hash) set_time_zone_without_conversion(super) elsif value.respond_to?(:in_time_zone) begin result = super(user_input_in_time_zone(value)) || super if result && type == :time result = result.change(year: 2000, month: 1, day: 1) end result rescue ArgumentError nil end elsif value.respond_to?(:infinite?) && value.infinite? value else map(super) { |v| cast(v) } end end |
#deserialize(value) ⇒ Object
13 14 15 |
# File 'lib/active_record/attribute_methods/time_zone_conversion.rb', line 13 def deserialize(value) convert_time_to_time_zone(super) end |