Class: ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter
- Inherits:
-
Type::Value
- Object
- Type::Value
- ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter
- Includes:
- Type::Decorator
- Defined in:
- lib/active_record/attribute_methods/time_zone_conversion.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from Type::Value
Instance Method Summary collapse
- #convert_time_to_time_zone(value) ⇒ Object
- #type_cast_from_database(value) ⇒ Object
- #type_cast_from_user(value) ⇒ Object
Methods included from Type::Decorator
Methods inherited from Type::Value
#==, #binary?, #changed?, #changed_in_place?, #hash, #initialize, #klass, #number?, #text?, #type, #type_cast_for_database, #type_cast_for_schema
Constructor Details
This class inherits a constructor from ActiveRecord::Type::Value
Instance Method Details
#convert_time_to_time_zone(value) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/active_record/attribute_methods/time_zone_conversion.rb', line 23 def convert_time_to_time_zone(value) if value.is_a?(Array) value.map { |v| convert_time_to_time_zone(v) } elsif value.acts_like?(:time) value.in_time_zone else value end end |
#type_cast_from_database(value) ⇒ Object
7 8 9 |
# File 'lib/active_record/attribute_methods/time_zone_conversion.rb', line 7 def type_cast_from_database(value) convert_time_to_time_zone(super) end |
#type_cast_from_user(value) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/active_record/attribute_methods/time_zone_conversion.rb', line 11 def type_cast_from_user(value) if value.is_a?(Array) value.map { |v| type_cast_from_user(v) } elsif value.respond_to?(:in_time_zone) begin value.in_time_zone || super rescue ArgumentError nil end end end |