module Sequel::Plugins::DeprecatedAssociations::ClassMethods
Public Instance Methods
Source
# File lib/sequel/plugins/deprecated_associations.rb 64 def association_reflection(assoc) 65 ref = super 66 if ref && ref[:deprecated] 67 emit_deprecated_association_warning(ref, nil) do 68 "Access of association reflection for deprecated association: class:#{name} association:#{assoc}" 69 end 70 end 71 ref 72 end
Issue a deprecation warning if the association is deprecated.
Calls superclass method
Private Instance Methods
Source
# File lib/sequel/plugins/deprecated_associations.rb 80 def association_module_def(name, opts=OPTS, &block) 81 super 82 if opts[:deprecated] && name[0] != "_" 83 deprecated_associations_module.module_exec do 84 define_method(name) do |*a, &b| 85 self.class.send(:emit_deprecated_association_warning, opts, name) do 86 "Calling deprecated association method: class:#{self.class.name} association:#{opts[:name]} method:#{name}" 87 end 88 super(*a, &b) 89 end 90 alias_method name, name 91 end 92 end 93 nil 94 end
Issue a deprecation warning when the defined method is called if the association is deprecated and the method name does not start with the underscore (to avoid not warning twice, once for the public association method and once for the private association method).
Calls superclass method
Source
# File lib/sequel/plugins/deprecated_associations.rb 98 def association_module_delegate_def(name, opts, &block) 99 super 100 if opts[:deprecated] 101 deprecated_associations_module.module_exec do 102 define_method(name) do |*a, &b| 103 self.class.send(:emit_deprecated_association_warning, opts, name) do 104 "Calling deprecated association method: class:#{self.class.name} association:#{opts[:name]} method:#{name}" 105 end 106 super(*a, &b) 107 end 108 # :nocov: 109 ruby2_keywords(name) if respond_to?(:ruby2_keywords, true) 110 # :nocov: 111 alias_method(name, name) 112 end 113 end 114 nil 115 end
Issue a deprecation warning when the defined method is called if the association is deprecated.
Calls superclass method
Source
# File lib/sequel/plugins/deprecated_associations.rb 120 def deprecated_associations_module 121 return @deprecated_associations_module if defined?(@deprecated_associations_module) 122 @deprecated_associations_module = Module.new 123 include(@deprecated_associations_module) 124 @deprecated_associations_module 125 end
A module to add deprecated association methods to. These methods handle issuing the deprecation warnings, and call super to get the default behavior.
Source
# File lib/sequel/plugins/deprecated_associations.rb 129 def emit_deprecated_association_warning(ref, method) 130 config = @deprecated_associations_config 131 132 raise Access, yield if config[:raise] 133 134 unless config[:deduplicate] == false 135 emit = false 136 ref.send(:cached_fetch, [:deprecated_associations, method]) do 137 emit = true 138 end 139 return unless emit 140 end 141 142 if config[:backtrace] 143 warn yield, caller(2) 144 else 145 warn yield, :uplevel => 2 146 end 147 end
Emit a deprecation warning, or raise an exception if the :raise plugin option was used.