rom-core 5.3.2 → 5.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rom/array_dataset.rb +5 -5
  3. data/lib/rom/association_set.rb +1 -2
  4. data/lib/rom/associations/definitions/abstract.rb +5 -3
  5. data/lib/rom/associations/many_to_many.rb +1 -2
  6. data/lib/rom/attribute.rb +15 -37
  7. data/lib/rom/auto_curry.rb +34 -23
  8. data/lib/rom/cache.rb +9 -21
  9. data/lib/rom/command.rb +19 -37
  10. data/lib/rom/command_compiler.rb +12 -14
  11. data/lib/rom/command_proxy.rb +6 -10
  12. data/lib/rom/command_registry.rb +4 -8
  13. data/lib/rom/commands/class_interface.rb +20 -20
  14. data/lib/rom/commands/composite.rb +3 -0
  15. data/lib/rom/commands/graph/class_interface.rb +3 -1
  16. data/lib/rom/commands/graph/input_evaluator.rb +3 -1
  17. data/lib/rom/commands/graph.rb +3 -0
  18. data/lib/rom/commands/lazy/create.rb +2 -0
  19. data/lib/rom/commands/lazy/update.rb +2 -0
  20. data/lib/rom/commands/lazy.rb +2 -3
  21. data/lib/rom/configuration.rb +14 -16
  22. data/lib/rom/configuration_dsl/command.rb +2 -2
  23. data/lib/rom/configuration_dsl/command_dsl.rb +9 -5
  24. data/lib/rom/configuration_dsl/mapper_dsl.rb +12 -3
  25. data/lib/rom/configuration_dsl/relation.rb +4 -2
  26. data/lib/rom/configuration_dsl.rb +8 -10
  27. data/lib/rom/constants.rb +26 -26
  28. data/lib/rom/container.rb +15 -15
  29. data/lib/rom/core/version.rb +1 -1
  30. data/lib/rom/core.rb +0 -1
  31. data/lib/rom/create_container.rb +3 -5
  32. data/lib/rom/data_proxy.rb +13 -15
  33. data/lib/rom/enumerable_dataset.rb +6 -6
  34. data/lib/rom/environment.rb +5 -5
  35. data/lib/rom/gateway.rb +4 -12
  36. data/lib/rom/global/plugin_dsl.rb +4 -4
  37. data/lib/rom/global.rb +2 -2
  38. data/lib/rom/header/attribute.rb +1 -1
  39. data/lib/rom/header.rb +13 -35
  40. data/lib/rom/initializer.rb +11 -15
  41. data/lib/rom/lint/enumerable_dataset.rb +2 -1
  42. data/lib/rom/lint/gateway.rb +3 -1
  43. data/lib/rom/lint/linter.rb +2 -2
  44. data/lib/rom/lint/test.rb +4 -6
  45. data/lib/rom/mapper/attribute_dsl.rb +39 -27
  46. data/lib/rom/mapper/builder.rb +2 -2
  47. data/lib/rom/mapper/dsl.rb +2 -3
  48. data/lib/rom/mapper/model_dsl.rb +5 -1
  49. data/lib/rom/mapper.rb +2 -4
  50. data/lib/rom/mapper_compiler.rb +3 -2
  51. data/lib/rom/mapper_registry.rb +2 -4
  52. data/lib/rom/memory/commands.rb +1 -1
  53. data/lib/rom/memory/dataset.rb +7 -5
  54. data/lib/rom/memory/gateway.rb +1 -0
  55. data/lib/rom/model_builder.rb +14 -14
  56. data/lib/rom/open_struct.rb +1 -1
  57. data/lib/rom/pipeline.rb +6 -15
  58. data/lib/rom/plugin_registry.rb +4 -10
  59. data/lib/rom/plugins/command/timestamps.rb +9 -5
  60. data/lib/rom/plugins/relation/instrumentation.rb +7 -2
  61. data/lib/rom/plugins/relation/registry_reader.rb +3 -15
  62. data/lib/rom/plugins.rb +1 -3
  63. data/lib/rom/processor/transproc.rb +14 -4
  64. data/lib/rom/processor.rb +1 -0
  65. data/lib/rom/registry.rb +20 -29
  66. data/lib/rom/relation/class_interface.rb +18 -16
  67. data/lib/rom/relation/combined.rb +7 -4
  68. data/lib/rom/relation/composite.rb +2 -6
  69. data/lib/rom/relation/curried.rb +12 -11
  70. data/lib/rom/relation/graph.rb +4 -12
  71. data/lib/rom/relation/loaded.rb +8 -16
  72. data/lib/rom/relation/materializable.rb +6 -14
  73. data/lib/rom/relation/name.rb +5 -14
  74. data/lib/rom/relation/view_dsl.rb +7 -9
  75. data/lib/rom/relation/wrap.rb +3 -9
  76. data/lib/rom/relation.rb +39 -81
  77. data/lib/rom/schema/associations_dsl.rb +4 -8
  78. data/lib/rom/schema/dsl.rb +14 -13
  79. data/lib/rom/schema/inferrer.rb +5 -3
  80. data/lib/rom/schema.rb +27 -41
  81. data/lib/rom/setup/auto_registration.rb +4 -6
  82. data/lib/rom/setup/auto_registration_strategies/base.rb +1 -1
  83. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +4 -8
  84. data/lib/rom/setup/finalize/finalize_commands.rb +3 -0
  85. data/lib/rom/setup/finalize/finalize_mappers.rb +16 -14
  86. data/lib/rom/setup/finalize/finalize_relations.rb +30 -4
  87. data/lib/rom/setup/finalize.rb +17 -3
  88. data/lib/rom/setup.rb +5 -4
  89. data/lib/rom/struct.rb +20 -18
  90. data/lib/rom/struct_compiler.rb +4 -7
  91. data/lib/rom/support/configurable.rb +10 -20
  92. data/lib/rom/support/memoizable.rb +10 -9
  93. data/lib/rom/support/notifications.rb +4 -8
  94. data/lib/rom/transaction.rb +2 -4
  95. data/lib/rom/transformer.rb +6 -10
  96. data/lib/rom/types.rb +3 -6
  97. metadata +15 -57
data/lib/rom/relation.rb CHANGED
@@ -144,7 +144,9 @@ module ROM
144
144
  # @!attribute [r] name
145
145
  # @return [Object] The relation name
146
146
  # @api public
147
- option :name, default: -> { self.class.schema ? self.class.schema.name : self.class.default_name }
147
+ option :name, default: lambda {
148
+ self.class.schema ? self.class.schema.name : self.class.default_name
149
+ }
148
150
 
149
151
  # @!attribute [r] input_schema
150
152
  # @return [Object#[]] tuple processing function, uses schema or defaults to Hash[]
@@ -159,12 +161,13 @@ module ROM
159
161
  }
160
162
 
161
163
  # @!attribute [r] auto_map
162
- # @return [TrueClass,FalseClass] Whether or not a relation and its compositions should be auto-mapped
164
+ # @return [true, false] Whether or not a relation and its
165
+ # compositions should be auto-mapped
163
166
  # @api private
164
167
  option :auto_map, default: -> { self.class.auto_map }
165
168
 
166
169
  # @!attribute [r] auto_struct
167
- # @return [TrueClass,FalseClass] Whether or not tuples should be auto-mapped to structs
170
+ # @return [true, false] Whether or not tuples should be auto-mapped to structs
168
171
  # @api private
169
172
  option :auto_struct, default: -> { self.class.auto_struct }
170
173
 
@@ -191,19 +194,19 @@ module ROM
191
194
  #
192
195
  # @example accessing canonical attribute
193
196
  # users[:id]
194
- # # => #<ROM::SQL::Attribute[Integer] primary_key=true name=:id source=ROM::Relation::Name(users)>
197
+ # # => #<ROM::SQL::Attribute[Integer] primary_key=true
198
+ # # name=:id source=ROM::Relation::Name(users)>
195
199
  #
196
200
  # @example accessing joined attribute
197
201
  # tasks_with_users = tasks.join(users).select_append(tasks[:title])
198
202
  # tasks_with_users[:title, :tasks]
199
- # # => #<ROM::SQL::Attribute[String] primary_key=false name=:title source=ROM::Relation::Name(tasks)>
203
+ # # => #<ROM::SQL::Attribute[String] primary_key=false
204
+ # # name=:title source=ROM::Relation::Name(tasks)>
200
205
  #
201
206
  # @return [Attribute]
202
207
  #
203
208
  # @api public
204
- def [](name)
205
- schema[name]
206
- end
209
+ def [](name) = schema[name]
207
210
 
208
211
  # Yields relation tuples
209
212
  #
@@ -214,11 +217,11 @@ module ROM
214
217
  # @return [Enumerator] if block is not provided
215
218
  #
216
219
  # @api public
217
- def each
220
+ def each(&)
218
221
  return to_enum unless block_given?
219
222
 
220
223
  if auto_map?
221
- mapper.(dataset.map { |tuple| output_schema[tuple] }).each { |struct| yield(struct) }
224
+ mapper.(dataset.map { |tuple| output_schema[tuple] }).each(&)
222
225
  else
223
226
  dataset.each { |tuple| yield(output_schema[tuple]) }
224
227
  end
@@ -248,9 +251,7 @@ module ROM
248
251
  # @return [Relation]
249
252
  #
250
253
  # @api public
251
- def combine(*args)
252
- combine_with(*nodes(*args))
253
- end
254
+ def combine(*args) = combine_with(*nodes(*args))
254
255
 
255
256
  # Composes with other relations
256
257
  #
@@ -259,9 +260,7 @@ module ROM
259
260
  # @return [Relation::Graph]
260
261
  #
261
262
  # @api public
262
- def combine_with(*others)
263
- Combined.new(self, others)
264
- end
263
+ def combine_with(*others) = Combined.new(self, others)
265
264
 
266
265
  # @api private
267
266
  def nodes(*args)
@@ -314,9 +313,7 @@ module ROM
314
313
  # @return [Relation::Curried]
315
314
  #
316
315
  # @api private
317
- def preload_assoc(assoc, other)
318
- assoc.preload(self, other)
319
- end
316
+ def preload_assoc(assoc, other) = assoc.preload(self, other)
320
317
 
321
318
  # Wrap other relations using association names
322
319
  #
@@ -339,63 +336,49 @@ module ROM
339
336
  # @return [Relation::Wrap]
340
337
  #
341
338
  # @api public
342
- def wrap_around(*others)
343
- wrap_class.new(self, others)
344
- end
339
+ def wrap_around(*others) = wrap_class.new(self, others)
345
340
 
346
341
  # Loads a relation
347
342
  #
348
343
  # @return [Relation::Loaded]
349
344
  #
350
345
  # @api public
351
- def call
352
- Loaded.new(self)
353
- end
346
+ def call = Loaded.new(self)
354
347
 
355
348
  # Materializes a relation into an array
356
349
  #
357
350
  # @return [Array<Hash>]
358
351
  #
359
352
  # @api public
360
- def to_a
361
- to_enum.to_a
362
- end
353
+ def to_a = to_enum.to_a
363
354
 
364
355
  # Returns if this relation is curried
365
356
  #
366
357
  # @return [false]
367
358
  #
368
359
  # @api private
369
- def curried?
370
- false
371
- end
360
+ def curried? = false
372
361
 
373
362
  # Returns if this relation is a graph
374
363
  #
375
364
  # @return [false]
376
365
  #
377
366
  # @api private
378
- def graph?
379
- false
380
- end
367
+ def graph? = false
381
368
 
382
369
  # Return if this is a wrap relation
383
370
  #
384
371
  # @return [false]
385
372
  #
386
373
  # @api private
387
- def wrap?
388
- false
389
- end
374
+ def wrap? = false
390
375
 
391
376
  # Returns true if a relation has schema defined
392
377
  #
393
378
  # @return [TrueClass, FalseClass]
394
379
  #
395
380
  # @api private
396
- def schema?
397
- !schema.empty?
398
- end
381
+ def schema? = !schema.empty?
399
382
 
400
383
  # Return a new relation with provided dataset and additional options
401
384
  #
@@ -420,7 +403,7 @@ module ROM
420
403
  if new_opts.empty?
421
404
  options
422
405
  elsif new_opts.key?(:schema)
423
- options.merge(new_opts).reject { |k, _| k == :input_schema || k == :output_schema }
406
+ options.merge(new_opts).except(:input_schema, :output_schema)
424
407
  else
425
408
  options.merge(new_opts)
426
409
  end
@@ -456,45 +439,34 @@ module ROM
456
439
  # @return [AssociationSet] Schema's association set (empty by default)
457
440
  #
458
441
  # @api public
459
- def associations
460
- schema.associations
461
- end
442
+ def associations = schema.associations
462
443
 
463
444
  # Returns AST for the wrapped relation
464
445
  #
465
446
  # @return [Array]
466
447
  #
467
448
  # @api public
468
- def to_ast
469
- [:relation, [name.relation, attr_ast, meta_ast]]
470
- end
449
+ def to_ast = [:relation, [name.relation, attr_ast, meta_ast]]
471
450
 
472
451
  # @api private
473
- def attr_ast
474
- schema.map(&:to_read_ast)
475
- end
452
+ def attr_ast = schema.map(&:to_read_ast)
476
453
 
477
454
  # @api private
478
455
  def meta_ast
479
- meta = self.meta.merge(dataset: name.dataset, alias: name.aliaz, struct_namespace: options[:struct_namespace])
456
+ meta = self.meta.merge(dataset: name.dataset, alias: name.aliaz,
457
+ struct_namespace: options[:struct_namespace])
480
458
  meta[:model] = false unless auto_struct? || meta[:model]
481
459
  meta
482
460
  end
483
461
 
484
462
  # @api private
485
- def auto_map?
486
- (auto_map || auto_struct) && !meta[:combine_type]
487
- end
463
+ def auto_map? = (auto_map || auto_struct) && !meta[:combine_type]
488
464
 
489
465
  # @api private
490
- def auto_struct?
491
- auto_struct && !meta[:combine_type]
492
- end
466
+ def auto_struct? = auto_struct && !meta[:combine_type]
493
467
 
494
468
  # @api private
495
- def mapper
496
- mappers[to_ast]
497
- end
469
+ def mapper = mappers[to_ast]
498
470
 
499
471
  # Maps relation with custom mappers available in the registry
500
472
  #
@@ -522,9 +494,7 @@ module ROM
522
494
  # @return [Relation::Composite] Mapped relation
523
495
  #
524
496
  # @api public
525
- def map_with(*names, **opts)
526
- super(*names).with(opts)
527
- end
497
+ def map_with(*names, **opts) = super(*names).with(opts)
528
498
 
529
499
  # Return a new relation that will map its tuples to instances of the provided class
530
500
  #
@@ -550,25 +520,19 @@ module ROM
550
520
  # @return [Relation]
551
521
  #
552
522
  # @api public
553
- def as(aliaz)
554
- with(name: name.as(aliaz))
555
- end
523
+ def as(aliaz) = with(name: name.as(aliaz))
556
524
 
557
525
  # @return [Symbol] The wrapped relation's adapter identifier ie :sql or :http
558
526
  #
559
527
  # @api private
560
- def adapter
561
- self.class.adapter
562
- end
528
+ def adapter = self.class.adapter
563
529
 
564
530
  # Return name of the source gateway of this relation
565
531
  #
566
532
  # @return [Symbol]
567
533
  #
568
534
  # @api private
569
- def gateway
570
- self.class.gateway
571
- end
535
+ def gateway = self.class.gateway
572
536
 
573
537
  # Return all registered relation schemas
574
538
  #
@@ -577,9 +541,7 @@ module ROM
577
541
  # @return [Hash<Symbol=>Schema>]
578
542
  #
579
543
  # @api public
580
- def schemas
581
- self.class.schemas
582
- end
544
+ def schemas = self.class.schemas
583
545
 
584
546
  # Return a foreign key name for the provided relation name
585
547
  #
@@ -624,17 +586,13 @@ module ROM
624
586
  # @return [Class]
625
587
  #
626
588
  # @api private
627
- def composite_class
628
- Relation::Composite
629
- end
589
+ def composite_class = Relation::Composite
630
590
 
631
591
  # Return configured "wrap" relation class used in Relation#wrap
632
592
  #
633
593
  # @return [Class]
634
594
  #
635
595
  # @api private
636
- def wrap_class
637
- self.class.wrap_class
638
- end
596
+ def wrap_class = self.class.wrap_class
639
597
  end
640
598
  end
@@ -21,10 +21,10 @@ module ROM
21
21
  attr_reader :registry
22
22
 
23
23
  # @api private
24
- def initialize(source, &block)
24
+ def initialize(source, &)
25
25
  @source = source
26
26
  @registry = {}
27
- instance_exec(&block)
27
+ instance_exec(&)
28
28
  end
29
29
 
30
30
  # Establish a one-to-many association
@@ -177,9 +177,7 @@ module ROM
177
177
  # @return [AssociationSet]
178
178
  #
179
179
  # @api private
180
- def call
181
- AssociationSet[source.relation].build(registry)
182
- end
180
+ def call = AssociationSet[source.relation].build(registry)
183
181
 
184
182
  private
185
183
 
@@ -198,9 +196,7 @@ module ROM
198
196
  end
199
197
 
200
198
  # @api private
201
- def dataset_name(name)
202
- Inflector.pluralize(name).to_sym
203
- end
199
+ def dataset_name(name) = Inflector.pluralize(name).to_sym
204
200
  end
205
201
  end
206
202
  end
@@ -9,8 +9,8 @@ module ROM
9
9
  # Schema DSL exposed as `schema { .. }` in relation classes
10
10
  #
11
11
  # @api public
12
- class DSL < BasicObject
13
- KERNEL_METHODS = %i[extend method].freeze
12
+ class DSL < ::BasicObject
13
+ KERNEL_METHODS = %i[extend method block_given?].freeze
14
14
  KERNEL_METHODS.each { |m| define_method(m, ::Kernel.instance_method(m)) }
15
15
 
16
16
  extend Initializer
@@ -55,7 +55,7 @@ module ROM
55
55
  attr_reader :associations_dsl
56
56
 
57
57
  # @api private
58
- def initialize(*, &block)
58
+ def initialize(*, **, &block)
59
59
  super
60
60
 
61
61
  @attributes = {}
@@ -63,7 +63,6 @@ module ROM
63
63
 
64
64
  @definition = block
65
65
  end
66
- ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
67
66
 
68
67
  # Defines a relation attribute with its type and options.
69
68
  #
@@ -112,8 +111,8 @@ module ROM
112
111
  # @return [AssociationDSL]
113
112
  #
114
113
  # @api public
115
- def associations(&block)
116
- @associations_dsl = AssociationsDSL.new(relation, &block)
114
+ def associations(&)
115
+ @associations_dsl = AssociationsDSL.new(relation, &)
117
116
  end
118
117
 
119
118
  # Builds a representation of the information needed to create an
@@ -140,6 +139,7 @@ module ROM
140
139
  # @return [Dry::Types::Type] Type instance
141
140
  #
142
141
  # @api private
142
+ # rubocop:disable Metrics/AbcSize
143
143
  def build_type(type, options = EMPTY_HASH)
144
144
  if options[:read]
145
145
  type.meta(source: relation, read: options[:read])
@@ -147,8 +147,11 @@ module ROM
147
147
  type.meta(source: relation, read: type.meta[:read].optional)
148
148
  else
149
149
  type.meta(source: relation)
150
- end.meta(Attribute::META_OPTIONS.map { |opt| [opt, options[opt]] if options.key?(opt) }.compact.to_h)
150
+ end.meta(Attribute::META_OPTIONS.map { |opt|
151
+ [opt, options[opt]] if options.key?(opt)
152
+ }.compact.to_h)
151
153
  end
154
+ # rubocop:enable Metrics/AbcSize
152
155
 
153
156
  # Specify which key(s) should be the primary key
154
157
  #
@@ -179,21 +182,19 @@ module ROM
179
182
  end
180
183
 
181
184
  # @api private
182
- def call(&block)
183
- instance_exec(&block) if block
185
+ def call(&)
186
+ instance_exec(&) if block_given?
184
187
  instance_exec(&definition) if definition
185
188
 
186
189
  schema_class.define(relation, **opts) do |schema|
187
- plugins.values.each do |plugin, options|
190
+ plugins.each_value do |plugin, options|
188
191
  plugin.apply_to(schema, **options)
189
192
  end
190
193
  end
191
194
  end
192
195
 
193
196
  # @api private
194
- def plugin_options(plugin)
195
- @plugins[plugin][1]
196
- end
197
+ def plugin_options(plugin) = @plugins[plugin][1]
197
198
 
198
199
  private
199
200
 
@@ -24,10 +24,10 @@ module ROM
24
24
  # @return [Class(ROM::Attribute)]
25
25
  defines :attributes_inferrer, :attr_class
26
26
 
27
- MissingAttributesError = Class.new(StandardError) do
27
+ MissingAttributesError = ::Class.new(::StandardError) do
28
28
  def initialize(name, attributes)
29
29
  super(
30
- "Following attributes in #{Relation::Name[name].relation.inspect} schema cannot "\
30
+ "Following attributes in #{Relation::Name[name].relation.inspect} schema cannot " \
31
31
  "be inferred and have to be defined explicitly: #{attributes.map(&:inspect).join(', ')}"
32
32
  )
33
33
  end
@@ -39,7 +39,7 @@ module ROM
39
39
 
40
40
  attr_class Attribute
41
41
 
42
- include Dry::Equalizer(:options)
42
+ include ::Dry::Equalizer(:options)
43
43
 
44
44
  # @!attribute [r] attr_class
45
45
  # @return [Class(ROM::Attribute)]
@@ -78,6 +78,7 @@ module ROM
78
78
  end
79
79
 
80
80
  # @api private
81
+ # rubocop:disable Metrics/AbcSize
81
82
  def merge_attributes(defined, inferred)
82
83
  type_lookup = lambda do |attrs, name|
83
84
  attrs.find { |a| a.name == name }.type
@@ -99,6 +100,7 @@ module ROM
99
100
  defined_names.include?(attr.name)
100
101
  end
101
102
  end
103
+ # rubocop:enable Metrics/AbcSize
102
104
  end
103
105
  end
104
106
  end
data/lib/rom/schema.rb CHANGED
@@ -31,6 +31,7 @@ module ROM
31
31
  # schemas are merged, and we know which attributes belong to which relation.
32
32
  #
33
33
  # @api public
34
+ # rubocop:disable Metrics/ClassLength
34
35
  class Schema
35
36
  include Memoizable
36
37
 
@@ -39,7 +40,7 @@ module ROM
39
40
  subscribe('configuration.relations.registry.created') do |event|
40
41
  registry = event[:registry]
41
42
 
42
- registry.each do |_, relation|
43
+ registry.each_value do |relation|
43
44
  unless relation.schema.frozen?
44
45
  relation.schema.finalize_associations!(relations: registry)
45
46
  relation.schema.finalize!
@@ -160,12 +161,11 @@ module ROM
160
161
  end
161
162
 
162
163
  # @api private
163
- def initialize(*)
164
+ def initialize(*, **)
164
165
  super
165
166
 
166
167
  yield(self) if block_given?
167
168
  end
168
- ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
169
169
 
170
170
  # Abstract method for creating a new relation based on schema definition
171
171
  #
@@ -180,27 +180,21 @@ module ROM
180
180
  # @return [Relation]
181
181
  #
182
182
  # @api public
183
- def call(relation)
184
- relation
185
- end
183
+ def call(relation) = relation
186
184
 
187
185
  # Iterate over schema's attributes
188
186
  #
189
187
  # @yield [Attribute]
190
188
  #
191
189
  # @api public
192
- def each(&block)
193
- attributes.each(&block)
194
- end
190
+ def each(&) = attributes.each(&)
195
191
 
196
192
  # Check if schema has any attributes
197
193
  #
198
194
  # @return [TrueClass, FalseClass]
199
195
  #
200
196
  # @api public
201
- def empty?
202
- attributes.empty?
203
- end
197
+ def empty? = attributes.empty?
204
198
 
205
199
  # Coerce schema into a <AttributeName=>Attribute> Hash
206
200
  #
@@ -208,7 +202,11 @@ module ROM
208
202
  #
209
203
  # @api public
210
204
  def to_h
211
- each_with_object({}) { |attr, h| h[attr.name] = attr }
205
+ if block_given?
206
+ super
207
+ else
208
+ super { [_1.name, _1] }
209
+ end
212
210
  end
213
211
 
214
212
  # Return attribute
@@ -250,9 +248,7 @@ module ROM
250
248
  # @return [Schema]
251
249
  #
252
250
  # @api public
253
- def exclude(*names)
254
- project(*(map(&:name) - names))
255
- end
251
+ def exclude(*names) = project(*(map(&:name) - names))
256
252
 
257
253
  # Project a schema with renamed attributes
258
254
  #
@@ -309,9 +305,7 @@ module ROM
309
305
  # @return [Array<Attribute>]
310
306
  #
311
307
  # @api public
312
- def primary_key
313
- select(&:primary_key?)
314
- end
308
+ def primary_key = select(&:primary_key?)
315
309
 
316
310
  # Merge with another schema
317
311
  #
@@ -320,9 +314,7 @@ module ROM
320
314
  # @return [Schema]
321
315
  #
322
316
  # @api public
323
- def merge(other)
324
- append(*other)
325
- end
317
+ def merge(other) = append(*other)
326
318
  alias_method :+, :merge
327
319
 
328
320
  # Append more attributes to the schema
@@ -343,9 +335,9 @@ module ROM
343
335
  # @return [Schema]
344
336
  #
345
337
  # @api public
346
- def uniq(&block)
347
- if block
348
- new(attributes.uniq(&block))
338
+ def uniq(&)
339
+ if block_given?
340
+ new(attributes.uniq(&))
349
341
  else
350
342
  new(attributes.uniq(&:name))
351
343
  end
@@ -367,9 +359,7 @@ module ROM
367
359
  # @return [Boolean]
368
360
  #
369
361
  # @api public
370
- def canonical?
371
- equal?(canonical)
372
- end
362
+ def canonical? = equal?(canonical)
373
363
 
374
364
  # Finalize a schema
375
365
  #
@@ -390,7 +380,7 @@ module ROM
390
380
  # @return [self]
391
381
  #
392
382
  # @api private
393
- def finalize_attributes!(gateway: nil, relations: nil)
383
+ def finalize_attributes!(gateway: nil, **)
394
384
  inferrer.(self, gateway).each { |key, value| set!(key, value) }
395
385
 
396
386
  yield if block_given?
@@ -407,7 +397,7 @@ module ROM
407
397
  # @return [self]
408
398
  #
409
399
  # @api private
410
- def finalize_associations!(relations:)
400
+ def finalize_associations!(**)
411
401
  set!(:associations, yield) if associations.any?
412
402
  self
413
403
  end
@@ -421,7 +411,7 @@ module ROM
421
411
  # @api private
422
412
  def to_output_hash
423
413
  HASH_SCHEMA.schema(
424
- map { |attr| [attr.key, attr.to_read_type] }.to_h
414
+ to_h { |attr| [attr.key, attr.to_read_type] }
425
415
  )
426
416
  end
427
417
 
@@ -435,7 +425,7 @@ module ROM
435
425
  # @api private
436
426
  def to_input_hash
437
427
  HASH_SCHEMA.schema(
438
- map { |attr| [attr.name, attr.to_write_type] }.to_h
428
+ to_h { |attr| [attr.name, attr.to_write_type] }
439
429
  )
440
430
  end
441
431
 
@@ -444,9 +434,7 @@ module ROM
444
434
  # @return [Array]
445
435
  #
446
436
  # @api public
447
- def to_ast
448
- [:schema, [name, attributes.map(&:to_ast)]]
449
- end
437
+ def to_ast = [:schema, [name, attributes.map(&:to_ast)]]
450
438
 
451
439
  # @api private
452
440
  def set!(key, value)
@@ -458,20 +446,17 @@ module ROM
458
446
 
459
447
  # @api private
460
448
  def count_index
461
- map(&:name).map { |name| [name, count { |attr| attr.name == name }] }.to_h
449
+ to_h { |attr| [attr.name, count { |a| a.name.eql?(attr.name) }] }
462
450
  end
463
451
 
464
452
  # @api private
465
- def name_index
466
- map { |attr| [attr.name, attr] }.to_h
467
- end
453
+ def name_index = to_h { |attr| [attr.name, attr] }
468
454
 
469
455
  # @api private
470
456
  def source_index
471
457
  select(&:source)
472
458
  .group_by(&:source)
473
- .map { |src, grp| [src.to_sym, grp.map { |attr| [attr.name, attr] }.to_h] }
474
- .to_h
459
+ .to_h { |src, grp| [src.to_sym, grp.to_h { |attr| [attr.name, attr] }] }
475
460
  end
476
461
 
477
462
  # @api private
@@ -489,4 +474,5 @@ module ROM
489
474
 
490
475
  memoize :count_index, :name_index, :source_index, :to_ast, :to_input_hash, :to_output_hash
491
476
  end
477
+ # rubocop:enable Metrics/ClassLength
492
478
  end
@@ -44,11 +44,9 @@ module ROM
44
44
  # @!attribute [r] globs
45
45
  # @return [Hash] File globbing functions for each component dir
46
46
  option :globs, default: lambda {
47
- Hash[
48
- component_dirs.map { |component, path|
49
- [component, directory.join("#{path}/**/*.rb")]
50
- }
51
- ]
47
+ component_dirs.transform_values { |path|
48
+ directory.join("#{path}/**/*.rb")
49
+ }
52
50
  }
53
51
 
54
52
  # Load relation files
@@ -78,7 +76,7 @@ module ROM
78
76
  #
79
77
  # @api private
80
78
  def load_entities(entity)
81
- Dir[globs[entity]].sort.map do |file|
79
+ Dir[globs[entity]].map do |file|
82
80
  require file
83
81
  klass_name =
84
82
  case namespace
@@ -13,7 +13,7 @@ module ROM
13
13
 
14
14
  PathnameType = Types.Instance(Pathname)
15
15
 
16
- EXTENSION_REGEX = /\.rb\z/.freeze
16
+ EXTENSION_REGEX = /\.rb\z/
17
17
 
18
18
  # @!attribute [r] file
19
19
  # @return [String] Name of a component file