Sha256: 65d4b77960ca57b149adeb0af42a5e910df54872b8eebf4ac41d4348c667c04d

Contents?: true

Size: 941 Bytes

Versions: 48

Compression:

Stored size: 941 Bytes

Contents

require 'active_record'

module Incline::Extensions
  ##
  # Patches the TimeZoneConverter to call super.
  module TimeZoneConverter

    ##
    # Patches the TimeZoneConverter to call super.
    def self.included(base)
      base.class_eval do

        undef type_cast_from_user

        def type_cast_from_user(value)
          if value.is_a?(::Array)
            value.map { |v| type_cast_from_user(v) }
          else
            # Convert to time first.
            value = super

            # Then convert the time zone if necessary.
            if value.respond_to?(:in_time_zone)
              begin
                value.in_time_zone
              rescue ArgumentError
                nil
              end
            else
              nil
            end
          end
        end
      end
    end

  end
end

ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter.include Incline::Extensions::TimeZoneConverter

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
incline-0.3.14 lib/incline/extensions/time_zone_converter.rb
incline-0.3.13 lib/incline/extensions/time_zone_converter.rb
incline-0.3.12 lib/incline/extensions/time_zone_converter.rb
incline-0.3.11 lib/incline/extensions/time_zone_converter.rb
incline-0.3.10 lib/incline/extensions/time_zone_converter.rb
incline-0.3.9 lib/incline/extensions/time_zone_converter.rb
incline-0.3.8 lib/incline/extensions/time_zone_converter.rb
incline-0.3.7 lib/incline/extensions/time_zone_converter.rb
incline-0.3.6 lib/incline/extensions/time_zone_converter.rb
incline-0.3.5 lib/incline/extensions/time_zone_converter.rb
incline-0.3.4 lib/incline/extensions/time_zone_converter.rb
incline-0.3.3 lib/incline/extensions/time_zone_converter.rb
incline-0.3.2 lib/incline/extensions/time_zone_converter.rb
incline-0.3.1 lib/incline/extensions/time_zone_converter.rb
incline-0.3.0 lib/incline/extensions/time_zone_converter.rb
incline-0.2.36 lib/incline/extensions/time_zone_converter.rb
incline-0.2.35 lib/incline/extensions/time_zone_converter.rb
incline-0.2.34 lib/incline/extensions/time_zone_converter.rb
incline-0.2.28 lib/incline/extensions/time_zone_converter.rb
incline-0.2.27 lib/incline/extensions/time_zone_converter.rb