Module: ActiveRecord::Associations::Deprecation
- Defined in:
- lib/active_record/associations/deprecation.rb
Overview
:nodoc:
Class Attribute Summary collapse
-
.backtrace ⇒ Object
Returns the value of attribute backtrace.
-
.mode ⇒ Object
Returns the value of attribute mode.
Class Method Summary collapse
Class Attribute Details
.backtrace ⇒ Object
Returns the value of attribute backtrace.
14 15 16 |
# File 'lib/active_record/associations/deprecation.rb', line 14 def backtrace @backtrace end |
.mode ⇒ Object
Returns the value of attribute mode.
14 15 16 |
# File 'lib/active_record/associations/deprecation.rb', line 14 def mode @mode end |
Class Method Details
.guard(reflection) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File '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:) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File '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 |