sequel 5.96.0 → 5.97.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: 52123540e6fde4ed7ade970b36fc60898bae7463c0e22f63c4205748365cd82b
4
- data.tar.gz: e3374571d1e4fc490d3e2dc847679a2d8893b196c152d26f760b723605951ddd
3
+ metadata.gz: 236cf31a3c7848a6699dc871558a387748593a83dda8a722aad2e1c6beaad2d9
4
+ data.tar.gz: 974c8617fcecc74f10fab9c7fa8dd9e2f74a7a56767cf47cafd95e1108cc5f57
5
5
  SHA512:
6
- metadata.gz: a4a48515dcb90df9ca6dde4b657f6d1ccce0724b0bd6d09c2a36aed3f37d338fe468135f177fb7cd5f985c79a5e06a91d1459731dc2fdc21601083863d9efd1a
7
- data.tar.gz: 3c18417f6991a190781cf0098aa81dae3077f52e5fed75162352ffe10fc2f065b5b9ffad1db3bdded7ecc8afed7ea698fc1047570a98dc8a7a87470e7cc2290e
6
+ metadata.gz: 5b396689d99af2a0882358e80150dc452b96a9cd09a73a9cdace42b903dd0958d341bf67e0570bd382dd051df54dc66b2d2b3e396506518c619d08bd006ebd1b
7
+ data.tar.gz: '0839e0177ccbb9d67880835b92e0b8767ea339b96375da914d0471a2cc24f25cdffbd8ada3b45ba69bdfc167a4609ed44fde1a7fd1db4c7574dff3f2efbfd80f'
@@ -571,6 +571,7 @@ module Sequel
571
571
  # :if_exists :: Don't raise an error if the schema doesn't exist.
572
572
  def drop_schema(name, opts=OPTS)
573
573
  self << drop_schema_sql(name, opts)
574
+ remove_all_cached_schemas
574
575
  end
575
576
 
576
577
  # Drops a trigger from the database. Arguments:
@@ -726,6 +727,14 @@ module Sequel
726
727
  Sequel.synchronize{@primary_key_sequences[quoted_table] = value} if value
727
728
  end
728
729
 
730
+ # Rename a schema in the database. Arguments:
731
+ # name :: Current name of the schema
732
+ # opts :: New name for the schema
733
+ def rename_schema(name, new_name)
734
+ self << rename_schema_sql(name, new_name)
735
+ remove_all_cached_schemas
736
+ end
737
+
729
738
  # Refresh the materialized view with the given name.
730
739
  #
731
740
  # DB.refresh_view(:items_view)
@@ -1806,6 +1815,18 @@ module Sequel
1806
1815
  super
1807
1816
  end
1808
1817
 
1818
+ # Clear all cached schema information
1819
+ def remove_all_cached_schemas
1820
+ @primary_keys.clear
1821
+ @primary_key_sequences.clear
1822
+ @schemas.clear
1823
+ end
1824
+
1825
+ # SQL for renaming a schema.
1826
+ def rename_schema_sql(name, new_name)
1827
+ "ALTER SCHEMA #{quote_identifier(name)} RENAME TO #{quote_identifier(new_name)}"
1828
+ end
1829
+
1809
1830
  # SQL DDL statement for renaming a table. PostgreSQL doesn't allow you to change a table's schema in
1810
1831
  # a rename table operation, so specifying a new schema in new_name will not have an effect.
1811
1832
  def rename_table_sql(name, new_name)
@@ -1256,8 +1256,6 @@ module Sequel
1256
1256
  # receiver's current order. This yields the row and the array of order expressions
1257
1257
  # to the block, which should return an array of values to use.
1258
1258
  def ignore_values_preceding(row)
1259
- @opts[:order].map{|v| v.is_a?(SQL::OrderedExpression) ? v.expression : v}
1260
-
1261
1259
  order_exprs = @opts[:order].map do |v|
1262
1260
  if v.is_a?(SQL::OrderedExpression)
1263
1261
  descending = v.descending
@@ -37,18 +37,11 @@ module Sequel
37
37
  value.to_s
38
38
  end
39
39
 
40
- if RUBY_VERSION >= '2.4'
41
- def _typecast_value_string_to_decimal(value)
42
- BigDecimal(value)
43
- rescue
44
- BigDecimal('0.0')
45
- end
46
- else
47
- # :nocov:
48
- def _typecast_value_string_to_decimal(value)
49
- BigDecimal(value)
50
- end
51
- # :nocov:
40
+ # Typecast invalid BigDecimal to 0.0.
41
+ def _typecast_value_string_to_decimal(value)
42
+ BigDecimal(value)
43
+ rescue
44
+ BigDecimal('0.0')
52
45
  end
53
46
  end
54
47
 
@@ -421,6 +421,17 @@ module Sequel
421
421
  @exclude_end
422
422
  end
423
423
 
424
+ # Support a friendly output
425
+ def inspect
426
+ range = if empty?
427
+ "empty"
428
+ else
429
+ "#{@exclude_begin ? "(" : "["}#{@begin},#{@end}#{@exclude_end ? ")" : "]"}"
430
+ end
431
+
432
+ "#<#{self.class.name} #{range}#{"::#{@db_type}" if @db_type}>"
433
+ end
434
+
424
435
  # Append a literalize version of the receiver to the sql.
425
436
  def sql_literal_append(ds, sql)
426
437
  if (s = @db_type) && !empty?
@@ -3063,7 +3063,7 @@ module Sequel
3063
3063
  if (((op == :'=' || op == :'!=') && r.is_a?(Sequel::Model)) ||
3064
3064
  (multiple = ((op == :IN || op == :'NOT IN') && ((is_ds = r.is_a?(Sequel::Dataset)) || (r.respond_to?(:all?) && r.all?{|x| x.is_a?(Sequel::Model)})))))
3065
3065
  l = args[0]
3066
- if ar = model.association_reflections[l]
3066
+ if ar = model.association_reflection(l)
3067
3067
  raise Error, "filtering by associations is not allowed for #{ar.inspect}" if ar[:allow_filtering_by] == false
3068
3068
 
3069
3069
  if multiple
@@ -0,0 +1,151 @@
1
+ # frozen-string-literal: true
2
+
3
+ module Sequel
4
+ module Plugins
5
+ # The deprecated_associations plugin adds support for
6
+ # deprecating associations. Attempts to use association
7
+ # methods and access association metadata for deprecated
8
+ # associations results in a warning.
9
+ #
10
+ # Album.plugin :deprecated_associations
11
+ # Album.many_to_one :artist, deprecated: true
12
+ # album = Album[1]
13
+ #
14
+ # # Warnings for all of the following calls
15
+ # album.artist
16
+ # album.artist_dataset
17
+ # album.artist = Artist[2]
18
+ # Album.association_reflection(:artist)
19
+ # Album.eager(:artist)
20
+ # Album.eager_graph(:artist)
21
+ # Album.where(artist: Artist[1]).all
22
+ #
23
+ # By default, the plugin issues a single warning per
24
+ # association method or association reflection. See
25
+ # DeprecatedAssociations.configure for options to make
26
+ # deprecated association issue warnings for every access,
27
+ # to include backtraces in warnings, or to raise an
28
+ # exception instead of warning.
29
+ #
30
+ # Note that Model.association_reflections and
31
+ # Model.all_association_reflections will include deprecated
32
+ # associations, and accessing the metadata for deprecated
33
+ # associations through these interfaces not issue warnings.
34
+ #
35
+ # Usage:
36
+ #
37
+ # # Make all models support deprecated associations
38
+ # # (called before loading subclasses)
39
+ # Sequel::Model.plugin :deprecated_associations
40
+ #
41
+ # # Make Album class support deprecated associations
42
+ # Album.plugin :deprecated_associations
43
+ module DeprecatedAssociations
44
+ # Exception class used for deprecated association use when
45
+ # raising exceptions instead of emitting warnings.
46
+ class Access < Sequel::Error; end
47
+
48
+ # Configure the deprecated associations plugin. Options:
49
+ #
50
+ # backtrace: Print backtrace with warning
51
+ # deduplicate: Set to false to emit warnings for every
52
+ # deprecated association method call/access
53
+ # (when not caching associations, this is always false)
54
+ # raise: Raise Sequel::Plugin::DeprecatedAssociations::Access
55
+ # instead of warning
56
+ def self.configure(model, opts = OPTS)
57
+ model.instance_exec do
58
+ (@deprecated_associations_config ||= {}).merge!(opts)
59
+ end
60
+ end
61
+
62
+ module ClassMethods
63
+ # Issue a deprecation warning if the association is deprecated.
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
73
+
74
+ private
75
+
76
+ # Issue a deprecation warning when the defined method is called if the
77
+ # association is deprecated and the method name does not start with the
78
+ # underscore (to avoid not warning twice, once for the public association
79
+ # method and once for the private association method).
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
95
+
96
+ # Issue a deprecation warning when the defined method is called if the
97
+ # association is deprecated.
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
116
+
117
+ # A module to add deprecated association methods to. These methods
118
+ # handle issuing the deprecation warnings, and call super to get the
119
+ # default behavior.
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
126
+
127
+ # Emit a deprecation warning, or raise an exception if the :raise
128
+ # plugin option was used.
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
148
+ end
149
+ end
150
+ end
151
+ end
@@ -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 = 96
9
+ MINOR = 97
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.96.0
4
+ version: 5.97.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
@@ -342,6 +342,7 @@ files:
342
342
  - lib/sequel/plugins/def_dataset_method.rb
343
343
  - lib/sequel/plugins/defaults_setter.rb
344
344
  - lib/sequel/plugins/delay_add_association.rb
345
+ - lib/sequel/plugins/deprecated_associations.rb
345
346
  - lib/sequel/plugins/dirty.rb
346
347
  - lib/sequel/plugins/eager_each.rb
347
348
  - lib/sequel/plugins/eager_graph_eager.rb