module Sequel::Plugins::DetectUnnecessaryAssociationOptions::ClassMethods
Public Instance Methods
Source
# File lib/sequel/plugins/detect_unnecessary_association_options.rb 67 def detect_unnecessary_association_options 68 @association_reflections.each_value do |ref| 69 meth = "detect_unnecessary_association_options_#{ref[:type]}" 70 # Expected to call private methods. 71 # Ignore unrecognized association types. 72 # External association types can define the appropriate method to 73 # support their own unnecessary association option checks. 74 if respond_to?(meth, true) 75 # All recognized association types need same class check 76 _detect_unnecessary_association_options_class(ref) 77 send(meth, ref) 78 end 79 end 80 81 nil 82 end
Check for unnecessary association options.
Source
# File lib/sequel/plugins/detect_unnecessary_association_options.rb 60 def finalize_associations 61 res = super 62 detect_unnecessary_association_options 63 res 64 end
Implicitly check for unnecessary association options when finalizing associations.
Calls superclass method
Private Instance Methods
Source
# File lib/sequel/plugins/detect_unnecessary_association_options.rb 96 def _detect_unnecessary_association_options_class(ref) 97 return unless ref[:orig_class] 98 99 h = {} 100 name = ref[:name] 101 late_binding_class_option(h, ref.returns_array? ? singularize(name) : name) 102 103 begin 104 default_association_class = constantize(h[:class_name]) 105 actual_association_class = ref.associated_class 106 rescue NameError 107 # Do not warn. For the default association class to not be a valid 108 # constant is expected. For the actual association class to not be 109 # a valid constant is not expected and a bug in the association, but 110 # the job of this plugin is not to detect invalid options, only 111 # unnecessary options. 112 else 113 if default_association_class.equal?(actual_association_class) 114 unnecessary_association_options_detected(ref, "class") 115 end 116 end 117 end
Detect unnecessary :class option.
Source
# File lib/sequel/plugins/detect_unnecessary_association_options.rb 130 def _detect_unnecessary_association_options_key(ref, key) 131 _detect_unnecessary_association_options_key_value(ref, key, ref.send(:"default_#{key}")) 132 end
Same as _detect_unnecessary_association_options_key_value, but calls the default_* method on the association reflection to get the default value.
Source
# File lib/sequel/plugins/detect_unnecessary_association_options.rb 122 def _detect_unnecessary_association_options_key_value(ref, key, value) 123 if ref[:orig_opts].has_key?(key) && ref[:orig_opts][key] == value 124 unnecessary_association_options_detected(ref, key) 125 end 126 end
Detect other unnecessary options. An option is considered unnecessary if the key was submitted as an association option and the value for the option is the same as the given value.
Source
# File lib/sequel/plugins/detect_unnecessary_association_options.rb 156 def detect_unnecessary_association_options_many_through_many(ref) 157 _detect_unnecessary_association_options_key_value(ref, :left_primary_key, primary_key) 158 _detect_unnecessary_association_options_key_value(ref, :right_primary_key, ref.associated_class.primary_key) 159 end
Also aliased as: detect_unnecessary_association_options_one_through_many
Source
# File lib/sequel/plugins/detect_unnecessary_association_options.rb 147 def detect_unnecessary_association_options_many_to_many(ref) 148 [:join_table, :left_key, :right_key].each do |key| 149 _detect_unnecessary_association_options_key(ref, key) 150 end 151 _detect_unnecessary_association_options_key_value(ref, :left_primary_key, primary_key) 152 _detect_unnecessary_association_options_key_value(ref, :right_primary_key, ref.associated_class.primary_key) 153 end
Also aliased as: detect_unnecessary_association_options_one_through_one
Source
# File lib/sequel/plugins/detect_unnecessary_association_options.rb 134 def detect_unnecessary_association_options_many_to_one(ref) 135 _detect_unnecessary_association_options_key(ref, :key) 136 _detect_unnecessary_association_options_key_value(ref, :primary_key, ref.associated_class.primary_key) 137 end
Also aliased as: detect_unnecessary_association_options_pg_array_to_many
Source
# File lib/sequel/plugins/detect_unnecessary_association_options.rb 140 def detect_unnecessary_association_options_one_to_many(ref) 141 _detect_unnecessary_association_options_key(ref, :key) 142 _detect_unnecessary_association_options_key_value(ref, :primary_key, primary_key) 143 end
Source
# File lib/sequel/plugins/detect_unnecessary_association_options.rb 87 def unnecessary_association_options_detected(ref, key) 88 if @detect_unnecessary_association_options_action == :raise 89 raise UnnecessaryAssociationOption, "#{ref.inspect} :#{key} option unnecessary" 90 else 91 warn "#{ref.inspect} :#{key} option unnecessary" 92 end 93 end
Action to take if an unnecessary association option is detected.