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.
- checksums.yaml +4 -4
- data/lib/rom/array_dataset.rb +4 -4
- data/lib/rom/association_set.rb +2 -3
- data/lib/rom/associations/definitions/abstract.rb +2 -2
- data/lib/rom/associations/many_to_many.rb +1 -0
- data/lib/rom/attribute.rb +5 -4
- data/lib/rom/auto_curry.rb +2 -0
- data/lib/rom/command.rb +6 -6
- data/lib/rom/command_compiler.rb +5 -7
- data/lib/rom/commands/class_interface.rb +7 -7
- data/lib/rom/commands/composite.rb +1 -1
- data/lib/rom/commands/graph/input_evaluator.rb +1 -1
- data/lib/rom/commands/lazy.rb +2 -1
- data/lib/rom/commands/lazy/create.rb +1 -1
- data/lib/rom/commands/lazy/update.rb +3 -3
- data/lib/rom/configuration.rb +5 -5
- data/lib/rom/configuration_dsl/relation.rb +1 -1
- data/lib/rom/constants.rb +1 -1
- data/lib/rom/core/version.rb +1 -1
- data/lib/rom/data_proxy.rb +3 -2
- data/lib/rom/enumerable_dataset.rb +4 -4
- data/lib/rom/environment.rb +0 -1
- data/lib/rom/header/attribute.rb +2 -4
- data/lib/rom/initializer.rb +9 -7
- data/lib/rom/lint/gateway.rb +1 -3
- data/lib/rom/lint/linter.rb +3 -4
- data/lib/rom/lint/spec.rb +2 -2
- data/lib/rom/mapper.rb +4 -3
- data/lib/rom/mapper/attribute_dsl.rb +5 -5
- data/lib/rom/mapper/dsl.rb +2 -5
- data/lib/rom/mapper/model_dsl.rb +2 -1
- data/lib/rom/mapper_compiler.rb +2 -1
- data/lib/rom/mapper_registry.rb +3 -3
- data/lib/rom/memory/dataset.rb +4 -3
- data/lib/rom/pipeline.rb +3 -1
- data/lib/rom/plugin.rb +3 -3
- data/lib/rom/plugin_registry.rb +1 -1
- data/lib/rom/plugins/command/schema.rb +2 -2
- data/lib/rom/plugins/relation/instrumentation.rb +1 -1
- data/lib/rom/plugins/relation/registry_reader.rb +4 -3
- data/lib/rom/plugins/schema/timestamps.rb +4 -6
- data/lib/rom/processor.rb +1 -1
- data/lib/rom/processor/transproc.rb +16 -19
- data/lib/rom/registry.rb +17 -12
- data/lib/rom/relation.rb +6 -6
- data/lib/rom/relation/class_interface.rb +9 -8
- data/lib/rom/relation/curried.rb +3 -2
- data/lib/rom/relation/loaded.rb +1 -0
- data/lib/rom/relation/materializable.rb +1 -0
- data/lib/rom/relation/name.rb +1 -1
- data/lib/rom/relation_registry.rb +1 -1
- data/lib/rom/schema.rb +22 -22
- data/lib/rom/schema/associations_dsl.rb +17 -17
- data/lib/rom/schema/dsl.rb +6 -6
- data/lib/rom/schema/inferrer.rb +2 -4
- data/lib/rom/setup.rb +2 -2
- data/lib/rom/setup/auto_registration.rb +1 -1
- data/lib/rom/setup/auto_registration_strategies/base.rb +1 -1
- data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +4 -4
- data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +1 -1
- data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +1 -1
- data/lib/rom/setup/finalize/finalize_commands.rb +7 -4
- data/lib/rom/setup/finalize/finalize_mappers.rb +9 -8
- data/lib/rom/setup/finalize/finalize_relations.rb +2 -2
- data/lib/rom/struct.rb +1 -1
- data/lib/rom/struct_compiler.rb +6 -5
- data/lib/rom/support/memoizable.rb +3 -2
- data/lib/rom/transaction.rb +1 -1
- data/lib/rom/transformer.rb +1 -0
- metadata +3 -3
data/lib/rom/relation.rb
CHANGED
@@ -156,7 +156,7 @@ module ROM
|
|
156
156
|
# @!attribute [r] output_schema
|
157
157
|
# @return [Object#[]] tuple processing function, uses schema or defaults to NOOP_OUTPUT_SCHEMA
|
158
158
|
# @api private
|
159
|
-
option :output_schema, default:
|
159
|
+
option :output_schema, default: lambda {
|
160
160
|
schema.any?(&:read?) ? schema.to_output_hash : NOOP_OUTPUT_SCHEMA
|
161
161
|
}
|
162
162
|
|
@@ -396,7 +396,7 @@ module ROM
|
|
396
396
|
#
|
397
397
|
# @api private
|
398
398
|
def schema?
|
399
|
-
!
|
399
|
+
!schema.empty?
|
400
400
|
end
|
401
401
|
|
402
402
|
# Return a new relation with provided dataset and additional options
|
@@ -417,7 +417,7 @@ module ROM
|
|
417
417
|
# @param [Hash] new_opts Additional options
|
418
418
|
#
|
419
419
|
# @api public
|
420
|
-
def new(dataset, new_opts
|
420
|
+
def new(dataset, **new_opts)
|
421
421
|
opts =
|
422
422
|
if new_opts.empty?
|
423
423
|
options
|
@@ -427,7 +427,7 @@ module ROM
|
|
427
427
|
options.merge(new_opts)
|
428
428
|
end
|
429
429
|
|
430
|
-
self.class.new(dataset, opts)
|
430
|
+
self.class.new(dataset, **opts)
|
431
431
|
end
|
432
432
|
|
433
433
|
undef_method :with
|
@@ -450,7 +450,7 @@ module ROM
|
|
450
450
|
opts
|
451
451
|
end
|
452
452
|
|
453
|
-
new(dataset, options
|
453
|
+
new(dataset, **options, **new_options)
|
454
454
|
end
|
455
455
|
|
456
456
|
# Return schema's association set (empty by default)
|
@@ -473,7 +473,7 @@ module ROM
|
|
473
473
|
|
474
474
|
# @api private
|
475
475
|
def attr_ast
|
476
|
-
schema.map
|
476
|
+
schema.map(&:to_read_ast)
|
477
477
|
end
|
478
478
|
|
479
479
|
# @api private
|
@@ -95,12 +95,12 @@ module ROM
|
|
95
95
|
if defined?(@schema) && !block && !infer
|
96
96
|
@schema
|
97
97
|
elsif block || infer
|
98
|
-
raise MissingSchemaClassError
|
98
|
+
raise MissingSchemaClassError, self unless schema_class
|
99
99
|
|
100
100
|
ds_name = dataset || schema_opts.fetch(:dataset, default_name.dataset)
|
101
101
|
relation = as || schema_opts.fetch(:relation, ds_name)
|
102
102
|
|
103
|
-
raise InvalidRelationName
|
103
|
+
raise InvalidRelationName, relation if invalid_relation_name?(relation)
|
104
104
|
|
105
105
|
@relation_name = Name[relation, ds_name]
|
106
106
|
|
@@ -133,7 +133,8 @@ module ROM
|
|
133
133
|
# @!attribute [r] relation_name
|
134
134
|
# @return [Name] Qualified relation name
|
135
135
|
def relation_name
|
136
|
-
raise MissingSchemaError
|
136
|
+
raise MissingSchemaError, self unless defined?(@relation_name)
|
137
|
+
|
137
138
|
@relation_name
|
138
139
|
end
|
139
140
|
|
@@ -188,7 +189,7 @@ module ROM
|
|
188
189
|
# @api public
|
189
190
|
def view(*args, &block)
|
190
191
|
if args.size == 1 && block.arity > 0
|
191
|
-
raise ArgumentError,
|
192
|
+
raise ArgumentError, 'schema attribute names must be provided as the second argument'
|
192
193
|
end
|
193
194
|
|
194
195
|
name, new_schema_fn, relation_block =
|
@@ -248,8 +249,8 @@ module ROM
|
|
248
249
|
# @option options [Symbol] :adapter (:default) first adapter to check for plugin
|
249
250
|
#
|
250
251
|
# @api public
|
251
|
-
def use(plugin, options
|
252
|
-
ROM.plugin_registry[:relation].fetch(plugin, adapter).apply_to(self, options)
|
252
|
+
def use(plugin, **options)
|
253
|
+
ROM.plugin_registry[:relation].fetch(plugin, adapter).apply_to(self, **options)
|
253
254
|
end
|
254
255
|
|
255
256
|
# Build default mapper registry
|
@@ -261,13 +262,13 @@ module ROM
|
|
261
262
|
adapter_ns = ROM.adapters[adapter]
|
262
263
|
|
263
264
|
compiler =
|
264
|
-
if adapter_ns
|
265
|
+
if adapter_ns&.const_defined?(:MapperCompiler)
|
265
266
|
adapter_ns.const_get(:MapperCompiler)
|
266
267
|
else
|
267
268
|
MapperCompiler
|
268
269
|
end
|
269
270
|
|
270
|
-
MapperRegistry.new({},
|
271
|
+
MapperRegistry.new({}, compiler: compiler.new(**opts), **opts)
|
271
272
|
end
|
272
273
|
|
273
274
|
# @api private
|
data/lib/rom/relation/curried.rb
CHANGED
@@ -97,8 +97,8 @@ module ROM
|
|
97
97
|
private
|
98
98
|
|
99
99
|
# @api private
|
100
|
-
def __new__(relation, new_opts
|
101
|
-
self.class.new(relation,
|
100
|
+
def __new__(relation, **new_opts)
|
101
|
+
self.class.new(relation, **options, **new_opts)
|
102
102
|
end
|
103
103
|
|
104
104
|
# @api private
|
@@ -122,6 +122,7 @@ module ROM
|
|
122
122
|
super
|
123
123
|
end
|
124
124
|
end
|
125
|
+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
125
126
|
end
|
126
127
|
end
|
127
128
|
end
|
data/lib/rom/relation/loaded.rb
CHANGED
data/lib/rom/relation/name.rb
CHANGED
data/lib/rom/schema.rb
CHANGED
@@ -60,7 +60,7 @@ module ROM
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
EMPTY_ASSOCIATION_SET = AssociationSet.
|
63
|
+
EMPTY_ASSOCIATION_SET = AssociationSet.build(EMPTY_HASH).freeze
|
64
64
|
|
65
65
|
DEFAULT_INFERRER = Inferrer.new(enabled: false).freeze
|
66
66
|
|
@@ -73,9 +73,9 @@ module ROM
|
|
73
73
|
k.required(false)
|
74
74
|
end
|
75
75
|
|
76
|
-
HASH_SCHEMA = Types::Coercible::Hash
|
77
|
-
|
78
|
-
|
76
|
+
HASH_SCHEMA = Types::Coercible::Hash
|
77
|
+
.schema(EMPTY_HASH)
|
78
|
+
.with_type_transform(type_transformation)
|
79
79
|
|
80
80
|
extend Initializer
|
81
81
|
|
@@ -147,7 +147,7 @@ module ROM
|
|
147
147
|
# @return [Hash] A hash with `:type` and `:options` keys.
|
148
148
|
#
|
149
149
|
# @api private
|
150
|
-
def self.build_attribute_info(type, options)
|
150
|
+
def self.build_attribute_info(type, **options)
|
151
151
|
{
|
152
152
|
type: type,
|
153
153
|
options: options
|
@@ -157,7 +157,7 @@ module ROM
|
|
157
157
|
# @api private
|
158
158
|
def self.attributes(attributes, attr_class)
|
159
159
|
attributes.map do |attr|
|
160
|
-
attr_class.new(attr[:type], attr.fetch(:options))
|
160
|
+
attr_class.new(attr[:type], **attr.fetch(:options))
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
@@ -167,6 +167,7 @@ module ROM
|
|
167
167
|
|
168
168
|
yield(self) if block_given?
|
169
169
|
end
|
170
|
+
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
|
170
171
|
|
171
172
|
# Abstract method for creating a new relation based on schema definition
|
172
173
|
#
|
@@ -200,7 +201,7 @@ module ROM
|
|
200
201
|
#
|
201
202
|
# @api public
|
202
203
|
def empty?
|
203
|
-
attributes.
|
204
|
+
attributes.empty?
|
204
205
|
end
|
205
206
|
|
206
207
|
# Coerce schema into a <AttributeName=>Attribute> Hash
|
@@ -228,9 +229,7 @@ module ROM
|
|
228
229
|
source_index[src][key]
|
229
230
|
end
|
230
231
|
|
231
|
-
unless attr
|
232
|
-
raise(KeyError, "#{key.inspect} attribute doesn't exist in #{src} schema")
|
233
|
-
end
|
232
|
+
raise(KeyError, "#{key.inspect} attribute doesn't exist in #{src} schema") unless attr
|
234
233
|
|
235
234
|
attr
|
236
235
|
end
|
@@ -362,7 +361,7 @@ module ROM
|
|
362
361
|
#
|
363
362
|
# @api public
|
364
363
|
def key?(name)
|
365
|
-
!
|
364
|
+
!attributes.detect { |attr| attr.name == name }.nil?
|
366
365
|
end
|
367
366
|
|
368
367
|
# Return if a schema is canonical
|
@@ -371,7 +370,7 @@ module ROM
|
|
371
370
|
#
|
372
371
|
# @api public
|
373
372
|
def canonical?
|
374
|
-
|
373
|
+
equal?(canonical)
|
375
374
|
end
|
376
375
|
|
377
376
|
# Finalize a schema
|
@@ -379,8 +378,9 @@ module ROM
|
|
379
378
|
# @return [self]
|
380
379
|
#
|
381
380
|
# @api private
|
382
|
-
def finalize!(**
|
381
|
+
def finalize!(**_opts)
|
383
382
|
return self if frozen?
|
383
|
+
|
384
384
|
freeze
|
385
385
|
end
|
386
386
|
|
@@ -452,7 +452,7 @@ module ROM
|
|
452
452
|
|
453
453
|
# @api private
|
454
454
|
def set!(key, value)
|
455
|
-
instance_variable_set("@#{
|
455
|
+
instance_variable_set("@#{key}", value)
|
456
456
|
options[key] = value
|
457
457
|
end
|
458
458
|
|
@@ -470,10 +470,10 @@ module ROM
|
|
470
470
|
|
471
471
|
# @api private
|
472
472
|
def source_index
|
473
|
-
select(&:source)
|
474
|
-
group_by(&:source)
|
475
|
-
map { |src, grp| [src.to_sym, grp.map { |attr| [attr.name, attr] }.to_h] }
|
476
|
-
to_h
|
473
|
+
select(&:source)
|
474
|
+
.group_by(&:source)
|
475
|
+
.map { |src, grp| [src.to_sym, grp.map { |attr| [attr.name, attr] }.to_h] }
|
476
|
+
.to_h
|
477
477
|
end
|
478
478
|
|
479
479
|
# @api private
|
@@ -483,10 +483,10 @@ module ROM
|
|
483
483
|
|
484
484
|
# @api private
|
485
485
|
def initialize_primary_key_names
|
486
|
-
if primary_key.
|
487
|
-
|
488
|
-
|
489
|
-
|
486
|
+
return if primary_key.empty?
|
487
|
+
|
488
|
+
set!(:primary_key_name, primary_key[0].name)
|
489
|
+
set!(:primary_key_names, primary_key.map(&:name))
|
490
490
|
end
|
491
491
|
|
492
492
|
memoize :count_index, :name_index, :source_index, :to_ast, :to_input_hash, :to_output_hash
|
@@ -59,11 +59,11 @@ module ROM
|
|
59
59
|
# @see #many_to_many
|
60
60
|
#
|
61
61
|
# @api public
|
62
|
-
def one_to_many(target, options
|
62
|
+
def one_to_many(target, **options)
|
63
63
|
if options[:through]
|
64
|
-
many_to_many(target, options)
|
64
|
+
many_to_many(target, **options)
|
65
65
|
else
|
66
|
-
add(::ROM::Associations::Definitions::OneToMany.new(source, target, options))
|
66
|
+
add(::ROM::Associations::Definitions::OneToMany.new(source, target, **options))
|
67
67
|
end
|
68
68
|
end
|
69
69
|
alias_method :has_many, :one_to_many
|
@@ -84,11 +84,11 @@ module ROM
|
|
84
84
|
# @see #belongs_to
|
85
85
|
#
|
86
86
|
# @api public
|
87
|
-
def one_to_one(target, options
|
87
|
+
def one_to_one(target, **options)
|
88
88
|
if options[:through]
|
89
|
-
one_to_one_through(target, options)
|
89
|
+
one_to_one_through(target, **options)
|
90
90
|
else
|
91
|
-
add(::ROM::Associations::Definitions::OneToOne.new(source, target, options))
|
91
|
+
add(::ROM::Associations::Definitions::OneToOne.new(source, target, **options))
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -100,8 +100,8 @@ module ROM
|
|
100
100
|
# @return [Associations::OneToOneThrough]
|
101
101
|
#
|
102
102
|
# @api public
|
103
|
-
def one_to_one_through(target, options
|
104
|
-
add(::ROM::Associations::Definitions::OneToOneThrough.new(source, target, options))
|
103
|
+
def one_to_one_through(target, **options)
|
104
|
+
add(::ROM::Associations::Definitions::OneToOneThrough.new(source, target, **options))
|
105
105
|
end
|
106
106
|
|
107
107
|
# Establish a many-to-many association
|
@@ -117,8 +117,8 @@ module ROM
|
|
117
117
|
# @see #one_to_many
|
118
118
|
#
|
119
119
|
# @api public
|
120
|
-
def many_to_many(target, options
|
121
|
-
add(::ROM::Associations::Definitions::ManyToMany.new(source, target, options))
|
120
|
+
def many_to_many(target, **options)
|
121
|
+
add(::ROM::Associations::Definitions::ManyToMany.new(source, target, **options))
|
122
122
|
end
|
123
123
|
|
124
124
|
# Establish a many-to-one association
|
@@ -134,8 +134,8 @@ module ROM
|
|
134
134
|
# @see #one_to_many
|
135
135
|
#
|
136
136
|
# @api public
|
137
|
-
def many_to_one(target, options
|
138
|
-
add(::ROM::Associations::Definitions::ManyToOne.new(source, target, options))
|
137
|
+
def many_to_one(target, **options)
|
138
|
+
add(::ROM::Associations::Definitions::ManyToOne.new(source, target, **options))
|
139
139
|
end
|
140
140
|
|
141
141
|
# Shortcut for many_to_one which sets alias automatically
|
@@ -151,8 +151,8 @@ module ROM
|
|
151
151
|
# @return [Associations::ManyToOne]
|
152
152
|
#
|
153
153
|
# @api public
|
154
|
-
def belongs_to(target, options
|
155
|
-
many_to_one(dataset_name(target),
|
154
|
+
def belongs_to(target, **options)
|
155
|
+
many_to_one(dataset_name(target), as: target, **options)
|
156
156
|
end
|
157
157
|
|
158
158
|
# Shortcut for one_to_one which sets alias automatically
|
@@ -168,8 +168,8 @@ module ROM
|
|
168
168
|
# @return [Associations::OneToOne]
|
169
169
|
#
|
170
170
|
# @api public
|
171
|
-
def has_one(target, options
|
172
|
-
one_to_one(dataset_name(target),
|
171
|
+
def has_one(target, **options)
|
172
|
+
one_to_one(dataset_name(target), as: target, **options)
|
173
173
|
end
|
174
174
|
|
175
175
|
# Return an association set for a schema
|
@@ -178,7 +178,7 @@ module ROM
|
|
178
178
|
#
|
179
179
|
# @api private
|
180
180
|
def call
|
181
|
-
AssociationSet[source.relation].
|
181
|
+
AssociationSet[source.relation].build(registry)
|
182
182
|
end
|
183
183
|
|
184
184
|
private
|
data/lib/rom/schema/dsl.rb
CHANGED
@@ -12,7 +12,7 @@ module ROM
|
|
12
12
|
#
|
13
13
|
# @api public
|
14
14
|
class DSL < BasicObject
|
15
|
-
KERNEL_METHODS = %i
|
15
|
+
KERNEL_METHODS = %i[extend method].freeze
|
16
16
|
KERNEL_METHODS.each { |m| define_method(m, ::Kernel.instance_method(m)) }
|
17
17
|
|
18
18
|
extend Initializer
|
@@ -65,6 +65,7 @@ module ROM
|
|
65
65
|
|
66
66
|
@definition = block
|
67
67
|
end
|
68
|
+
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
|
68
69
|
|
69
70
|
# Defines a relation attribute with its type and options.
|
70
71
|
#
|
@@ -78,7 +79,7 @@ module ROM
|
|
78
79
|
def attribute(name, type_or_options, options = EMPTY_HASH)
|
79
80
|
if attributes.key?(name)
|
80
81
|
::Kernel.raise ::ROM::AttributeAlreadyDefinedError,
|
81
|
-
"Attribute #{
|
82
|
+
"Attribute #{name.inspect} already defined"
|
82
83
|
end
|
83
84
|
|
84
85
|
attributes[name] = build_attribute_info(name, type_or_options, options)
|
@@ -132,8 +133,7 @@ module ROM
|
|
132
133
|
[build_type(type_or_options, options), options]
|
133
134
|
end
|
134
135
|
Schema.build_attribute_info(
|
135
|
-
type,
|
136
|
-
options.merge(name: name)
|
136
|
+
type, **options, name: name
|
137
137
|
)
|
138
138
|
end
|
139
139
|
|
@@ -185,9 +185,9 @@ module ROM
|
|
185
185
|
instance_exec(&block) if block
|
186
186
|
instance_exec(&definition) if definition
|
187
187
|
|
188
|
-
schema_class.define(relation, opts) do |schema|
|
188
|
+
schema_class.define(relation, **opts) do |schema|
|
189
189
|
plugins.values.each do |plugin, options|
|
190
|
-
plugin.apply_to(schema, options)
|
190
|
+
plugin.apply_to(schema, **options)
|
191
191
|
end
|
192
192
|
end
|
193
193
|
end
|
data/lib/rom/schema/inferrer.rb
CHANGED
@@ -76,9 +76,7 @@ module ROM
|
|
76
76
|
def check_all_attributes_defined(schema, all_known, not_inferred)
|
77
77
|
not_defined = not_inferred - all_known.map(&:name)
|
78
78
|
|
79
|
-
|
80
|
-
raise MissingAttributesError.new(schema.name, not_defined)
|
81
|
-
end
|
79
|
+
raise MissingAttributesError.new(schema.name, not_defined) unless not_defined.empty?
|
82
80
|
end
|
83
81
|
|
84
82
|
# @api private
|
@@ -91,7 +89,7 @@ module ROM
|
|
91
89
|
attrs << if attr.type.nil?
|
92
90
|
attr.class.new(
|
93
91
|
type_lookup.(inferred, attr.name),
|
94
|
-
attr.options
|
92
|
+
**attr.options
|
95
93
|
)
|
96
94
|
else
|
97
95
|
attr
|