Sha256: 52e31394b9056e204e24adf62343696aaba2e228d04dceaf47d34126455643b8
Contents?: true
Size: 856 Bytes
Versions: 11
Compression:
Stored size: 856 Bytes
Contents
# Load Application record from the upstream require "application_record" module RailsBase class ApplicationRecord < ::ApplicationRecord self.abstract_class = true def self._magically_defined_time_objects columns.each do |column| next unless [:datetime].include?(column.type) # This is actually pretty cool. If you set the thread corectly, you can define_method("#{column.name}") do thread_tz = Thread.current[RailsBaseApplicationController::TIMEZONE_THREAD_NAME] return super() if thread_tz.nil? time = self[column.name].in_time_zone(thread_tz) rescue self[column.name] Rails.logger.debug { "#{self.class.name}.#{column.name} intercepted :datetime [#{self[column.name]}] and returned [#{time}] - tz[#{thread_tz}]" } time end end end end end
Version data entries
11 entries across 11 versions & 1 rubygems