# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true if defined?(ActionController) && defined?(ActionController::Railties) && defined?(ActionController::Railties::Helpers) module ActionController module Railties # Used to monkey patch all the inherited calls in action_pack # # This is the usual entry point for Rails inheritance work, so it should # catch most of the calls to inherited. module Helpers alias_method :cs__patched_inherited, :inherited def inherited klass klass&.instance_variable_set(:@cs__defining_class, true) cs__patched_inherited(klass) ensure klass&.instance_variable_set(:@cs__defining_class, false) end end end end end if defined?(ActiveRecord) && defined?(ActiveRecord::AttributeMethods) && defined?(ActiveRecord::AttributeMethods::TimeZoneConversion) && defined?(ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods) module ActiveRecord module AttributeMethods # Used to monkey patch all the inherited calls in action_pack module TimeZoneConversion module ClassMethods #:nodoc: private alias_method :cs__patched_inherited, :inherited def inherited klass klass&.instance_variable_set(:@cs__defining_class, true) cs__patched_inherited(klass) ensure klass&.instance_variable_set(:@cs__defining_class, false) end end end end end end