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.
- checksums.yaml +4 -4
- data/lib/rom/array_dataset.rb +5 -5
- data/lib/rom/association_set.rb +1 -2
- data/lib/rom/associations/definitions/abstract.rb +5 -3
- data/lib/rom/associations/many_to_many.rb +1 -2
- data/lib/rom/attribute.rb +15 -37
- data/lib/rom/auto_curry.rb +34 -23
- data/lib/rom/cache.rb +9 -21
- data/lib/rom/command.rb +19 -37
- data/lib/rom/command_compiler.rb +12 -14
- data/lib/rom/command_proxy.rb +6 -10
- data/lib/rom/command_registry.rb +4 -8
- data/lib/rom/commands/class_interface.rb +20 -20
- data/lib/rom/commands/composite.rb +3 -0
- data/lib/rom/commands/graph/class_interface.rb +3 -1
- data/lib/rom/commands/graph/input_evaluator.rb +3 -1
- data/lib/rom/commands/graph.rb +3 -0
- data/lib/rom/commands/lazy/create.rb +2 -0
- data/lib/rom/commands/lazy/update.rb +2 -0
- data/lib/rom/commands/lazy.rb +2 -3
- data/lib/rom/configuration.rb +14 -16
- data/lib/rom/configuration_dsl/command.rb +2 -2
- data/lib/rom/configuration_dsl/command_dsl.rb +9 -5
- data/lib/rom/configuration_dsl/mapper_dsl.rb +12 -3
- data/lib/rom/configuration_dsl/relation.rb +4 -2
- data/lib/rom/configuration_dsl.rb +8 -10
- data/lib/rom/constants.rb +26 -26
- data/lib/rom/container.rb +15 -15
- data/lib/rom/core/version.rb +1 -1
- data/lib/rom/core.rb +0 -1
- data/lib/rom/create_container.rb +3 -5
- data/lib/rom/data_proxy.rb +13 -15
- data/lib/rom/enumerable_dataset.rb +6 -6
- data/lib/rom/environment.rb +5 -5
- data/lib/rom/gateway.rb +4 -12
- data/lib/rom/global/plugin_dsl.rb +4 -4
- data/lib/rom/global.rb +2 -2
- data/lib/rom/header/attribute.rb +1 -1
- data/lib/rom/header.rb +13 -35
- data/lib/rom/initializer.rb +11 -15
- data/lib/rom/lint/enumerable_dataset.rb +2 -1
- data/lib/rom/lint/gateway.rb +3 -1
- data/lib/rom/lint/linter.rb +2 -2
- data/lib/rom/lint/test.rb +4 -6
- data/lib/rom/mapper/attribute_dsl.rb +39 -27
- data/lib/rom/mapper/builder.rb +2 -2
- data/lib/rom/mapper/dsl.rb +2 -3
- data/lib/rom/mapper/model_dsl.rb +5 -1
- data/lib/rom/mapper.rb +2 -4
- data/lib/rom/mapper_compiler.rb +3 -2
- data/lib/rom/mapper_registry.rb +2 -4
- data/lib/rom/memory/commands.rb +1 -1
- data/lib/rom/memory/dataset.rb +7 -5
- data/lib/rom/memory/gateway.rb +1 -0
- data/lib/rom/model_builder.rb +14 -14
- data/lib/rom/open_struct.rb +1 -1
- data/lib/rom/pipeline.rb +6 -15
- data/lib/rom/plugin_registry.rb +4 -10
- data/lib/rom/plugins/command/timestamps.rb +9 -5
- data/lib/rom/plugins/relation/instrumentation.rb +7 -2
- data/lib/rom/plugins/relation/registry_reader.rb +3 -15
- data/lib/rom/plugins.rb +1 -3
- data/lib/rom/processor/transproc.rb +14 -4
- data/lib/rom/processor.rb +1 -0
- data/lib/rom/registry.rb +20 -29
- data/lib/rom/relation/class_interface.rb +18 -16
- data/lib/rom/relation/combined.rb +7 -4
- data/lib/rom/relation/composite.rb +2 -6
- data/lib/rom/relation/curried.rb +12 -11
- data/lib/rom/relation/graph.rb +4 -12
- data/lib/rom/relation/loaded.rb +8 -16
- data/lib/rom/relation/materializable.rb +6 -14
- data/lib/rom/relation/name.rb +5 -14
- data/lib/rom/relation/view_dsl.rb +7 -9
- data/lib/rom/relation/wrap.rb +3 -9
- data/lib/rom/relation.rb +39 -81
- data/lib/rom/schema/associations_dsl.rb +4 -8
- data/lib/rom/schema/dsl.rb +14 -13
- data/lib/rom/schema/inferrer.rb +5 -3
- data/lib/rom/schema.rb +27 -41
- data/lib/rom/setup/auto_registration.rb +4 -6
- data/lib/rom/setup/auto_registration_strategies/base.rb +1 -1
- data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +4 -8
- data/lib/rom/setup/finalize/finalize_commands.rb +3 -0
- data/lib/rom/setup/finalize/finalize_mappers.rb +16 -14
- data/lib/rom/setup/finalize/finalize_relations.rb +30 -4
- data/lib/rom/setup/finalize.rb +17 -3
- data/lib/rom/setup.rb +5 -4
- data/lib/rom/struct.rb +20 -18
- data/lib/rom/struct_compiler.rb +4 -7
- data/lib/rom/support/configurable.rb +10 -20
- data/lib/rom/support/memoizable.rb +10 -9
- data/lib/rom/support/notifications.rb +4 -8
- data/lib/rom/transaction.rb +2 -4
- data/lib/rom/transformer.rb +6 -10
- data/lib/rom/types.rb +3 -6
- metadata +15 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d157d2abe517cdafa10b73c50b3ccf54647a5251887b0bd59e007abfc72b5de3
|
4
|
+
data.tar.gz: 944ee8977bd9cdd2e980c7d67ec5d96e96db4dd51b8372218cfaaa58ddb397e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 346ca3842e535322fd537e01812db38ee8f1f9b5eb35087deb3e8bfa3e55d378b9702a12f49f9e084610307281ab1a638c728dafa598517bd691104d80be12a3
|
7
|
+
data.tar.gz: a60428bda2a664a8b38deec4fd272ecb02e31cb3530bd9e5f4a6f30371f128fb6abb4186e4d914a8f8f35c7d7c6d3cfa771a47aea47c9fe1dd212683c0321b88
|
data/lib/rom/array_dataset.rb
CHANGED
@@ -35,11 +35,11 @@ module ROM
|
|
35
35
|
map! combination cycle delete_if keep_if permutation reject!
|
36
36
|
select! sort_by!
|
37
37
|
].each do |method|
|
38
|
-
class_eval
|
39
|
-
def #{method}(*args, &
|
40
|
-
return to_enum unless
|
41
|
-
self.class.new(data.
|
42
|
-
end
|
38
|
+
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
39
|
+
def #{method}(*args, &) # def map!(*args, &)
|
40
|
+
return to_enum unless block_given? # return to_enum unless block_given?
|
41
|
+
self.class.new(data.__send__(:#{method}, *args, &), **options) # self.class.new(data.__send__(:map!, *args, &), **options)
|
42
|
+
end # end
|
43
43
|
RUBY
|
44
44
|
end
|
45
45
|
end
|
data/lib/rom/association_set.rb
CHANGED
@@ -9,12 +9,11 @@ module ROM
|
|
9
9
|
# @api public
|
10
10
|
class AssociationSet < ROM::Registry
|
11
11
|
# @api private
|
12
|
-
def initialize(
|
12
|
+
def initialize(...)
|
13
13
|
super
|
14
14
|
elements.values.each do |assoc|
|
15
15
|
elements[assoc.name] = assoc if assoc.aliased? && !key?(assoc.name)
|
16
16
|
end
|
17
17
|
end
|
18
|
-
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
|
19
18
|
end
|
20
19
|
end
|
@@ -67,14 +67,16 @@ module ROM
|
|
67
67
|
# @option opts [Symbol] :as The name of the association (defaults to target)
|
68
68
|
# @option opts [Symbol] :relation The name of the target relation (defaults to target)
|
69
69
|
# @option opts [Symbol] :foreign_key The name of a custom foreign key
|
70
|
-
# @option opts [Symbol] :view The name of a custom relation view
|
71
|
-
#
|
70
|
+
# @option opts [Symbol] :view The name of a custom relation view
|
71
|
+
# on the target's relation side
|
72
|
+
# @option opts [true, false] :override Whether provided :view should override
|
73
|
+
# association's default view
|
72
74
|
#
|
73
75
|
# @api public
|
74
76
|
def self.new(source, target, **opts)
|
75
77
|
source_name = Relation::Name[source]
|
76
78
|
target_name = resolve_target_name(target, opts)
|
77
|
-
options = process_options(target_name,
|
79
|
+
options = process_options(target_name, opts.to_h)
|
78
80
|
|
79
81
|
super(source_name, target_name, **options)
|
80
82
|
end
|
@@ -14,11 +14,10 @@ module ROM
|
|
14
14
|
attr_reader :join_relation
|
15
15
|
|
16
16
|
# @api private
|
17
|
-
def initialize(
|
17
|
+
def initialize(*, **)
|
18
18
|
super
|
19
19
|
@join_relation = relations[through]
|
20
20
|
end
|
21
|
-
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
|
22
21
|
|
23
22
|
# Adapters should implement this method
|
24
23
|
#
|
data/lib/rom/attribute.rb
CHANGED
@@ -23,7 +23,8 @@ module ROM
|
|
23
23
|
META_OPTIONS = %i[primary_key foreign_key source target relation].freeze
|
24
24
|
|
25
25
|
# @!attribute [r] type
|
26
|
-
# @return [Dry::Types::Nominal, Dry::Types::Sum, Dry::Types::Constrained] The attribute's
|
26
|
+
# @return [Dry::Types::Nominal, Dry::Types::Sum, Dry::Types::Constrained] The attribute's
|
27
|
+
# type object
|
27
28
|
param :type
|
28
29
|
|
29
30
|
# @!attribute [r] name
|
@@ -82,9 +83,7 @@ module ROM
|
|
82
83
|
# @return [TrueClass,FalseClass]
|
83
84
|
#
|
84
85
|
# @api public
|
85
|
-
def primary_key?
|
86
|
-
meta[:primary_key].equal?(true)
|
87
|
-
end
|
86
|
+
def primary_key? = meta[:primary_key].equal?(true)
|
88
87
|
|
89
88
|
# Return true if this attribute type is a foreign key
|
90
89
|
#
|
@@ -105,9 +104,7 @@ module ROM
|
|
105
104
|
# @return [TrueClass,FalseClass]
|
106
105
|
#
|
107
106
|
# @api public
|
108
|
-
def foreign_key?
|
109
|
-
meta[:foreign_key].equal?(true)
|
110
|
-
end
|
107
|
+
def foreign_key? = meta[:foreign_key].equal?(true)
|
111
108
|
|
112
109
|
# Return true if this attribute has a configured alias
|
113
110
|
#
|
@@ -128,9 +125,7 @@ module ROM
|
|
128
125
|
# @return [TrueClass,FalseClass]
|
129
126
|
#
|
130
127
|
# @api public
|
131
|
-
def aliased?
|
132
|
-
!self.alias.nil?
|
133
|
-
end
|
128
|
+
def aliased? = !self.alias.nil?
|
134
129
|
|
135
130
|
# Return source relation of this attribute type
|
136
131
|
#
|
@@ -151,9 +146,7 @@ module ROM
|
|
151
146
|
# @return [Symbol, Relation::Name]
|
152
147
|
#
|
153
148
|
# @api public
|
154
|
-
def source
|
155
|
-
meta[:source]
|
156
|
-
end
|
149
|
+
def source = meta[:source]
|
157
150
|
|
158
151
|
# Return target relation of this attribute type
|
159
152
|
#
|
@@ -174,9 +167,7 @@ module ROM
|
|
174
167
|
# @return [NilClass, Symbol, Relation::Name]
|
175
168
|
#
|
176
169
|
# @api public
|
177
|
-
def target
|
178
|
-
meta[:target]
|
179
|
-
end
|
170
|
+
def target = meta[:target]
|
180
171
|
|
181
172
|
# Return tuple key
|
182
173
|
#
|
@@ -199,9 +190,7 @@ module ROM
|
|
199
190
|
# @return [Symbol]
|
200
191
|
#
|
201
192
|
# @api public
|
202
|
-
def key
|
203
|
-
self.alias || name
|
204
|
-
end
|
193
|
+
def key = self.alias || name
|
205
194
|
|
206
195
|
# Return new attribute type with provided alias
|
207
196
|
#
|
@@ -229,9 +218,7 @@ module ROM
|
|
229
218
|
# @return [Attribute]
|
230
219
|
#
|
231
220
|
# @api public
|
232
|
-
def aliased(name)
|
233
|
-
with(alias: name)
|
234
|
-
end
|
221
|
+
def aliased(name) = with(alias: name)
|
235
222
|
alias_method :as, :aliased
|
236
223
|
|
237
224
|
# Return new attribute type with an alias using provided prefix
|
@@ -276,9 +263,7 @@ module ROM
|
|
276
263
|
# correctly in places like auto-mapping.
|
277
264
|
#
|
278
265
|
# @api public
|
279
|
-
def wrapped?
|
280
|
-
meta[:wrapped].equal?(true)
|
281
|
-
end
|
266
|
+
def wrapped? = meta[:wrapped].equal?(true)
|
282
267
|
|
283
268
|
# Return attribute type wrapped for the specified relation name
|
284
269
|
#
|
@@ -337,27 +322,21 @@ module ROM
|
|
337
322
|
# @return [TrueClass, FalseClass]
|
338
323
|
#
|
339
324
|
# @api private
|
340
|
-
def read?
|
341
|
-
!meta[:read].nil?
|
342
|
-
end
|
325
|
+
def read? = !meta[:read].nil?
|
343
326
|
|
344
327
|
# Return read type
|
345
328
|
#
|
346
329
|
# @return [Dry::Types::Type]
|
347
330
|
#
|
348
331
|
# @api private
|
349
|
-
def to_read_type
|
350
|
-
read? ? meta[:read] : type
|
351
|
-
end
|
332
|
+
def to_read_type = read? ? meta[:read] : type
|
352
333
|
|
353
334
|
# Return write type
|
354
335
|
#
|
355
336
|
# @return [Dry::Types::Type]
|
356
337
|
#
|
357
338
|
# @api private
|
358
|
-
def to_write_type
|
359
|
-
type
|
360
|
-
end
|
339
|
+
def to_write_type = type
|
361
340
|
|
362
341
|
# Return nullable attribute
|
363
342
|
#
|
@@ -405,9 +384,9 @@ module ROM
|
|
405
384
|
private
|
406
385
|
|
407
386
|
# @api private
|
408
|
-
def method_missing(meth,
|
387
|
+
def method_missing(meth, ...)
|
409
388
|
if type.respond_to?(meth)
|
410
|
-
response = type.__send__(meth,
|
389
|
+
response = type.__send__(meth, ...)
|
411
390
|
|
412
391
|
if response.is_a?(type.class)
|
413
392
|
self.class.new(response, **options)
|
@@ -418,6 +397,5 @@ module ROM
|
|
418
397
|
super
|
419
398
|
end
|
420
399
|
end
|
421
|
-
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
422
400
|
end
|
423
401
|
end
|
data/lib/rom/auto_curry.rb
CHANGED
@@ -5,6 +5,33 @@ module ROM
|
|
5
5
|
#
|
6
6
|
# @api private
|
7
7
|
module AutoCurry
|
8
|
+
# @api private
|
9
|
+
class Wrapper < ::Module
|
10
|
+
def initialize(name, arity, &block)
|
11
|
+
define_method(name) do |*args, **kwargs, &mblock|
|
12
|
+
kwargs_size =
|
13
|
+
if kwargs.empty?
|
14
|
+
0
|
15
|
+
else
|
16
|
+
1
|
17
|
+
end
|
18
|
+
|
19
|
+
response =
|
20
|
+
if arity.negative? || arity.eql?(args.size + kwargs_size)
|
21
|
+
super(*args, **kwargs, &mblock)
|
22
|
+
else
|
23
|
+
self.class.curried.new(self, view: name, curry_args: args, arity: arity)
|
24
|
+
end
|
25
|
+
|
26
|
+
if block
|
27
|
+
response.instance_exec(&block)
|
28
|
+
else
|
29
|
+
response
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
8
35
|
def self.extended(klass)
|
9
36
|
klass.define_singleton_method(:method_added) do |name|
|
10
37
|
return if auto_curry_busy?
|
@@ -37,34 +64,18 @@ module ROM
|
|
37
64
|
# @param [Symbol] name The name of a method
|
38
65
|
#
|
39
66
|
# @api private
|
40
|
-
def auto_curry(name, &
|
67
|
+
def auto_curry(name, &)
|
41
68
|
arity = instance_method(name).arity
|
42
69
|
|
43
|
-
|
70
|
+
if public_instance_methods.include?(name) && arity != 0
|
71
|
+
mod = Wrapper.new(name, arity, &)
|
44
72
|
|
45
|
-
|
46
|
-
|
47
|
-
mod.module_eval do
|
48
|
-
define_method(name) do |*args, &mblock|
|
49
|
-
response =
|
50
|
-
if arity < 0 || arity == args.size
|
51
|
-
super(*args, &mblock)
|
52
|
-
else
|
53
|
-
self.class.curried.new(self, view: name, curry_args: args, arity: arity)
|
54
|
-
end
|
73
|
+
auto_curried_methods << name
|
55
74
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
response
|
60
|
-
end
|
61
|
-
end
|
62
|
-
ruby2_keywords(name) if respond_to?(:ruby2_keywords, true)
|
75
|
+
prepend(mod)
|
76
|
+
else
|
77
|
+
self
|
63
78
|
end
|
64
|
-
|
65
|
-
auto_curried_methods << name
|
66
|
-
|
67
|
-
prepend(mod)
|
68
79
|
end
|
69
80
|
end
|
70
81
|
end
|
data/lib/rom/cache.rb
CHANGED
@@ -24,45 +24,33 @@ module ROM
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# @api private
|
27
|
-
def [](key)
|
28
|
-
cache[[namespace, key].hash]
|
29
|
-
end
|
27
|
+
def [](key) = cache[[namespace, key].hash]
|
30
28
|
|
31
29
|
# @api private
|
32
|
-
def fetch_or_store(*args, &
|
33
|
-
cache.fetch_or_store([namespace, args
|
30
|
+
def fetch_or_store(*args, &)
|
31
|
+
cache.fetch_or_store([namespace, args].hash, &)
|
34
32
|
end
|
35
33
|
|
36
34
|
# @api private
|
37
|
-
def size
|
38
|
-
cache.size
|
39
|
-
end
|
35
|
+
def size = cache.size
|
40
36
|
|
41
37
|
# @api private
|
42
|
-
def inspect
|
43
|
-
%(#<#{self.class} size=#{size}>)
|
44
|
-
end
|
38
|
+
def inspect = %(#<#{self.class} size=#{size}>)
|
45
39
|
end
|
46
40
|
|
47
41
|
# @api private
|
48
42
|
def initialize
|
49
|
-
@objects = Concurrent::Map.new
|
43
|
+
@objects = ::Concurrent::Map.new
|
50
44
|
@namespaced = {}
|
51
45
|
end
|
52
46
|
|
53
|
-
def [](key)
|
54
|
-
cache[key]
|
55
|
-
end
|
47
|
+
def [](key) = objects[key]
|
56
48
|
|
57
49
|
# @api private
|
58
|
-
def fetch_or_store(*args, &
|
59
|
-
objects.fetch_or_store(args.hash, &block)
|
60
|
-
end
|
50
|
+
def fetch_or_store(*args, &) = objects.fetch_or_store(args.hash, &)
|
61
51
|
|
62
52
|
# @api private
|
63
|
-
def size
|
64
|
-
objects.size
|
65
|
-
end
|
53
|
+
def size = objects.size
|
66
54
|
|
67
55
|
# @api private
|
68
56
|
def namespaced(namespace)
|
data/lib/rom/command.rb
CHANGED
@@ -265,7 +265,9 @@ module ROM
|
|
265
265
|
# This method will apply before/after hooks automatically
|
266
266
|
#
|
267
267
|
# @api public
|
268
|
-
|
268
|
+
#
|
269
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
270
|
+
def call(*args, &)
|
269
271
|
tuples =
|
270
272
|
if hooks?
|
271
273
|
prepared =
|
@@ -275,7 +277,7 @@ module ROM
|
|
275
277
|
apply_hooks(before_hooks, *args)
|
276
278
|
end
|
277
279
|
|
278
|
-
result = prepared ? execute(prepared, &
|
280
|
+
result = prepared ? execute(prepared, &) : execute(&)
|
279
281
|
|
280
282
|
if curried?
|
281
283
|
if !args.empty?
|
@@ -286,10 +288,10 @@ module ROM
|
|
286
288
|
apply_hooks(after_hooks, result)
|
287
289
|
end
|
288
290
|
else
|
289
|
-
apply_hooks(after_hooks, result, *args
|
291
|
+
apply_hooks(after_hooks, result, *args.drop(1))
|
290
292
|
end
|
291
293
|
else
|
292
|
-
execute(*(curry_args + args), &
|
294
|
+
execute(*(curry_args + args), &)
|
293
295
|
end
|
294
296
|
|
295
297
|
if one?
|
@@ -298,6 +300,8 @@ module ROM
|
|
298
300
|
tuples
|
299
301
|
end
|
300
302
|
end
|
303
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
304
|
+
|
301
305
|
alias_method :[], :call
|
302
306
|
|
303
307
|
# Curry this command with provided args
|
@@ -323,18 +327,14 @@ module ROM
|
|
323
327
|
# @return [Command::Graph]
|
324
328
|
#
|
325
329
|
# @api public
|
326
|
-
def combine(*others)
|
327
|
-
Graph.new(self, others)
|
328
|
-
end
|
330
|
+
def combine(*others) = Graph.new(self, others)
|
329
331
|
|
330
332
|
# Check if this command is curried
|
331
333
|
#
|
332
334
|
# @return [TrueClass, FalseClass]
|
333
335
|
#
|
334
336
|
# @api public
|
335
|
-
def curried?
|
336
|
-
!curry_args.empty?
|
337
|
-
end
|
337
|
+
def curried? = !curry_args.empty?
|
338
338
|
|
339
339
|
# Return a new command with appended before hooks
|
340
340
|
#
|
@@ -363,18 +363,14 @@ module ROM
|
|
363
363
|
# @return [Array]
|
364
364
|
#
|
365
365
|
# @api public
|
366
|
-
def before_hooks
|
367
|
-
options[:before]
|
368
|
-
end
|
366
|
+
def before_hooks = options[:before]
|
369
367
|
|
370
368
|
# List of after hooks
|
371
369
|
#
|
372
370
|
# @return [Array]
|
373
371
|
#
|
374
372
|
# @api public
|
375
|
-
def after_hooks
|
376
|
-
options[:after]
|
377
|
-
end
|
373
|
+
def after_hooks = options[:after]
|
378
374
|
|
379
375
|
# Return a new command with other source relation
|
380
376
|
#
|
@@ -390,54 +386,42 @@ module ROM
|
|
390
386
|
# Check if this command has any hooks
|
391
387
|
#
|
392
388
|
# @api private
|
393
|
-
def hooks?
|
394
|
-
!before_hooks.empty? || !after_hooks.empty?
|
395
|
-
end
|
389
|
+
def hooks? = !before_hooks.empty? || !after_hooks.empty?
|
396
390
|
|
397
391
|
# Check if this command is lazy
|
398
392
|
#
|
399
393
|
# @return [false]
|
400
394
|
#
|
401
395
|
# @api private
|
402
|
-
def lazy?
|
403
|
-
false
|
404
|
-
end
|
396
|
+
def lazy? = false
|
405
397
|
|
406
398
|
# Check if this command is a graph
|
407
399
|
#
|
408
400
|
# @return [false]
|
409
401
|
#
|
410
402
|
# @api private
|
411
|
-
def graph?
|
412
|
-
false
|
413
|
-
end
|
403
|
+
def graph? = false
|
414
404
|
|
415
405
|
# Check if this command returns a single tuple
|
416
406
|
#
|
417
407
|
# @return [TrueClass,FalseClass]
|
418
408
|
#
|
419
409
|
# @api private
|
420
|
-
def one?
|
421
|
-
result.equal?(:one)
|
422
|
-
end
|
410
|
+
def one? = result.equal?(:one)
|
423
411
|
|
424
412
|
# Check if this command returns many tuples
|
425
413
|
#
|
426
414
|
# @return [TrueClass,FalseClass]
|
427
415
|
#
|
428
416
|
# @api private
|
429
|
-
def many?
|
430
|
-
result.equal?(:many)
|
431
|
-
end
|
417
|
+
def many? = result.equal?(:many)
|
432
418
|
|
433
419
|
# Check if this command is restrictible through relation
|
434
420
|
#
|
435
421
|
# @return [TrueClass,FalseClass]
|
436
422
|
#
|
437
423
|
# @api private
|
438
|
-
def restrictible?
|
439
|
-
self.class.restrictable.equal?(true)
|
440
|
-
end
|
424
|
+
def restrictible? = self.class.restrictable.equal?(true)
|
441
425
|
|
442
426
|
# Yields tuples for insertion or return an enumerator
|
443
427
|
#
|
@@ -459,9 +443,7 @@ module ROM
|
|
459
443
|
# @return [Class]
|
460
444
|
#
|
461
445
|
# @api private
|
462
|
-
def composite_class
|
463
|
-
Command::Composite
|
464
|
-
end
|
446
|
+
def composite_class = Command::Composite
|
465
447
|
|
466
448
|
# Apply provided hooks
|
467
449
|
#
|
data/lib/rom/command_compiler.rb
CHANGED
@@ -128,6 +128,8 @@ module ROM
|
|
128
128
|
private
|
129
129
|
|
130
130
|
# @api private
|
131
|
+
#
|
132
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
131
133
|
def visit_relation(node, parent_relation = nil)
|
132
134
|
name, header, meta = node
|
133
135
|
other = header.map { |attr| visit(attr, name) }.compact
|
@@ -157,21 +159,20 @@ module ROM
|
|
157
159
|
default_mapping
|
158
160
|
end
|
159
161
|
|
160
|
-
if
|
161
|
-
[mapping, [type, other]]
|
162
|
-
else
|
162
|
+
if other.empty?
|
163
163
|
[mapping, type]
|
164
|
+
else
|
165
|
+
[mapping, [type, other]]
|
164
166
|
end
|
165
167
|
else
|
166
168
|
registry[name][id] = commands[name][id]
|
167
169
|
[name, id]
|
168
170
|
end
|
169
171
|
end
|
172
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
170
173
|
|
171
174
|
# @api private
|
172
|
-
def visit_attribute(*_args)
|
173
|
-
nil
|
174
|
-
end
|
175
|
+
def visit_attribute(*_args) = nil
|
175
176
|
|
176
177
|
# Build a command object for a specific relation
|
177
178
|
#
|
@@ -187,6 +188,8 @@ module ROM
|
|
187
188
|
# @return [ROM::Command]
|
188
189
|
#
|
189
190
|
# @api private
|
191
|
+
#
|
192
|
+
# rubocop:disable Metrics/AbcSize
|
190
193
|
def register_command(rel_name, type, rel_meta, parent_relation = nil)
|
191
194
|
relation = relations[rel_name]
|
192
195
|
|
@@ -216,15 +219,14 @@ module ROM
|
|
216
219
|
registry[rel_name][type] = klass.build(relation)
|
217
220
|
end
|
218
221
|
end
|
222
|
+
# rubocop:enable Metrics/AbcSize
|
219
223
|
|
220
224
|
# Return default result type
|
221
225
|
#
|
222
226
|
# @return [Symbol]
|
223
227
|
#
|
224
228
|
# @api private
|
225
|
-
def result
|
226
|
-
meta.fetch(:result, :one)
|
227
|
-
end
|
229
|
+
def result = meta.fetch(:result, :one)
|
228
230
|
|
229
231
|
# Sets up `associates` plugin for a given command class and relation
|
230
232
|
#
|
@@ -241,11 +243,7 @@ module ROM
|
|
241
243
|
singular_name if relation.associations.key?(singular_name)
|
242
244
|
end
|
243
245
|
|
244
|
-
|
245
|
-
klass.associates(assoc_name)
|
246
|
-
else
|
247
|
-
klass.associates(parent_relation)
|
248
|
-
end
|
246
|
+
klass.associates(assoc_name || parent_relation)
|
249
247
|
end
|
250
248
|
end
|
251
249
|
end
|
data/lib/rom/command_proxy.rb
CHANGED
@@ -8,7 +8,9 @@ module ROM
|
|
8
8
|
#
|
9
9
|
# @api private
|
10
10
|
class CommandProxy
|
11
|
-
attr_reader :command
|
11
|
+
attr_reader :command
|
12
|
+
|
13
|
+
attr_reader :root
|
12
14
|
|
13
15
|
# @api private
|
14
16
|
def initialize(command, root = Inflector.singularize(command.name.relation).to_sym)
|
@@ -17,18 +19,12 @@ module ROM
|
|
17
19
|
end
|
18
20
|
|
19
21
|
# @api private
|
20
|
-
def call(input)
|
21
|
-
command.call(root => input)
|
22
|
-
end
|
22
|
+
def call(input) = command.call(root => input)
|
23
23
|
|
24
24
|
# @api private
|
25
|
-
def >>(other)
|
26
|
-
self.class.new(command >> other)
|
27
|
-
end
|
25
|
+
def >>(other) = self.class.new(command >> other)
|
28
26
|
|
29
27
|
# @api private
|
30
|
-
def restrictible?
|
31
|
-
command.restrictible?
|
32
|
-
end
|
28
|
+
def restrictible? = command.restrictible?
|
33
29
|
end
|
34
30
|
end
|
data/lib/rom/command_registry.rb
CHANGED
@@ -34,9 +34,7 @@ module ROM
|
|
34
34
|
option :compiler, optional: true
|
35
35
|
|
36
36
|
# @api private
|
37
|
-
def self.element_not_found_error
|
38
|
-
CommandNotFoundError
|
39
|
-
end
|
37
|
+
def self.element_not_found_error = CommandNotFoundError
|
40
38
|
|
41
39
|
# Return a command from the registry
|
42
40
|
#
|
@@ -86,17 +84,15 @@ module ROM
|
|
86
84
|
# @return [CommandRegistry]
|
87
85
|
#
|
88
86
|
# @api public
|
89
|
-
def map_with(mapper_name)
|
90
|
-
with(mapper: mappers[mapper_name])
|
91
|
-
end
|
87
|
+
def map_with(mapper_name) = with(mapper: mappers[mapper_name])
|
92
88
|
|
93
89
|
# @api private
|
94
|
-
def set_compiler(compiler)
|
90
|
+
def set_compiler(compiler) # rubocop:disable Naming/AccessorMethodName
|
95
91
|
options[:compiler] = @compiler = compiler
|
96
92
|
end
|
97
93
|
|
98
94
|
# @api private
|
99
|
-
def set_mappers(mappers)
|
95
|
+
def set_mappers(mappers) # rubocop:disable Naming/AccessorMethodName
|
100
96
|
options[:mappers] = @mappers = mappers
|
101
97
|
end
|
102
98
|
|