Module: ActiveRecord::Associations::Deprecation
Do not use. This module is for internal use only.
Relationships & Source Files | |
Defined in: | activerecord/lib/active_record/associations/deprecation.rb |
Constant Summary
-
EVENT =
private
# File 'activerecord/lib/active_record/associations/deprecation.rb', line 7"deprecated_association.active_record"
-
MODES =
private
# File 'activerecord/lib/active_record/associations/deprecation.rb', line 10[:warn, :raise, :notify].freeze
Class Attribute Summary
- .backtrace rw
- .backtrace=(value) rw
- .mode rw
-
.mode=(value)
rw
private setter.
- .set_backtrace_supports_array_of_locations? ⇒ Boolean readonly private
Class Method Summary
- .guard(reflection)
- .report(reflection, context:)
- .backtrace_cleaner private
- .clean_frames private
- .clean_locations private
- .user_facing_reflection(reflection) private
Class Attribute Details
.backtrace (rw)
[ GitHub ]# File 'activerecord/lib/active_record/associations/deprecation.rb', line 14
attr_reader :mode, :backtrace
.backtrace=(value) (rw)
[ GitHub ]# File 'activerecord/lib/active_record/associations/deprecation.rb', line 24
def backtrace=(value) @backtrace = !!value end
.mode (rw)
[ GitHub ]# File 'activerecord/lib/active_record/associations/deprecation.rb', line 14
attr_reader :mode, :backtrace
.mode=(value) (rw)
private setter
.set_backtrace_supports_array_of_locations? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'activerecord/lib/active_record/associations/deprecation.rb', line 77
def set_backtrace_supports_array_of_locations? @backtrace_supports_array_of_locations ||= Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") end
Class Method Details
.backtrace_cleaner (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/deprecation.rb', line 65
def backtrace_cleaner ActiveRecord::LogSubscriber.backtrace_cleaner end
.clean_frames (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/deprecation.rb', line 69
def clean_frames backtrace_cleaner.clean(caller) end
.clean_locations (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/deprecation.rb', line 73
def clean_locations backtrace_cleaner.clean_locations(caller_locations) end
.guard(reflection)
[ GitHub ]# File 'activerecord/lib/active_record/associations/deprecation.rb', line 28
def guard(reflection) report(reflection, context: yield) if reflection.deprecated? if reflection.through_reflection? reflection.deprecated_nested_reflections.each do |deprecated_nested_reflection| context = "referenced as nested association of the through #{reflection.active_record}##{reflection.name}" report(deprecated_nested_reflection, context: context) end end end
.report(reflection, context:)
[ GitHub ]# File 'activerecord/lib/active_record/associations/deprecation.rb', line 39
def report(reflection, context:) reflection = user_facing_reflection(reflection) = +"The association #{reflection.active_record}##{reflection.name} is deprecated, #{context}" << " (#{backtrace_cleaner.first_clean_frame})" case @mode when :warn = [, *clean_frames].join("\n\t") if @backtrace ActiveRecord::Base.logger&.warn( ) when :raise error = ActiveRecord::DeprecatedAssociationError.new( ) if set_backtrace_supports_array_of_locations? error.set_backtrace(clean_locations) else error.set_backtrace(clean_frames) end raise error else payload = { reflection: reflection, message: , location: backtrace_cleaner.first_clean_location } payload[:backtrace] = clean_locations if @backtrace ActiveSupport::Notifications.instrument(EVENT, payload) end end
.user_facing_reflection(reflection) (private)
[ GitHub ]# File 'activerecord/lib/active_record/associations/deprecation.rb', line 81
def user_facing_reflection(reflection) case reflection.parent_reflection when ActiveRecord::Reflection::HasAndBelongsToManyReflection reflection.parent_reflection else reflection end end