rom-core 5.1.1 → 5.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rom/array_dataset.rb +4 -4
  3. data/lib/rom/association_set.rb +2 -3
  4. data/lib/rom/associations/definitions/abstract.rb +2 -2
  5. data/lib/rom/associations/many_to_many.rb +1 -0
  6. data/lib/rom/attribute.rb +5 -4
  7. data/lib/rom/auto_curry.rb +2 -0
  8. data/lib/rom/command.rb +6 -6
  9. data/lib/rom/command_compiler.rb +5 -9
  10. data/lib/rom/commands/class_interface.rb +7 -7
  11. data/lib/rom/commands/composite.rb +1 -1
  12. data/lib/rom/commands/graph/input_evaluator.rb +1 -1
  13. data/lib/rom/commands/lazy.rb +2 -1
  14. data/lib/rom/commands/lazy/create.rb +1 -1
  15. data/lib/rom/commands/lazy/update.rb +3 -3
  16. data/lib/rom/configuration.rb +5 -5
  17. data/lib/rom/configuration_dsl/relation.rb +1 -1
  18. data/lib/rom/constants.rb +1 -1
  19. data/lib/rom/core/version.rb +1 -1
  20. data/lib/rom/data_proxy.rb +3 -2
  21. data/lib/rom/enumerable_dataset.rb +4 -4
  22. data/lib/rom/environment.rb +0 -1
  23. data/lib/rom/header/attribute.rb +2 -4
  24. data/lib/rom/initializer.rb +9 -7
  25. data/lib/rom/lint/gateway.rb +1 -3
  26. data/lib/rom/lint/linter.rb +3 -4
  27. data/lib/rom/lint/spec.rb +2 -2
  28. data/lib/rom/mapper.rb +4 -3
  29. data/lib/rom/mapper/attribute_dsl.rb +5 -5
  30. data/lib/rom/mapper/dsl.rb +2 -5
  31. data/lib/rom/mapper/model_dsl.rb +2 -1
  32. data/lib/rom/mapper_compiler.rb +2 -1
  33. data/lib/rom/mapper_registry.rb +3 -3
  34. data/lib/rom/memory/dataset.rb +4 -3
  35. data/lib/rom/pipeline.rb +3 -1
  36. data/lib/rom/plugin.rb +3 -3
  37. data/lib/rom/plugin_registry.rb +1 -1
  38. data/lib/rom/plugins/command/schema.rb +11 -10
  39. data/lib/rom/plugins/relation/instrumentation.rb +1 -1
  40. data/lib/rom/plugins/relation/registry_reader.rb +4 -3
  41. data/lib/rom/plugins/schema/timestamps.rb +4 -6
  42. data/lib/rom/processor.rb +1 -1
  43. data/lib/rom/processor/transproc.rb +16 -19
  44. data/lib/rom/registry.rb +17 -12
  45. data/lib/rom/relation.rb +6 -6
  46. data/lib/rom/relation/class_interface.rb +9 -8
  47. data/lib/rom/relation/combined.rb +1 -1
  48. data/lib/rom/relation/curried.rb +3 -2
  49. data/lib/rom/relation/loaded.rb +1 -0
  50. data/lib/rom/relation/materializable.rb +1 -0
  51. data/lib/rom/relation/name.rb +2 -2
  52. data/lib/rom/relation_registry.rb +1 -1
  53. data/lib/rom/schema.rb +22 -22
  54. data/lib/rom/schema/associations_dsl.rb +17 -17
  55. data/lib/rom/schema/dsl.rb +6 -6
  56. data/lib/rom/schema/inferrer.rb +2 -4
  57. data/lib/rom/setup.rb +2 -2
  58. data/lib/rom/setup/auto_registration.rb +2 -2
  59. data/lib/rom/setup/auto_registration_strategies/base.rb +1 -1
  60. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +4 -4
  61. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +1 -1
  62. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +1 -1
  63. data/lib/rom/setup/finalize/finalize_commands.rb +7 -4
  64. data/lib/rom/setup/finalize/finalize_mappers.rb +9 -8
  65. data/lib/rom/setup/finalize/finalize_relations.rb +2 -2
  66. data/lib/rom/struct.rb +1 -1
  67. data/lib/rom/struct_compiler.rb +7 -6
  68. data/lib/rom/support/configurable.rb +0 -6
  69. data/lib/rom/support/memoizable.rb +3 -2
  70. data/lib/rom/transaction.rb +1 -1
  71. data/lib/rom/transformer.rb +1 -0
  72. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3937d432700b0d1f83c80f86e39fecf7b162f48cebf3aa0da70ecbf98bb3d74b
4
- data.tar.gz: c2870cc40c18958f8b5b7c57a486bc4dbb639086efe9b108027ed70dd7251ef0
3
+ metadata.gz: 35f12c6601d4e265450e2c8d6cc450da987ba13f5de31f33dfefc1687c83c023
4
+ data.tar.gz: 62e345fc8d4630732b40ebc58d201255f6359ed23e498feceb9385cf739d2749
5
5
  SHA512:
6
- metadata.gz: 6296974fe1790016095700736478a76b68ecb054ab6c53e1219ab54997467d6def0058427982186eb06e33e86f0c1f964c1d7b35d8bbba2febee62ee89b700b3
7
- data.tar.gz: cf9f5ac91c372e72f21184a437dadf2ad671cfacc7926ce3d985accd138cc5c4e7ca7974207a5c74c003a4a0d23c2f529865d39fcf98cd8f8e2bec3ba3a470cb
6
+ metadata.gz: be684d34005176ce3535b8533700055f2103ea04869b19d07917680f024ea4918a4c97af8d13bbaa1f35e912c4a822c6238489227dbee90c1a1c6b5875280d78
7
+ data.tar.gz: c7dba5888e86336bcaa2448825caaafd8eb7b57ea8b7b0449df00b58e34e7b662966ac63fc2bdf6a6e0917e5bc23607d211b05dae36e827ba10c1f52ab924880
@@ -31,14 +31,14 @@ module ROM
31
31
  :slice, :slice!, :sort!, :uniq, :uniq!, :unshift, :values_at
32
32
  )
33
33
 
34
- [
35
- :map!, :combination, :cycle, :delete_if, :keep_if, :permutation, :reject!,
36
- :select!, :sort_by!
34
+ %i[
35
+ map! combination cycle delete_if keep_if permutation reject!
36
+ select! sort_by!
37
37
  ].each do |method|
38
38
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
39
39
  def #{method}(*args, &block)
40
40
  return to_enum unless block
41
- self.class.new(data.send(:#{method}, *args, &block), options)
41
+ self.class.new(data.send(:#{method}, *args, &block), **options)
42
42
  end
43
43
  RUBY
44
44
  end
@@ -12,10 +12,9 @@ module ROM
12
12
  def initialize(*)
13
13
  super
14
14
  elements.values.each do |assoc|
15
- if assoc.aliased? && !key?(assoc.name)
16
- elements[assoc.name] = assoc
17
- end
15
+ elements[assoc.name] = assoc if assoc.aliased? && !key?(assoc.name)
18
16
  end
19
17
  end
18
+ ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
20
19
  end
21
20
  end
@@ -73,12 +73,12 @@ module ROM
73
73
  # @option opts [TrueClass,FalseClass] :override Whether provided :view should override association's default view
74
74
  #
75
75
  # @api public
76
- def self.new(source, target, opts = EMPTY_HASH)
76
+ def self.new(source, target, **opts)
77
77
  source_name = Relation::Name[source]
78
78
  target_name = resolve_target_name(target, opts)
79
79
  options = process_options(target_name, Hash[opts])
80
80
 
81
- super(source_name, target_name, options)
81
+ super(source_name, target_name, **options)
82
82
  end
83
83
 
84
84
  # @api private
@@ -18,6 +18,7 @@ module ROM
18
18
  super
19
19
  @join_relation = relations[through]
20
20
  end
21
+ ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
21
22
 
22
23
  # Adapters should implement this method
23
24
  #
@@ -304,7 +304,7 @@ module ROM
304
304
  # @api public
305
305
  def meta(opts = nil)
306
306
  if opts
307
- self.class.new(type.meta(opts), options)
307
+ self.class.new(type.meta(opts), **options)
308
308
  else
309
309
  type.meta
310
310
  end
@@ -340,7 +340,7 @@ module ROM
340
340
  #
341
341
  # @api private
342
342
  def read?
343
- ! meta[:read].nil?
343
+ !meta[:read].nil?
344
344
  end
345
345
 
346
346
  # Return read type
@@ -367,7 +367,7 @@ module ROM
367
367
  #
368
368
  # @api public
369
369
  def optional
370
- sum = self.class.new(super, options)
370
+ sum = self.class.new(super, **options)
371
371
  read? ? sum.meta(read: meta[:read].optional) : sum
372
372
  end
373
373
 
@@ -412,7 +412,7 @@ module ROM
412
412
  response = type.__send__(meth, *args, &block)
413
413
 
414
414
  if response.is_a?(type.class)
415
- self.class.new(response, options)
415
+ self.class.new(response, **options)
416
416
  else
417
417
  response
418
418
  end
@@ -420,5 +420,6 @@ module ROM
420
420
  super
421
421
  end
422
422
  end
423
+ ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
423
424
  end
424
425
  end
@@ -8,6 +8,7 @@ module ROM
8
8
  def self.extended(klass)
9
9
  klass.define_singleton_method(:method_added) do |name|
10
10
  return if auto_curry_busy?
11
+
11
12
  auto_curry_guard { auto_curry(name) }
12
13
  super(name)
13
14
  end
@@ -58,6 +59,7 @@ module ROM
58
59
  response
59
60
  end
60
61
  end
62
+ ruby2_keywords(name) if respond_to?(:ruby2_keywords, true)
61
63
  end
62
64
 
63
65
  auto_curried_methods << name
@@ -280,7 +280,7 @@ module ROM
280
280
  result = prepared ? execute(prepared, &block) : execute(&block)
281
281
 
282
282
  if curried?
283
- if args.size > 0
283
+ if !args.empty?
284
284
  apply_hooks(after_hooks, result, *args)
285
285
  elsif curry_args.size > 1
286
286
  apply_hooks(after_hooks, result, curry_args[1])
@@ -288,7 +288,7 @@ module ROM
288
288
  apply_hooks(after_hooks, result)
289
289
  end
290
290
  else
291
- apply_hooks(after_hooks, result, *args[1..args.size-1])
291
+ apply_hooks(after_hooks, result, *args[1..args.size - 1])
292
292
  end
293
293
  else
294
294
  execute(*(curry_args + args), &block)
@@ -314,7 +314,7 @@ module ROM
314
314
  if curry_args.empty? && args.first.is_a?(Graph::InputEvaluator)
315
315
  Lazy[self].new(self, *args)
316
316
  else
317
- self.class.build(relation, { **options, curry_args: args })
317
+ self.class.build(relation, **options, curry_args: args)
318
318
  end
319
319
  end
320
320
 
@@ -335,7 +335,7 @@ module ROM
335
335
  #
336
336
  # @api public
337
337
  def curried?
338
- curry_args.size > 0
338
+ !curry_args.empty?
339
339
  end
340
340
 
341
341
  # Return a new command with appended before hooks
@@ -386,14 +386,14 @@ module ROM
386
386
  #
387
387
  # @api public
388
388
  def new(new_relation)
389
- self.class.build(new_relation, {**options, source: relation})
389
+ self.class.build(new_relation, **options, source: relation)
390
390
  end
391
391
 
392
392
  # Check if this command has any hooks
393
393
  #
394
394
  # @api private
395
395
  def hooks?
396
- before_hooks.size > 0 || after_hooks.size > 0
396
+ !before_hooks.empty? || !after_hooks.empty?
397
397
  end
398
398
 
399
399
  # Check if this command is lazy
@@ -157,7 +157,7 @@ module ROM
157
157
  default_mapping
158
158
  end
159
159
 
160
- if other.size > 0
160
+ if !other.empty?
161
161
  [mapping, [type, other]]
162
162
  else
163
163
  [mapping, type]
@@ -169,7 +169,7 @@ module ROM
169
169
  end
170
170
 
171
171
  # @api private
172
- def visit_attribute(*args)
172
+ def visit_attribute(*_args)
173
173
  nil
174
174
  end
175
175
 
@@ -193,19 +193,15 @@ module ROM
193
193
  type.create_class(rel_name, type) do |klass|
194
194
  klass.result(rel_meta.fetch(:combine_type, result))
195
195
 
196
- klass.input(meta.fetch(:input, relation.input_schema))
197
-
198
196
  meta.each do |name, value|
199
197
  klass.public_send(name, value)
200
198
  end
201
199
 
202
- if rel_meta[:combine_type]
203
- setup_associates(klass, relation, rel_meta, parent_relation)
204
- end
200
+ setup_associates(klass, relation, rel_meta, parent_relation) if rel_meta[:combine_type]
205
201
 
206
202
  plugins.each do |plugin|
207
203
  plugin_options = plugins_options.fetch(plugin) { EMPTY_HASH }
208
- klass.use(plugin, plugin_options)
204
+ klass.use(plugin, **plugin_options)
209
205
  end
210
206
 
211
207
  gateway = gateways[relation.gateway]
@@ -236,7 +232,7 @@ module ROM
236
232
  # @param [Relation] relation The relation for the command
237
233
  #
238
234
  # @api private
239
- def setup_associates(klass, relation, meta, parent_relation)
235
+ def setup_associates(klass, relation, _meta, parent_relation)
240
236
  assoc_name =
241
237
  if relation.associations.key?(parent_relation)
242
238
  parent_relation
@@ -71,8 +71,8 @@ module ROM
71
71
  # @return [Command]
72
72
  #
73
73
  # @api public
74
- def build(relation, options = EMPTY_HASH)
75
- new(relation, self.options.merge(options))
74
+ def build(relation, **options)
75
+ new(relation, **self.options, **options)
76
76
  end
77
77
 
78
78
  # Create a command class with a specific type
@@ -111,8 +111,8 @@ module ROM
111
111
  # @option options [Symbol] :adapter (:default) first adapter to check for plugin
112
112
  #
113
113
  # @api public
114
- def use(plugin, options = EMPTY_HASH)
115
- ROM.plugin_registry[:command].fetch(plugin, adapter).apply_to(self, options)
114
+ def use(plugin, **options)
115
+ ROM.plugin_registry[:command].fetch(plugin, adapter).apply_to(self, **options)
116
116
  end
117
117
 
118
118
  # Extend a command class with relation view methods
@@ -151,7 +151,7 @@ module ROM
151
151
  # relation :users
152
152
  # register_as :create
153
153
  #
154
- # before my_hook: { arg1: 1, arg1: 2 }
154
+ # before my_hook: { arg1: 1, arg2: 2 }
155
155
  #
156
156
  # def my_hook(tuple, arg1:, arg2:)
157
157
  # puts "hook called with args: #{arg1} and #{arg2}"
@@ -164,7 +164,7 @@ module ROM
164
164
  #
165
165
  # @api public
166
166
  def before(*hooks)
167
- if hooks.size > 0
167
+ if !hooks.empty?
168
168
  set_hooks(:before, hooks)
169
169
  else
170
170
  @before
@@ -209,7 +209,7 @@ module ROM
209
209
  #
210
210
  # @api public
211
211
  def after(*hooks)
212
- if hooks.size > 0
212
+ if !hooks.empty?
213
213
  set_hooks(:after, hooks)
214
214
  else
215
215
  @after
@@ -18,7 +18,7 @@ module ROM
18
18
  def call(*args)
19
19
  response = left.call(*args)
20
20
 
21
- if response.nil? || (many? && response.size == 0)
21
+ if response.nil? || (many? && response.empty?)
22
22
  return one? ? nil : EMPTY_ARRAY
23
23
  end
24
24
 
@@ -72,7 +72,7 @@ module ROM
72
72
  value =
73
73
  begin
74
74
  if index
75
- tuple_path[0..tuple_path.size-2]
75
+ tuple_path[0..tuple_path.size - 2]
76
76
  .reduce(input) { |a, e| a.fetch(e) }
77
77
  .at(index)[tuple_path.last]
78
78
  else
@@ -44,7 +44,7 @@ module ROM
44
44
  # @return [Array,Hash]
45
45
  #
46
46
  # @api public
47
- def call(*args)
47
+ def call(*_args)
48
48
  raise NotImplementedError
49
49
  end
50
50
 
@@ -96,6 +96,7 @@ module ROM
96
96
  super
97
97
  end
98
98
  end
99
+ ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
99
100
  end
100
101
  end
101
102
  end
@@ -26,7 +26,7 @@ module ROM
26
26
  end.reduce(:concat)
27
27
  else
28
28
  input = evaluator.call(first)
29
- command.call(input, *args[1..size-1])
29
+ command.call(input, *args[1..size - 1])
30
30
  end
31
31
  end
32
32
  end
@@ -31,12 +31,12 @@ module ROM
31
31
  input = evaluator.call(first)
32
32
 
33
33
  if input.is_a?(Array)
34
- input.map.with_index do |item, index|
35
- command_proc[command, last, item].call(item, *args[1..size-1])
34
+ input.map.with_index do |item, _index|
35
+ command_proc[command, last, item].call(item, *args[1..size - 1])
36
36
  end
37
37
  else
38
38
  command_proc[command, *(size > 1 ? [last, input] : [input])]
39
- .call(input, *args[1..size-1])
39
+ .call(input, *args[1..size - 1])
40
40
  end
41
41
  end
42
42
  end
@@ -37,8 +37,8 @@ module ROM
37
37
  attr_reader :notifications
38
38
 
39
39
  def_delegators :@setup, :register_relation, :register_command, :register_mapper, :register_plugin,
40
- :command_classes, :mapper_classes,
41
- :auto_registration
40
+ :command_classes, :mapper_classes,
41
+ :auto_registration
42
42
 
43
43
  def_delegators :@environment, :gateways, :gateways_map, :configure, :config
44
44
 
@@ -54,7 +54,7 @@ module ROM
54
54
  @notifications = Notifications.event_bus(:configuration)
55
55
  @setup = Setup.new(notifications)
56
56
 
57
- block.call(self) if block
57
+ block&.call(self)
58
58
  end
59
59
 
60
60
  # Apply a plugin to the configuration
@@ -100,8 +100,8 @@ module ROM
100
100
 
101
101
  # @api private
102
102
  def adapter_for_gateway(gateway)
103
- ROM.adapters.select do |key, value|
104
- value.const_defined?(:Gateway) && gateway.kind_of?(value.const_get(:Gateway))
103
+ ROM.adapters.select do |_key, value|
104
+ value.const_defined?(:Gateway) && gateway.is_a?(value.const_get(:Gateway))
105
105
  end.keys.first
106
106
  end
107
107
 
@@ -20,7 +20,7 @@ module ROM
20
20
 
21
21
  Dry::Core::ClassBuilder.new(name: class_name, parent: ROM::Relation[adapter]).call do |klass|
22
22
  klass.gateway(options.fetch(:gateway, :default))
23
- klass.schema(name) { }
23
+ klass.schema(name) {}
24
24
  end
25
25
  end
26
26
  end
@@ -14,7 +14,7 @@ module ROM
14
14
  def initialize(adapter, component)
15
15
  super(
16
16
  "Failed to find #{component} class for #{adapter} adapter. " \
17
- "Make sure ROM setup was started and the adapter identifier is correct."
17
+ 'Make sure ROM setup was started and the adapter identifier is correct.'
18
18
  )
19
19
  end
20
20
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ROM
4
4
  module Core
5
- VERSION = '5.1.1'
5
+ VERSION = '5.2.4'
6
6
  end
7
7
  end
@@ -8,8 +8,8 @@ module ROM
8
8
  #
9
9
  # @private
10
10
  module DataProxy
11
- NON_FORWARDABLE = [
12
- :each, :to_a, :to_ary, :kind_of?, :instance_of?, :is_a?
11
+ NON_FORWARDABLE = %i[
12
+ each to_a to_ary kind_of? instance_of? is_a?
13
13
  ].freeze
14
14
 
15
15
  # Wrapped data array
@@ -46,6 +46,7 @@ module ROM
46
46
  # @api private
47
47
  def each
48
48
  return to_enum unless block_given?
49
+
49
50
  data.each { |tuple| yield(row_proc[tuple]) }
50
51
  end
51
52
 
@@ -55,14 +55,14 @@ module ROM
55
55
 
56
56
  forward :take
57
57
 
58
- [
59
- :chunk, :collect, :collect_concat, :drop_while, :find_all, :flat_map,
60
- :grep, :map, :reject, :select, :sort, :sort_by, :take_while
58
+ %i[
59
+ chunk collect collect_concat drop_while find_all flat_map
60
+ grep map reject select sort sort_by take_while
61
61
  ].each do |method|
62
62
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
63
63
  def #{method}(*args, &block)
64
64
  return to_enum unless block
65
- self.class.new(super(*args, &block), options)
65
+ self.class.new(super(*args, &block), **options)
66
66
  end
67
67
  RUBY
68
68
  end
@@ -35,7 +35,6 @@ module ROM
35
35
  end
36
36
  end
37
37
 
38
-
39
38
  # @api private
40
39
  def normalize_gateway_args(*args)
41
40
  args.first.is_a?(Hash) ? args.first : { default: args }