rom-sql 3.6.5 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +1 -2
  4. data/lib/rom/plugins/relation/sql/auto_restrictions.rb +4 -1
  5. data/lib/rom/plugins/relation/sql/instrumentation.rb +6 -2
  6. data/lib/rom/plugins/relation/sql/postgres/explain.rb +1 -1
  7. data/lib/rom/plugins/relation/sql/postgres/full_text_search.rb +31 -12
  8. data/lib/rom/plugins/relation/sql/postgres/streaming.rb +6 -6
  9. data/lib/rom/sql/associations/many_to_many.rb +6 -3
  10. data/lib/rom/sql/associations/many_to_one.rb +3 -0
  11. data/lib/rom/sql/attribute.rb +22 -8
  12. data/lib/rom/sql/attribute_aliasing.rb +7 -6
  13. data/lib/rom/sql/commands/create.rb +4 -3
  14. data/lib/rom/sql/commands/update.rb +4 -3
  15. data/lib/rom/sql/dsl.rb +3 -1
  16. data/lib/rom/sql/extensions/active_support_notifications.rb +1 -1
  17. data/lib/rom/sql/extensions/postgres/type_builder.rb +7 -7
  18. data/lib/rom/sql/extensions/postgres/type_serializer.rb +2 -2
  19. data/lib/rom/sql/extensions/postgres/types/geometric.rb +12 -12
  20. data/lib/rom/sql/extensions/postgres/types/json.rb +9 -3
  21. data/lib/rom/sql/extensions/postgres/types/ltree.rb +106 -36
  22. data/lib/rom/sql/extensions/postgres/types/range.rb +18 -18
  23. data/lib/rom/sql/extensions/rails_log_subscriber.rb +4 -4
  24. data/lib/rom/sql/function.rb +37 -18
  25. data/lib/rom/sql/gateway.rb +8 -7
  26. data/lib/rom/sql/group_dsl.rb +7 -2
  27. data/lib/rom/sql/migration/inline_runner.rb +8 -2
  28. data/lib/rom/sql/migration/migrator.rb +5 -5
  29. data/lib/rom/sql/migration/recorder.rb +10 -4
  30. data/lib/rom/sql/migration/runner.rb +5 -4
  31. data/lib/rom/sql/migration/schema_diff.rb +15 -10
  32. data/lib/rom/sql/migration/writer.rb +8 -8
  33. data/lib/rom/sql/migration.rb +5 -5
  34. data/lib/rom/sql/order_dsl.rb +6 -2
  35. data/lib/rom/sql/plugin/associates.rb +21 -7
  36. data/lib/rom/sql/plugin/pagination.rb +2 -2
  37. data/lib/rom/sql/projection_dsl.rb +1 -1
  38. data/lib/rom/sql/relation/reading.rb +83 -71
  39. data/lib/rom/sql/relation/writing.rb +19 -13
  40. data/lib/rom/sql/relation.rb +74 -28
  41. data/lib/rom/sql/restriction_dsl.rb +6 -2
  42. data/lib/rom/sql/schema/attributes_inferrer.rb +2 -2
  43. data/lib/rom/sql/schema/dsl.rb +2 -2
  44. data/lib/rom/sql/schema/index_dsl.rb +5 -6
  45. data/lib/rom/sql/schema/inferrer.rb +23 -19
  46. data/lib/rom/sql/schema/type_builder.rb +5 -2
  47. data/lib/rom/sql/schema.rb +10 -10
  48. data/lib/rom/sql/tasks/migration_tasks.rake +4 -5
  49. data/lib/rom/sql/transaction.rb +1 -0
  50. data/lib/rom/sql/type_dsl.rb +7 -3
  51. data/lib/rom/sql/type_extensions.rb +4 -4
  52. data/lib/rom/sql/type_serializer.rb +2 -2
  53. data/lib/rom/sql/types.rb +2 -2
  54. data/lib/rom/sql/version.rb +1 -1
  55. data/lib/rom/types/values.rb +2 -4
  56. metadata +9 -15
@@ -16,7 +16,7 @@ module ROM
16
16
  # @return [Integer] Number of affected rows
17
17
  #
18
18
  # @api public
19
- def upsert(*args, &block)
19
+ def upsert(*args, &)
20
20
  if args.size > 1 && args[-1].is_a?(Hash)
21
21
  *values, opts = args
22
22
  else
@@ -24,7 +24,7 @@ module ROM
24
24
  opts = EMPTY_HASH
25
25
  end
26
26
 
27
- dataset.insert_conflict(opts).insert(*values, &block)
27
+ dataset.insert_conflict(opts).insert(*values, &)
28
28
  end
29
29
 
30
30
  # Insert tuple into relation
@@ -37,8 +37,8 @@ module ROM
37
37
  # @return [Hash] Inserted tuple
38
38
  #
39
39
  # @api public
40
- def insert(*args, &block)
41
- dataset.insert(*args, &block)
40
+ def insert(...)
41
+ dataset.insert(...)
42
42
  end
43
43
 
44
44
  # Multi insert tuples into relation
@@ -51,8 +51,8 @@ module ROM
51
51
  # @return [Array<String>] A list of executed SQL statements
52
52
  #
53
53
  # @api public
54
- def multi_insert(*args, &block)
55
- dataset.multi_insert(*args, &block)
54
+ def multi_insert(...)
55
+ dataset.multi_insert(...)
56
56
  end
57
57
 
58
58
  # Update tuples in the relation
@@ -64,8 +64,8 @@ module ROM
64
64
  # @return [Integer] Number of updated rows
65
65
  #
66
66
  # @api public
67
- def update(*args, &block)
68
- dataset.update(*args, &block)
67
+ def update(...)
68
+ dataset.update(...)
69
69
  end
70
70
 
71
71
  # Delete tuples from the relation
@@ -78,8 +78,8 @@ module ROM
78
78
  # @return [Integer] Number of deleted tuples
79
79
  #
80
80
  # @api public
81
- def delete(*args, &block)
82
- dataset.delete(*args, &block)
81
+ def delete(...)
82
+ dataset.delete(...)
83
83
  end
84
84
 
85
85
  # Insert tuples from other relation
@@ -113,13 +113,19 @@ module ROM
113
113
  #
114
114
  # @api public
115
115
  def import(other, options = EMPTY_HASH)
116
+ columns = other.schema.map { |a| a.alias || a.name }
117
+
116
118
  if other.gateway.eql?(gateway)
117
- columns = other.schema.map { |a| a.alias || a.name }
118
119
  dataset.import(columns, other.dataset, options)
119
120
  else
120
- columns = other.schema.map { |a| a.alias || a.name }
121
121
  keys = columns.map(&:to_sym)
122
- dataset.import(columns, other.to_a.map { |record| record.to_h.values_at(*keys) }, options)
122
+ dataset.import(
123
+ columns,
124
+ other.to_a.map { |record|
125
+ record.to_h.values_at(*keys)
126
+ },
127
+ options
128
+ )
123
129
  end
124
130
  end
125
131
  end
@@ -37,7 +37,9 @@ module ROM
37
37
  table = opts[:from].first
38
38
 
39
39
  if db.table_exists?(table)
40
- select(*schema.qualified_projection).order(*schema.project(*schema.primary_key_names).qualified)
40
+ select(*schema.qualified_projection).order(
41
+ *schema.project(*schema.primary_key_names).qualified
42
+ )
41
43
  else
42
44
  self
43
45
  end
@@ -49,10 +51,13 @@ module ROM
49
51
  end
50
52
 
51
53
  # @api private
54
+ #
55
+ # rubocop:disable Metrics/MethodLength
52
56
  def self.define_default_views!
53
57
  undef_method :by_pk if method_defined?(:by_pk)
54
58
 
55
59
  if schema.primary_key.size > 1
60
+ pks = schema.primary_key
56
61
  # @!method by_pk(val1, val2)
57
62
  # Return a relation restricted by its composite primary key
58
63
  #
@@ -61,10 +66,13 @@ module ROM
61
66
  # @return [SQL::Relation]
62
67
  #
63
68
  # @api public
64
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
65
- def by_pk(#{schema.primary_key.map(&:name).join(', ')})
66
- where(#{schema.primary_key.map { |attr| "schema.canonical[:#{attr.name}] => #{attr.name}" }.join(', ')})
67
- end
69
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
70
+ def by_pk(#{pks.map(&:name).join(", ")}) # def by_pk(val1, val2)
71
+ s = schema.canonical # s = schema.canonical
72
+ where( # where(
73
+ #{pks.map { "s[:#{_1.name}] => #{_1.name}" }.join(", ")} # s[:val1] => val1, s[:val2] => val2
74
+ ) # )
75
+ end # end
68
76
  RUBY
69
77
  else
70
78
  # @!method by_pk(pk)
@@ -75,18 +83,20 @@ module ROM
75
83
  # @return [SQL::Relation]
76
84
  #
77
85
  # @api public
78
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
79
- def by_pk(pk)
80
- if primary_key.nil?
81
- raise MissingPrimaryKeyError.new(
82
- "Missing primary key for :\#{schema.name}"
83
- )
84
- end
85
- where(schema.canonical[schema.canonical.primary_key_name].qualified => pk)
86
- end
86
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
87
+ def by_pk(pk) # def by_pk(pk)
88
+ s = schema.canonical # s = schema.canonical
89
+ if primary_key.nil? # if primary_key.nil?
90
+ raise MissingPrimaryKeyError.new( # raise MissingPrimaryKeyError.new(
91
+ "Missing primary key for :\#{schema.name}" # "Missing primary key for :#{schema.name}"
92
+ ) # )
93
+ end # end
94
+ where(s[s.primary_key_name].qualified => pk) # where(s[s.primary_key_name].qualified => pk)
95
+ end # end
87
96
  RUBY
88
97
  end
89
98
  end
99
+ # rubocop:enable Metrics/MethodLength
90
100
 
91
101
  # @api private
92
102
  def self.associations
@@ -121,26 +131,62 @@ module ROM
121
131
  # Open a database transaction
122
132
  #
123
133
  # @param [Hash] opts
124
- # @option opts [Boolean] :auto_savepoint Automatically use a savepoint for Database#transaction calls inside this transaction block.
125
- # @option opts [Symbol] :isolation The transaction isolation level to use for this transaction, should be :uncommitted, :committed, :repeatable, or :serializable, used if given and the database/adapter supports customizable transaction isolation levels.
126
- # @option opts [Integer] :num_retries The number of times to retry if the :retry_on option is used. The default is 5 times. Can be set to nil to retry indefinitely, but that is not recommended.
127
- # @option opts [Proc] :before_retry Proc to execute before rertrying if the :retry_on option is used. Called with two arguments: the number of retry attempts (counting the current one) and the error the last attempt failed with.
128
- # @option opts [String] :prepare A string to use as the transaction identifier for a prepared transaction (two-phase commit), if the database/adapter supports prepared transactions.
129
- # @option opts [Class] :retry_on An exception class or array of exception classes for which to automatically retry the transaction. Can only be set if not inside an existing transaction. Note that this should not be used unless the entire transaction block is idempotent, as otherwise it can cause non-idempotent behavior to execute multiple times.
130
- # @option opts [Symbol] :rollback Can the set to :reraise to reraise any Sequel::Rollback exceptions raised, or :always to always rollback even if no exceptions occur (useful for testing).
131
- # @option opts [Symbol] :server The server to use for the transaction. Set to :default, :read_only, or whatever symbol you used in the connect string when naming your servers.
132
- # @option opts [Boolean] :savepoint Whether to create a new savepoint for this transaction, only respected if the database/adapter supports savepoints. By default Sequel will reuse an existing transaction, so if you want to use a savepoint you must use this option. If the surrounding transaction uses :auto_savepoint, you can set this to false to not use a savepoint. If the value given for this option is :only, it will only create a savepoint if it is inside a transacation.
133
- # @option opts [Boolean] :deferrable **PG 9.1+ only** If present, set to DEFERRABLE if true or NOT DEFERRABLE if false.
134
- # @option opts [Boolean] :read_only **PG only** If present, set to READ ONLY if true or READ WRITE if false.
135
- # @option opts [Symbol] :synchronous **PG only** if non-nil, set synchronous_commit appropriately. Valid values true, :on, false, :off, :local (9.1+), and :remote_write (9.2+).
134
+ # @option opts [Boolean] :auto_savepoint
135
+ # Automatically use a savepoint for Database#transaction
136
+ # calls inside this transaction block.
137
+ # @option opts [Symbol] :isolation
138
+ # The transaction isolation level to use for this transaction,
139
+ # should be :uncommitted, :committed, :repeatable, or :serializable,
140
+ # used if given and the database/adapter supports customizable
141
+ # transaction isolation levels.
142
+ # @option opts [Integer] :num_retries
143
+ # The number of times to retry if the :retry_on option is used.
144
+ # The default is 5 times. Can be set to nil to retry indefinitely,
145
+ # but that is not recommended.
146
+ # @option opts [Proc] :before_retry
147
+ # Proc to execute before rertrying if the :retry_on option is used.
148
+ # Called with two arguments: the number of retry attempts (counting the
149
+ # current one) and the error the last attempt failed with.
150
+ # @option opts [String] :prepare
151
+ # A string to use as the transaction identifier for a prepared transaction
152
+ # (two-phase commit), if the database/adapter supports prepared transactions.
153
+ # @option opts [Class] :retry_on
154
+ # An exception class or array of exception classes for which to automatically
155
+ # retry the transaction. Can only be set if not inside an existing transaction.
156
+ # Note that this should not be used unless the entire transaction block is
157
+ # idempotent, as otherwise it can cause non-idempotent behavior to execute
158
+ # multiple times.
159
+ # @option opts [Symbol] :rollback
160
+ # Can be set to :reraise to reraise any Sequel::Rollback
161
+ # exceptions raised, or :always to always rollback even if no
162
+ # exceptions occur (useful for testing).
163
+ # @option opts [Symbol] :server
164
+ # The server to use for the transaction. Set to :default, :read_only,
165
+ # or whatever symbol you used in the connect string when naming
166
+ # your servers.
167
+ # @option opts [Boolean] :savepoint
168
+ # Whether to create a new savepoint for this transaction, only
169
+ # respected if the database/adapter supports savepoints. By default
170
+ # Sequel will reuse an existing transaction, so if you want to use a
171
+ # savepoint you must use this option. If the surrounding transaction
172
+ # uses :auto_savepoint, you can set this to false to not use a savepoint.
173
+ # If the value given for this option is :only, it will only create a
174
+ # savepoint if it is inside a transacation.
175
+ # @option opts [Boolean] :deferrable
176
+ # If present, set to DEFERRABLE if true or NOT DEFERRABLE if false.
177
+ # @option opts [Boolean] :read_only
178
+ # **PG only** If present, set to READ ONLY if true or READ WRITE if false.
179
+ # @option opts [Symbol] :synchronous
180
+ # **PG only** If non-nil, set synchronous_commit appropriately.
181
+ # Valid values true, :on, false, :off, :local, and :remote_write.
136
182
  #
137
183
  # @yield [t] Transaction
138
184
  #
139
185
  # @return [Mixed]
140
186
  #
141
187
  # @api public
142
- def transaction(opts = EMPTY_HASH, &block)
143
- Transaction.new(dataset.db).run(opts, &block)
188
+ def transaction(opts = EMPTY_HASH, &)
189
+ Transaction.new(dataset.db).run(opts, &)
144
190
  end
145
191
 
146
192
  # Return raw column names
@@ -19,8 +19,12 @@ module ROM
19
19
 
20
20
  private
21
21
 
22
+ def respond_to_missing?(_meth, _include_private = false)
23
+ true
24
+ end
25
+
22
26
  # @api private
23
- def method_missing(meth, *args, &block)
27
+ def method_missing(meth, ...)
24
28
  if schema.key?(meth)
25
29
  schema[meth]
26
30
  else
@@ -29,7 +33,7 @@ module ROM
29
33
  if type
30
34
  ::ROM::SQL::Function.new(type).meta(schema: schema)
31
35
  else
32
- ::Sequel::VIRTUAL_ROW.__send__(meth, *args, &block)
36
+ ::Sequel::VIRTUAL_ROW.__send__(meth, ...)
33
37
  end
34
38
  end
35
39
  end
@@ -12,7 +12,7 @@ module ROM
12
12
 
13
13
  defines :type_builders
14
14
 
15
- CONSTRAINT_DB_TYPE = 'add_constraint'.freeze
15
+ CONSTRAINT_DB_TYPE = 'add_constraint'
16
16
 
17
17
  option :type_builder
18
18
 
@@ -30,7 +30,7 @@ module ROM
30
30
  attr_class.new(type.meta(source: schema.name), name: name) if type
31
31
  end.compact
32
32
 
33
- missing = columns.map(&:first) - inferred.map { |attr| attr.name }
33
+ missing = columns.map(&:first) - inferred.map(&:name)
34
34
 
35
35
  [inferred, missing]
36
36
  end
@@ -16,8 +16,8 @@ module ROM
16
16
  # Define indexes within a block
17
17
  #
18
18
  # @api public
19
- def indexes(&block)
20
- @index_dsl = IndexDSL.new(**options, &block)
19
+ def indexes(&)
20
+ @index_dsl = IndexDSL.new(**options, &)
21
21
  end
22
22
 
23
23
  private
@@ -6,7 +6,7 @@ module ROM
6
6
  module SQL
7
7
  class Schema < ROM::Schema
8
8
  # @api public
9
- class IndexDSL # < BasicObject
9
+ class IndexDSL
10
10
  extend Initializer
11
11
 
12
12
  option :attr_class
@@ -14,14 +14,13 @@ module ROM
14
14
  attr_reader :registry
15
15
 
16
16
  # @api private
17
- def initialize(*, &block)
17
+ def initialize(*, **, &)
18
18
  super
19
19
 
20
20
  @registry = []
21
21
 
22
- instance_exec(&block)
22
+ instance_exec(&)
23
23
  end
24
- ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
25
24
 
26
25
  # @api public
27
26
  def index(*attributes, **options)
@@ -34,9 +33,9 @@ module ROM
34
33
  attr_class.new(attr[:type], **(attr[:options] || {})).meta(source: schema_name)
35
34
  end
36
35
 
37
- registry.map { |attr_names, options|
36
+ registry.to_set do |attr_names, options|
38
37
  build_index(attributes, attr_names, options)
39
- }.to_set
38
+ end
40
39
  end
41
40
 
42
41
  private
@@ -38,8 +38,8 @@ module ROM
38
38
  else
39
39
  infer_from_attributes(gateway, schema, **super)
40
40
  end
41
- rescue Sequel::Error => error
42
- on_error(schema.name, error)
41
+ rescue Sequel::Error => e
42
+ on_error(schema.name, e)
43
43
  { **FALLBACK_SCHEMA, indexes: schema.indexes }
44
44
  end
45
45
 
@@ -49,10 +49,14 @@ module ROM
49
49
  indexes = indexes_from_database(gateway, schema, idx)
50
50
  foreign_keys = foreign_keys_from_database(gateway, schema, idx)
51
51
 
52
- { **rest,
53
- attributes: attributes.map { |attr| mark_fk(mark_indexed(attr, indexes), foreign_keys) },
52
+ {
53
+ **rest,
54
+ attributes: attributes.map { |attr|
55
+ mark_fk(mark_indexed(attr, indexes), foreign_keys)
56
+ },
54
57
  foreign_keys: foreign_keys,
55
- indexes: indexes }
58
+ indexes: indexes
59
+ }
56
60
  end
57
61
 
58
62
  # @api private
@@ -60,10 +64,12 @@ module ROM
60
64
  indexes = schema.indexes | indexes_from_attributes(attributes)
61
65
  foreign_keys = foreign_keys_from_attributes(attributes)
62
66
 
63
- { **rest,
67
+ {
68
+ **rest,
64
69
  attributes: attributes.map { |attr| mark_indexed(attr, indexes) },
65
70
  foreign_keys: foreign_keys,
66
- indexes: indexes }
71
+ indexes: indexes
72
+ }
67
73
  end
68
74
 
69
75
  # @api private
@@ -71,12 +77,12 @@ module ROM
71
77
  if gateway.connection.respond_to?(:indexes)
72
78
  dataset = schema.name.dataset
73
79
 
74
- gateway.connection.indexes(dataset).map { |index_name, definition|
80
+ gateway.connection.indexes(dataset).to_set do |index_name, definition|
75
81
  columns, unique = definition.values_at(:columns, :unique)
76
82
  attrs = columns.map { |name| attributes[name] }
77
83
 
78
84
  SQL::Index.new(attrs, name: index_name, unique: unique)
79
- }.to_set
85
+ end
80
86
  else
81
87
  EMPTY_SET
82
88
  end
@@ -86,28 +92,26 @@ module ROM
86
92
  def foreign_keys_from_database(gateway, schema, attributes)
87
93
  dataset = schema.name.dataset
88
94
 
89
- gateway.connection.foreign_key_list(dataset).map { |definition|
95
+ gateway.connection.foreign_key_list(dataset).to_set do |definition|
90
96
  columns, table, key = definition.values_at(:columns, :table, :key)
91
97
  attrs = columns.map { |name| attributes[name] }
92
98
 
93
99
  SQL::ForeignKey.new(attrs, table, parent_keys: key)
94
- }.to_set
100
+ end
95
101
  end
96
102
 
97
103
  # @api private
98
104
  def indexes_from_attributes(attributes)
99
- attributes.
100
- select(&:indexed?).
101
- map { |attr| SQL::Index.new([attr.unwrap]) }.
102
- to_set
105
+ attributes
106
+ .select(&:indexed?)
107
+ .to_set { |attr| SQL::Index.new([attr.unwrap]) }
103
108
  end
104
109
 
105
110
  # @api private
106
111
  def foreign_keys_from_attributes(attributes)
107
- attributes.
108
- select(&:foreign_key?).
109
- map { |attr| SQL::ForeignKey.new([attr.unwrap], attr.target) }.
110
- to_set
112
+ attributes
113
+ .select(&:foreign_key?)
114
+ .to_set { |attr| SQL::ForeignKey.new([attr.unwrap], attr.target) }
111
115
  end
112
116
 
113
117
  # @api private
@@ -21,7 +21,7 @@ module ROM
21
21
 
22
22
  defines :ruby_type_mapping, :numeric_pk_type
23
23
 
24
- DECIMAL_REGEX = /(?:decimal|numeric)\((\d+)(?:,\s*(\d+))?\)/.freeze
24
+ DECIMAL_REGEX = /(?:decimal|numeric)\((\d+)(?:,\s*(\d+))?\)/
25
25
 
26
26
  ruby_type_mapping(
27
27
  integer: Types::Integer,
@@ -67,10 +67,12 @@ module ROM
67
67
  end
68
68
 
69
69
  # @api private
70
+ #
71
+ # rubocop:disable Metrics/PerceivedComplexity
70
72
  def map_type(ruby_type, db_type, **kw)
71
73
  type = self.class.ruby_type_mapping[ruby_type || guess_type(db_type)]
72
74
 
73
- if db_type.is_a?(String) && db_type.include?('numeric') || db_type.include?('decimal')
75
+ if (db_type.is_a?(String) && db_type.include?('numeric')) || db_type.include?('decimal')
74
76
  map_decimal_type(db_type)
75
77
  elsif db_type.is_a?(String) && db_type.include?('char') && kw[:max_length]
76
78
  type.meta(limit: kw[:max_length])
@@ -78,6 +80,7 @@ module ROM
78
80
  type
79
81
  end
80
82
  end
83
+ # rubocop:enable Metrics/PerceivedComplexity
81
84
 
82
85
  # @api private
83
86
  def guess_type(db_type)
@@ -32,8 +32,8 @@ module ROM
32
32
  # @return [Mixed] Result of the block call
33
33
  #
34
34
  # @api public
35
- def restriction(&block)
36
- RestrictionDSL.new(self).call(&block)
35
+ def restriction(&)
36
+ RestrictionDSL.new(self).call(&)
37
37
  end
38
38
 
39
39
  # Open Order DSL for setting ORDER clause in queries
@@ -43,8 +43,8 @@ module ROM
43
43
  # @return [Mixed] Result of the block call
44
44
  #
45
45
  # @api public
46
- def order(&block)
47
- OrderDSL.new(self).call(&block)
46
+ def order(&)
47
+ OrderDSL.new(self).call(&)
48
48
  end
49
49
 
50
50
  # Open Group DSL for setting GROUP BY clause in queries
@@ -54,8 +54,8 @@ module ROM
54
54
  # @return [Mixed] Result of the block call
55
55
  #
56
56
  # @api public
57
- def group(&block)
58
- GroupDSL.new(self).call(&block)
57
+ def group(&)
58
+ GroupDSL.new(self).call(&)
59
59
  end
60
60
 
61
61
  # Return a new schema with attributes marked as qualified
@@ -87,9 +87,9 @@ module ROM
87
87
  # @return [Schema] A new schema with projected attributes
88
88
  #
89
89
  # @api public
90
- def project(*names, &block)
91
- if block
92
- super(*(names + ProjectionDSL.new(self).(&block)))
90
+ def project(*names, &)
91
+ if block_given?
92
+ super(*(names + ProjectionDSL.new(self).(&)))
93
93
  else
94
94
  super
95
95
  end
@@ -141,7 +141,7 @@ module ROM
141
141
  #
142
142
  # @api public
143
143
  def call(relation)
144
- relation.new(relation.dataset.select(*self.qualified_projection), schema: self)
144
+ relation.new(relation.dataset.select(*qualified_projection), schema: self)
145
145
  end
146
146
 
147
147
  # Return an empty schema
@@ -13,8 +13,8 @@ module ROM
13
13
  gateway.run_migrations(migration_options.merge(options))
14
14
  end
15
15
 
16
- def create_migration(*args)
17
- gateway.migrator.create_file(*args)
16
+ def create_migration(...)
17
+ gateway.migrator.create_file(...)
18
18
  end
19
19
 
20
20
  # Global environment used for running migrations. You normally
@@ -24,8 +24,7 @@ module ROM
24
24
  # @api public
25
25
  attr_accessor :env
26
26
 
27
-
28
- # Migration options, which are passed to `ROM::SQL::RakeSupport.run_migrations`. You can
27
+ # Migration options, which are passed to `ROM::SQL::RakeSupport.run_migrations`. You can
29
28
  # set them in the `db:setup` task with `ROM::SQL::RakeSupport.migration_options = { ... }`
30
29
  #
31
30
  # @api public
@@ -84,7 +83,7 @@ namespace :db do
84
83
  end
85
84
 
86
85
  desc 'Create a migration (parameters: NAME, VERSION)'
87
- task :create_migration, [:name, :version] => :rom_configuration do |_, args|
86
+ task :create_migration, %i[name version] => :rom_configuration do |_, args|
88
87
  name, version = args.values_at(:name, :version)
89
88
 
90
89
  if name.nil?
@@ -8,6 +8,7 @@ module ROM
8
8
  private :connection
9
9
 
10
10
  def initialize(connection)
11
+ super()
11
12
  @connection = connection
12
13
  end
13
14
 
@@ -6,7 +6,11 @@ module ROM
6
6
  #
7
7
  # @api public
8
8
  class TypeDSL
9
- attr_reader :definition, :input_constructor, :output_constructor
9
+ attr_reader :definition
10
+
11
+ attr_reader :input_constructor
12
+
13
+ attr_reader :output_constructor
10
14
 
11
15
  # @api private
12
16
  def initialize(value_type)
@@ -18,8 +22,8 @@ module ROM
18
22
  end
19
23
 
20
24
  # @api private
21
- def call(&block)
22
- instance_exec(&block)
25
+ def call(&)
26
+ instance_exec(&)
23
27
 
24
28
  definition.constructor(input_constructor)
25
29
  .meta(read: definition.constructor(output_constructor))
@@ -30,13 +30,13 @@ module ROM
30
30
  # @param [Dry::Types::Type] type Type
31
31
  #
32
32
  # @api public
33
- def register(type, &block)
33
+ def register(type, &)
34
34
  extensions = @types[type.meta[:database]]
35
35
  db_type = type.meta[:db_type]
36
36
 
37
- mod = Module.new(&block)
38
- ctx = Object.new.extend(mod)
39
- functions = mod.public_instance_methods.each_with_object({}) { |m, ms| ms[m] = ctx.method(m) }
37
+ mod = ::Module.new(&)
38
+ ctx = ::Object.new.extend(mod)
39
+ functions = mod.public_instance_methods.to_h { |m| [m, ctx.method(m)] }
40
40
  extensions[db_type] = (extensions[db_type] || {}).merge(functions)
41
41
  end
42
42
  end
@@ -29,7 +29,7 @@ module ROM
29
29
  Types::Date => 'date',
30
30
  Types::Bool => 'boolean',
31
31
  Types::Decimal => 'numeric',
32
- Types::Float => 'float',
32
+ Types::Float => 'float'
33
33
  )
34
34
 
35
35
  def call(type)
@@ -40,7 +40,7 @@ module ROM
40
40
  self.class.mapping.fetch(type.with(meta: meta)) {
41
41
  if block_given?
42
42
  yield(type)
43
- end or raise "Cannot serialize #{ type }"
43
+ end or raise "Cannot serialize #{type}"
44
44
  }
45
45
  end
46
46
  end
data/lib/rom/sql/types.rb CHANGED
@@ -37,8 +37,8 @@ module ROM
37
37
  # @return [Dry::Types::Nominal]
38
38
  #
39
39
  # @api public
40
- def self.define(value_type, &block)
41
- TypeDSL.new(value_type).call(&block)
40
+ def self.define(value_type, &)
41
+ TypeDSL.new(value_type).call(&)
42
42
  end
43
43
 
44
44
  Serial = Integer.meta(primary_key: true)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ROM
4
4
  module SQL
5
- VERSION = "3.6.5"
5
+ VERSION = '3.7.0'
6
6
  end
7
7
  end
@@ -5,11 +5,9 @@ require 'rom/sql/types'
5
5
  module ROM
6
6
  module Types
7
7
  module Values
8
- class TreePath < ::Struct.new(:value, :separator)
9
- DEFAULT_SEPARATOR = '.'.freeze
10
-
8
+ class TreePath < ::Struct.new(:value, :separator) # rubocop:disable Style/StructInheritance
11
9
  # @api public
12
- def self.new(value, separator = DEFAULT_SEPARATOR)
10
+ def self.new(value, separator = '.')
13
11
  super
14
12
  end
15
13