Module: ActiveRecord::MonkeyPatch

Defined in:
lib/activerecord/monkey_patch.rb,
lib/activerecord/monkey_patch/rails4_2.rb,
lib/activerecord/monkey_patch/rails5_0.rb,
lib/activerecord/monkey_patch/rails5_1.rb,
lib/activerecord/monkey_patch/rails5_2.rb

Constant Summary collapse

SUPPORTED_MAJOR_VERSION =
5
MINIMUM_SUPPORTED_VERSION =
'5.2.0'.freeze

Class Method Summary collapse

Class Method Details

.adjust_timezone_offset(opts) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/activerecord/monkey_patch.rb', line 18

def adjust_timezone_offset(opts)
  if ActiveRecord::Base.connection_config[:adapter] != 'oracle_enhanced' ||
    ActiveRecord::VERSION::MAJOR != SUPPORTED_MAJOR_VERSION ||
    ActiveRecord.version < Gem::Version.create(MINIMUM_SUPPORTED_VERSION) ||
    Gem::Version.create(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::VERSION ) > Gem::Version.create('1.7.3')
    return opts
  end

  case opts
  when Array
    opts.each_with_object([]) {|v, ret|
      ret << if v.is_a?(Time) || v.is_a?(Date)
        offset = v.to_time.utc_offset

        offset.positive? ? v.to_time.ago(offset) : v.to_time.since(offset)
      else
        v
      end
    }
  when Hash
    opts.each_with_object({}) {|(c, v), ret|
      ret[c] = if v.is_a?(Time) || v.is_a?(Date)
        offset = v.to_time.utc_offset

        offset.positive? ? v.to_time.ago(offset) : v.to_time.since(offset)
      else
        v
      end
    }
  else
    opts
  end
end