sequel 5.100.0 → 5.101.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9de2d20e1483de5f15a285b695d5eab98601c26f1e711e378de1a03331f197a1
|
|
4
|
+
data.tar.gz: 4d7df1811d7242dad22f6c9968fb43feecb5a86fd814aa2ba7434bdb44369cb8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a9aa7a3bd15f4f35457aace92b68b4734d367273996dc605d80adbe87bca1c945fc484571cad90149e69807980eea2f8b2a6a6fea85a4a0670c10a082a056a03
|
|
7
|
+
data.tar.gz: ca5c1eb34d71d16660a0b5eb2b9e5b4c784f06d6e4f89b036f00a62f31b57d564f071b8346bdcb9ebd9cced7bcfbe429e2c50bcda1b8b150d723b1e59105c474
|
|
@@ -372,6 +372,15 @@ module Sequel
|
|
|
372
372
|
# DB[:table].import([:x, :y], DB[:table2].select(:a, :b))
|
|
373
373
|
# # INSERT INTO table (x, y) SELECT a, b FROM table2
|
|
374
374
|
#
|
|
375
|
+
# The return value of this method is undefined and should not be used,
|
|
376
|
+
# except in two cases:
|
|
377
|
+
#
|
|
378
|
+
# * When the <tt>return: :primary_key</tt> option is used.
|
|
379
|
+
# * On PostgreSQL, when the dataset uses RETURNING. In this case, if
|
|
380
|
+
# a single value is returned per row, the return value is an array
|
|
381
|
+
# of those values. If multiple values are returned per row, the
|
|
382
|
+
# return value is an array of hashes.
|
|
383
|
+
#
|
|
375
384
|
# Options:
|
|
376
385
|
# :commit_every :: Open a new transaction for every given number of
|
|
377
386
|
# records. For example, if you provide a value of 50,
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
3
|
+
module Sequel
|
|
4
|
+
module Plugins
|
|
5
|
+
# The detect_unnecessary_association_options plugin can detect unnecessary
|
|
6
|
+
# association options, and either warn or raise if they are detected.
|
|
7
|
+
# This allows you to find and remove the unnecessary options.
|
|
8
|
+
# Association options are considered unnecessary if they specify the same
|
|
9
|
+
# value as Sequel's defaults.
|
|
10
|
+
#
|
|
11
|
+
# To detect unnecessary association options, you should load the plugin
|
|
12
|
+
# into your model base class (e.g. Sequel::Model) before loading your model
|
|
13
|
+
# classes. Then, after all models have been loaded, you can call the
|
|
14
|
+
# detect_unnecessary_association_options on each to check for unnecessary
|
|
15
|
+
# association options. Additionally, if you are calling finalize_associations,
|
|
16
|
+
# it will automatically check for unnecessary association options.
|
|
17
|
+
#
|
|
18
|
+
# A typical usage would be to combine this with the subclasses plugin:
|
|
19
|
+
#
|
|
20
|
+
# Sequel::Model.plugin :detect_unnecessary_association_options
|
|
21
|
+
# Sequel::Model.plugin :subclasses
|
|
22
|
+
# # load model classes
|
|
23
|
+
#
|
|
24
|
+
# # implicitly check all subclasses when freezing descendants
|
|
25
|
+
# Sequel::Model.freeze_descendants
|
|
26
|
+
#
|
|
27
|
+
# # or, if not freezing all descendants
|
|
28
|
+
# Sequel::Model.descendants.each(&:detect_unnecessary_association_options)
|
|
29
|
+
#
|
|
30
|
+
# By default, the plugin warns for every unnecessary association option.
|
|
31
|
+
# To raise an error instead, you can pass the <tt>action: :raise</tt> option when loading the
|
|
32
|
+
# plugin:
|
|
33
|
+
#
|
|
34
|
+
# Sequel::Model.plugin :detect_unnecessary_association_options, action: :raise
|
|
35
|
+
#
|
|
36
|
+
# This plugin only detects the most common unnecessary association options, such as:
|
|
37
|
+
#
|
|
38
|
+
# * :class (all associations)
|
|
39
|
+
# * :key and :primary_key (associations without join tables)
|
|
40
|
+
# * :join_table, :left_key, :right_key, :left_primary_key, :right_primary_key (single join table associations)
|
|
41
|
+
# * :left_primary_key, :right_primary_key (*_through_many associations)
|
|
42
|
+
#
|
|
43
|
+
# Only association types supported by default or supported by a plugin that
|
|
44
|
+
# ships with Sequel are supported by this plugin. Other association types are
|
|
45
|
+
# ignored.
|
|
46
|
+
module DetectUnnecessaryAssociationOptions
|
|
47
|
+
def self.configure(model, opts={})
|
|
48
|
+
model.instance_variable_set(:@detect_unnecessary_association_options_action, opts[:action] || :warn)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Raised if the plugin action is to raise and an unnecessary association option
|
|
52
|
+
# is detected.
|
|
53
|
+
class UnnecessaryAssociationOption < Sequel::Error
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
module ClassMethods
|
|
57
|
+
Plugins.inherited_instance_variables(self, :@detect_unnecessary_association_options_action => nil)
|
|
58
|
+
|
|
59
|
+
# Implicitly check for unnecessary association options when finalizing associations.
|
|
60
|
+
def finalize_associations
|
|
61
|
+
res = super
|
|
62
|
+
detect_unnecessary_association_options
|
|
63
|
+
res
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Check for unnecessary association options.
|
|
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
|
|
83
|
+
|
|
84
|
+
private
|
|
85
|
+
|
|
86
|
+
# Action to take if an unnecessary association option is detected.
|
|
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
|
|
94
|
+
|
|
95
|
+
# Detect unnecessary :class option.
|
|
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
|
|
118
|
+
|
|
119
|
+
# Detect other unnecessary options. An option is considered unnecessary
|
|
120
|
+
# if the key was submitted as an association option and the value for
|
|
121
|
+
# the option is the same as the given value.
|
|
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
|
|
127
|
+
|
|
128
|
+
# Same as _detect_unnecessary_association_options_key_value, but calls
|
|
129
|
+
# the default_* method on the association reflection to get the default value.
|
|
130
|
+
def _detect_unnecessary_association_options_key(ref, key)
|
|
131
|
+
_detect_unnecessary_association_options_key_value(ref, key, ref.send(:"default_#{key}"))
|
|
132
|
+
end
|
|
133
|
+
|
|
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
|
|
138
|
+
alias detect_unnecessary_association_options_pg_array_to_many detect_unnecessary_association_options_many_to_one
|
|
139
|
+
|
|
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
|
|
144
|
+
alias detect_unnecessary_association_options_one_to_one detect_unnecessary_association_options_one_to_many
|
|
145
|
+
alias detect_unnecessary_association_options_many_to_pg_array detect_unnecessary_association_options_one_to_many
|
|
146
|
+
|
|
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
|
|
154
|
+
alias detect_unnecessary_association_options_one_through_one detect_unnecessary_association_options_many_to_many
|
|
155
|
+
|
|
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
|
|
160
|
+
alias detect_unnecessary_association_options_one_through_many detect_unnecessary_association_options_many_through_many
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
data/lib/sequel/version.rb
CHANGED
|
@@ -6,7 +6,7 @@ module Sequel
|
|
|
6
6
|
|
|
7
7
|
# The minor version of Sequel. Bumped for every non-patch level
|
|
8
8
|
# release, generally around once a month.
|
|
9
|
-
MINOR =
|
|
9
|
+
MINOR = 101
|
|
10
10
|
|
|
11
11
|
# The tiny version of Sequel. Usually 0, only bumped for bugfix
|
|
12
12
|
# releases that fix regressions from previous versions.
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sequel
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.
|
|
4
|
+
version: 5.101.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jeremy Evans
|
|
@@ -344,6 +344,7 @@ files:
|
|
|
344
344
|
- lib/sequel/plugins/defaults_setter.rb
|
|
345
345
|
- lib/sequel/plugins/delay_add_association.rb
|
|
346
346
|
- lib/sequel/plugins/deprecated_associations.rb
|
|
347
|
+
- lib/sequel/plugins/detect_unnecessary_association_options.rb
|
|
347
348
|
- lib/sequel/plugins/dirty.rb
|
|
348
349
|
- lib/sequel/plugins/eager_each.rb
|
|
349
350
|
- lib/sequel/plugins/eager_graph_eager.rb
|