rom-core 5.1.2 → 5.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) 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 -7
  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 +2 -2
  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/curried.rb +3 -2
  48. data/lib/rom/relation/loaded.rb +1 -0
  49. data/lib/rom/relation/materializable.rb +1 -0
  50. data/lib/rom/relation/name.rb +1 -1
  51. data/lib/rom/relation_registry.rb +1 -1
  52. data/lib/rom/schema.rb +22 -22
  53. data/lib/rom/schema/associations_dsl.rb +17 -17
  54. data/lib/rom/schema/dsl.rb +6 -6
  55. data/lib/rom/schema/inferrer.rb +2 -4
  56. data/lib/rom/setup.rb +2 -2
  57. data/lib/rom/setup/auto_registration.rb +1 -1
  58. data/lib/rom/setup/auto_registration_strategies/base.rb +1 -1
  59. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +4 -4
  60. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +1 -1
  61. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +1 -1
  62. data/lib/rom/setup/finalize/finalize_commands.rb +7 -4
  63. data/lib/rom/setup/finalize/finalize_mappers.rb +9 -8
  64. data/lib/rom/setup/finalize/finalize_relations.rb +2 -2
  65. data/lib/rom/struct.rb +1 -1
  66. data/lib/rom/struct_compiler.rb +6 -5
  67. data/lib/rom/support/memoizable.rb +3 -2
  68. data/lib/rom/transaction.rb +1 -1
  69. data/lib/rom/transformer.rb +1 -0
  70. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6612046c720abd4934be59209162df02dfdc55d9174ff728a9cda0b605b32493
4
- data.tar.gz: f58907caa62964d19c970ad61cb90ad552a84a8d303a881866f2a4cbbae3552e
3
+ metadata.gz: 210baca2c0408ebc0debfb706045e5d10c287bf25005f5fef6456a034f371be9
4
+ data.tar.gz: 2a6f63a627bdc874a696e40d164f8ba394c514abe3afe3ed2a7f704c705ebc3b
5
5
  SHA512:
6
- metadata.gz: 627092c0dd3ee99d3dd6df6f3f24f50585e0a07240b5057b470f663429d684090ebe5c753114cef46faa11aa5f746c56e79987f72d43e66548b82e2d34d42789
7
- data.tar.gz: 34ccdd1ba67a4f6c566f6254c676e1a5fdd22b6d8072917f61a3161a85d03a3586d5c1a523e2ba97547a550d73480e8b4fdeaf9e2bfaf01b9d76c2036af9c745
6
+ metadata.gz: 192dc8383ec5e6c2b4f98658d36417fa0e22a1a1c93f08e50c915a4410abd6a4edf70227f3db604c3e8a516fc2e54114eb407fb852bb2e42bcb423b4fd42aa04
7
+ data.tar.gz: 93703fe2e0474b5eb9052d4f9a0ad13d434e30180486bb9835898454959ee2b71dbc6f7d893df96f85ac70f78f4bf228576fbf9fe200f1295bc4b67ec1f8d560
@@ -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
 
@@ -199,13 +199,11 @@ module ROM
199
199
  klass.public_send(name, value)
200
200
  end
201
201
 
202
- if rel_meta[:combine_type]
203
- setup_associates(klass, relation, rel_meta, parent_relation)
204
- end
202
+ setup_associates(klass, relation, rel_meta, parent_relation) if rel_meta[:combine_type]
205
203
 
206
204
  plugins.each do |plugin|
207
205
  plugin_options = plugins_options.fetch(plugin) { EMPTY_HASH }
208
- klass.use(plugin, plugin_options)
206
+ klass.use(plugin, **plugin_options)
209
207
  end
210
208
 
211
209
  gateway = gateways[relation.gateway]
@@ -236,7 +234,7 @@ module ROM
236
234
  # @param [Relation] relation The relation for the command
237
235
  #
238
236
  # @api private
239
- def setup_associates(klass, relation, meta, parent_relation)
237
+ def setup_associates(klass, relation, _meta, parent_relation)
240
238
  assoc_name =
241
239
  if relation.associations.key?(parent_relation)
242
240
  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.2'
5
+ VERSION = '5.2.1'
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 }
@@ -60,9 +60,7 @@ module ROM
60
60
 
61
61
  meta[:type] ||= :object
62
62
 
63
- if meta.key?(:header)
64
- meta[:header] = Header.coerce(meta[:header], model: meta[:model])
65
- end
63
+ meta[:header] = Header.coerce(meta[:header], model: meta[:model]) if meta.key?(:header)
66
64
 
67
65
  self[meta].new(name, meta)
68
66
  end
@@ -187,6 +185,6 @@ module ROM
187
185
  hash: Hash,
188
186
  array: Array,
189
187
  exclude: Exclude
190
- }
188
+ }.freeze
191
189
  end
192
190
  end