rom-core 4.2.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +0 -2
- data/lib/rom-core.rb +2 -0
- data/lib/rom/array_dataset.rb +2 -0
- data/lib/rom/association_set.rb +2 -0
- data/lib/rom/associations/abstract.rb +2 -0
- data/lib/rom/associations/definitions.rb +2 -0
- data/lib/rom/associations/definitions/abstract.rb +2 -0
- data/lib/rom/associations/definitions/many_to_many.rb +2 -0
- data/lib/rom/associations/definitions/many_to_one.rb +2 -0
- data/lib/rom/associations/definitions/one_to_many.rb +2 -0
- data/lib/rom/associations/definitions/one_to_one.rb +2 -0
- data/lib/rom/associations/definitions/one_to_one_through.rb +2 -0
- data/lib/rom/associations/many_to_many.rb +2 -0
- data/lib/rom/associations/many_to_one.rb +2 -0
- data/lib/rom/associations/one_to_many.rb +2 -0
- data/lib/rom/associations/one_to_one.rb +2 -0
- data/lib/rom/associations/one_to_one_through.rb +2 -0
- data/lib/rom/associations/through_identifier.rb +2 -0
- data/lib/rom/attribute.rb +58 -72
- data/lib/rom/auto_curry.rb +2 -0
- data/lib/rom/cache.rb +2 -0
- data/lib/rom/command.rb +7 -5
- data/lib/rom/command_compiler.rb +2 -0
- data/lib/rom/command_proxy.rb +2 -0
- data/lib/rom/command_registry.rb +13 -7
- data/lib/rom/commands.rb +2 -0
- data/lib/rom/commands/class_interface.rb +4 -2
- data/lib/rom/commands/composite.rb +2 -0
- data/lib/rom/commands/create.rb +2 -0
- data/lib/rom/commands/delete.rb +2 -0
- data/lib/rom/commands/graph.rb +2 -0
- data/lib/rom/commands/graph/class_interface.rb +2 -0
- data/lib/rom/commands/graph/input_evaluator.rb +2 -0
- data/lib/rom/commands/lazy.rb +2 -0
- data/lib/rom/commands/lazy/create.rb +2 -0
- data/lib/rom/commands/lazy/delete.rb +2 -0
- data/lib/rom/commands/lazy/update.rb +2 -0
- data/lib/rom/commands/update.rb +2 -0
- data/lib/rom/configuration.rb +2 -0
- data/lib/rom/configuration_dsl.rb +2 -0
- data/lib/rom/configuration_dsl/command.rb +2 -0
- data/lib/rom/configuration_dsl/command_dsl.rb +2 -0
- data/lib/rom/configuration_dsl/relation.rb +2 -0
- data/lib/rom/configuration_plugin.rb +2 -0
- data/lib/rom/constants.rb +3 -0
- data/lib/rom/container.rb +2 -0
- data/lib/rom/core.rb +4 -1
- data/lib/rom/create_container.rb +2 -0
- data/lib/rom/data_proxy.rb +2 -0
- data/lib/rom/enumerable_dataset.rb +2 -0
- data/lib/rom/environment.rb +2 -0
- data/lib/rom/gateway.rb +2 -0
- data/lib/rom/global.rb +2 -0
- data/lib/rom/global/plugin_dsl.rb +2 -0
- data/lib/rom/header.rb +198 -0
- data/lib/rom/header/attribute.rb +192 -0
- data/lib/rom/initializer.rb +2 -0
- data/lib/rom/lint/enumerable_dataset.rb +2 -0
- data/lib/rom/lint/gateway.rb +2 -0
- data/lib/rom/lint/linter.rb +2 -0
- data/lib/rom/lint/spec.rb +2 -0
- data/lib/rom/lint/test.rb +2 -0
- data/lib/rom/mapper.rb +100 -0
- data/lib/rom/mapper/attribute_dsl.rb +480 -0
- data/lib/rom/mapper/builder.rb +39 -0
- data/lib/rom/mapper/configuration_plugin.rb +28 -0
- data/lib/rom/mapper/dsl.rb +123 -0
- data/lib/rom/mapper/mapper_dsl.rb +45 -0
- data/lib/rom/mapper/model_dsl.rb +60 -0
- data/lib/rom/mapper_compiler.rb +84 -0
- data/lib/rom/mapper_registry.rb +2 -0
- data/lib/rom/memory.rb +2 -0
- data/lib/rom/memory/associations.rb +2 -0
- data/lib/rom/memory/associations/many_to_many.rb +2 -0
- data/lib/rom/memory/associations/many_to_one.rb +2 -0
- data/lib/rom/memory/associations/one_to_many.rb +2 -0
- data/lib/rom/memory/associations/one_to_one.rb +2 -0
- data/lib/rom/memory/commands.rb +2 -0
- data/lib/rom/memory/dataset.rb +2 -0
- data/lib/rom/memory/gateway.rb +2 -0
- data/lib/rom/memory/mapper_compiler.rb +2 -0
- data/lib/rom/memory/relation.rb +2 -0
- data/lib/rom/memory/schema.rb +2 -0
- data/lib/rom/memory/storage.rb +2 -0
- data/lib/rom/memory/types.rb +2 -0
- data/lib/rom/model_builder.rb +103 -0
- data/lib/rom/open_struct.rb +37 -0
- data/lib/rom/pipeline.rb +2 -0
- data/lib/rom/plugin.rb +2 -0
- data/lib/rom/plugin_base.rb +2 -0
- data/lib/rom/plugin_registry.rb +2 -0
- data/lib/rom/plugins/command/schema.rb +2 -0
- data/lib/rom/plugins/command/timestamps.rb +2 -0
- data/lib/rom/plugins/relation/instrumentation.rb +2 -0
- data/lib/rom/plugins/relation/registry_reader.rb +2 -0
- data/lib/rom/plugins/schema/timestamps.rb +8 -1
- data/lib/rom/processor.rb +30 -0
- data/lib/rom/processor/transproc.rb +417 -0
- data/lib/rom/registry.rb +2 -0
- data/lib/rom/relation.rb +4 -2
- data/lib/rom/relation/class_interface.rb +2 -0
- data/lib/rom/relation/combined.rb +2 -0
- data/lib/rom/relation/commands.rb +2 -0
- data/lib/rom/relation/composite.rb +2 -0
- data/lib/rom/relation/curried.rb +3 -1
- data/lib/rom/relation/graph.rb +2 -0
- data/lib/rom/relation/loaded.rb +2 -0
- data/lib/rom/relation/materializable.rb +2 -0
- data/lib/rom/relation/name.rb +2 -0
- data/lib/rom/relation/view_dsl.rb +2 -0
- data/lib/rom/relation/wrap.rb +2 -0
- data/lib/rom/relation_registry.rb +2 -0
- data/lib/rom/schema.rb +39 -6
- data/lib/rom/schema/associations_dsl.rb +5 -3
- data/lib/rom/schema/dsl.rb +41 -11
- data/lib/rom/schema/inferrer.rb +21 -3
- data/lib/rom/schema_plugin.rb +2 -0
- data/lib/rom/setup.rb +2 -0
- data/lib/rom/setup/auto_registration.rb +2 -0
- data/lib/rom/setup/auto_registration_strategies/base.rb +3 -1
- data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +2 -0
- data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +2 -0
- data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +2 -0
- data/lib/rom/setup/finalize.rb +2 -0
- data/lib/rom/setup/finalize/finalize_commands.rb +2 -0
- data/lib/rom/setup/finalize/finalize_mappers.rb +2 -0
- data/lib/rom/setup/finalize/finalize_relations.rb +2 -0
- data/lib/rom/struct.rb +108 -0
- data/lib/rom/struct_compiler.rb +110 -0
- data/lib/rom/support/configurable.rb +2 -0
- data/lib/rom/support/inflector.rb +2 -0
- data/lib/rom/support/memoizable.rb +2 -0
- data/lib/rom/support/notifications.rb +2 -0
- data/lib/rom/transaction.rb +2 -0
- data/lib/rom/transformer.rb +34 -0
- data/lib/rom/types.rb +10 -3
- data/lib/rom/version.rb +3 -1
- metadata +37 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3f8bcda8c133820affac0b652c40ad16434c3c5ceaa3d8ceb34195562f8c4a9
|
4
|
+
data.tar.gz: 48611a1d36d140df12fd1ef93860f7349f95e81dc2b4d539da5dad979bf94565
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a97ea813e0ed8ede39740911f2ee45a3679cdc8b50c5461ac0e07f171567f52f6ea77e18e424fb408e82ac67f289ccc98a89b142ade78ae66cc62f3baf4deb83
|
7
|
+
data.tar.gz: 06ba213179501490959c77c929fe399dda690baa915b105def02a4179b20e6e819fb5d84dfacb685792ff8605cc8ab407021bc75342dcd92ed8ade1d7cb8473a
|
data/README.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
[gem]: https://rubygems.org/gems/rom-core
|
2
|
-
[gemnasium]: https://gemnasium.com/rom-rb/rom-core
|
3
2
|
|
4
3
|
# rom-core [](https://gitter.im/rom-rb/chat)
|
5
4
|
|
6
5
|
[][gem]
|
7
|
-
[][gemnasium]
|
8
6
|
|
9
7
|
Core API for rom-rb and its adapters and extensions.
|
10
8
|
|
data/lib/rom-core.rb
CHANGED
data/lib/rom/array_dataset.rb
CHANGED
data/lib/rom/association_set.rb
CHANGED
data/lib/rom/attribute.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/equalizer'
|
2
4
|
|
3
5
|
require 'rom/initializer'
|
4
6
|
require 'rom/support/memoizable'
|
7
|
+
require 'rom/types'
|
5
8
|
|
6
9
|
module ROM
|
7
10
|
# Schema attributes provide meta information about types and an API
|
@@ -20,12 +23,42 @@ module ROM
|
|
20
23
|
extend Initializer
|
21
24
|
|
22
25
|
# @!attribute [r] type
|
23
|
-
# @return [Dry::Types::
|
26
|
+
# @return [Dry::Types::Nominal, Dry::Types::Sum, Dry::Types::Constrained] The attribute's type object
|
24
27
|
param :type
|
25
28
|
|
29
|
+
# @!attribute [r] name
|
30
|
+
#
|
31
|
+
# Return the canonical name of this attribute name
|
32
|
+
#
|
33
|
+
# This *always* returns the name that is used in the datastore, even when
|
34
|
+
# an attribute is aliased
|
35
|
+
#
|
36
|
+
# @example
|
37
|
+
# class Users < ROM::Relation[:memory]
|
38
|
+
# schema do
|
39
|
+
# attribute :user_id, Types::Integer, alias: :id
|
40
|
+
# attribute :email, Types::String
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# users[:user_id].name
|
45
|
+
# # => :user_id
|
46
|
+
#
|
47
|
+
# users[:email].name
|
48
|
+
# # => :email
|
49
|
+
#
|
50
|
+
# @return [Symbol]
|
51
|
+
#
|
52
|
+
# @api public
|
53
|
+
option :name, optional: true, type: Types::Strict::Symbol
|
54
|
+
|
55
|
+
# @!attribute [r] type
|
56
|
+
# @return [Symbol, nil] Alias to use instead of attribute name
|
57
|
+
option :alias, optional: true, type: Types::Strict::Symbol.optional
|
58
|
+
|
26
59
|
# @api private
|
27
|
-
def [](
|
28
|
-
type[
|
60
|
+
def [](value = Undefined)
|
61
|
+
type[value]
|
29
62
|
end
|
30
63
|
|
31
64
|
# Return true if this attribute type is a primary key
|
@@ -33,7 +66,7 @@ module ROM
|
|
33
66
|
# @example
|
34
67
|
# class Users < ROM::Relation[:memory]
|
35
68
|
# schema do
|
36
|
-
# attribute :id, Types::
|
69
|
+
# attribute :id, Types::Integer
|
37
70
|
# attribute :name, Types::String
|
38
71
|
#
|
39
72
|
# primary_key :id
|
@@ -58,7 +91,7 @@ module ROM
|
|
58
91
|
# @example
|
59
92
|
# class Tasks < ROM::Relation[:memory]
|
60
93
|
# schema do
|
61
|
-
# attribute :id, Types::
|
94
|
+
# attribute :id, Types::Integer
|
62
95
|
# attribute :user_id, Types.ForeignKey(:users)
|
63
96
|
# end
|
64
97
|
# end
|
@@ -76,12 +109,12 @@ module ROM
|
|
76
109
|
meta[:foreign_key].equal?(true)
|
77
110
|
end
|
78
111
|
|
79
|
-
# Return true if this attribute
|
112
|
+
# Return true if this attribute has a configured alias
|
80
113
|
#
|
81
114
|
# @example
|
82
115
|
# class Tasks < ROM::Relation[:memory]
|
83
116
|
# schema do
|
84
|
-
# attribute :user_id, Types::
|
117
|
+
# attribute :user_id, Types::Integer, alias: :id
|
85
118
|
# attribute :name, Types::String
|
86
119
|
# end
|
87
120
|
# end
|
@@ -96,7 +129,7 @@ module ROM
|
|
96
129
|
#
|
97
130
|
# @api public
|
98
131
|
def aliased?
|
99
|
-
!
|
132
|
+
!self.alias.nil?
|
100
133
|
end
|
101
134
|
|
102
135
|
# Return source relation of this attribute type
|
@@ -104,7 +137,7 @@ module ROM
|
|
104
137
|
# @example
|
105
138
|
# class Tasks < ROM::Relation[:memory]
|
106
139
|
# schema do
|
107
|
-
# attribute :id, Types::
|
140
|
+
# attribute :id, Types::Integer
|
108
141
|
# attribute :user_id, Types.ForeignKey(:users)
|
109
142
|
# end
|
110
143
|
# end
|
@@ -127,7 +160,7 @@ module ROM
|
|
127
160
|
# @example
|
128
161
|
# class Tasks < ROM::Relation[:memory]
|
129
162
|
# schema do
|
130
|
-
# attribute :id, Types::
|
163
|
+
# attribute :id, Types::Integer
|
131
164
|
# attribute :user_id, Types.ForeignKey(:users)
|
132
165
|
# end
|
133
166
|
# end
|
@@ -145,32 +178,6 @@ module ROM
|
|
145
178
|
meta[:target]
|
146
179
|
end
|
147
180
|
|
148
|
-
# Return the canonical name of this attribute name
|
149
|
-
#
|
150
|
-
# This *always* returns the name that is used in the datastore, even when
|
151
|
-
# an attribute is aliased
|
152
|
-
#
|
153
|
-
# @example
|
154
|
-
# class Tasks < ROM::Relation[:memory]
|
155
|
-
# schema do
|
156
|
-
# attribute :user_id, Types::Int.meta(alias: :id)
|
157
|
-
# attribute :name, Types::String
|
158
|
-
# end
|
159
|
-
# end
|
160
|
-
#
|
161
|
-
# Users.schema[:id].name
|
162
|
-
# # => :id
|
163
|
-
#
|
164
|
-
# Users.schema[:user_id].name
|
165
|
-
# # => :user_id
|
166
|
-
#
|
167
|
-
# @return [Symbol]
|
168
|
-
#
|
169
|
-
# @api public
|
170
|
-
def name
|
171
|
-
meta[:name]
|
172
|
-
end
|
173
|
-
|
174
181
|
# Return tuple key
|
175
182
|
#
|
176
183
|
# When schemas are projected with aliased attributes, we need a simple access to tuple keys
|
@@ -178,7 +185,7 @@ module ROM
|
|
178
185
|
# @example
|
179
186
|
# class Tasks < ROM::Relation[:memory]
|
180
187
|
# schema do
|
181
|
-
# attribute :user_id, Types::
|
188
|
+
# attribute :user_id, Types::Integer, alias: :id
|
182
189
|
# attribute :name, Types::String
|
183
190
|
# end
|
184
191
|
# end
|
@@ -193,30 +200,7 @@ module ROM
|
|
193
200
|
#
|
194
201
|
# @api public
|
195
202
|
def key
|
196
|
-
|
197
|
-
end
|
198
|
-
|
199
|
-
# Return attribute's alias
|
200
|
-
#
|
201
|
-
# @example
|
202
|
-
# class Tasks < ROM::Relation[:memory]
|
203
|
-
# schema do
|
204
|
-
# attribute :user_id, Types::Int.meta(alias: :id)
|
205
|
-
# attribute :name, Types::String
|
206
|
-
# end
|
207
|
-
# end
|
208
|
-
#
|
209
|
-
# Users.schema[:user_id].alias
|
210
|
-
# # => :user_id
|
211
|
-
#
|
212
|
-
# Users.schema[:name].alias
|
213
|
-
# # => nil
|
214
|
-
#
|
215
|
-
# @return [NilClass,Symbol]
|
216
|
-
#
|
217
|
-
# @api public
|
218
|
-
def alias
|
219
|
-
meta[:alias]
|
203
|
+
self.alias || name
|
220
204
|
end
|
221
205
|
|
222
206
|
# Return new attribute type with provided alias
|
@@ -224,7 +208,7 @@ module ROM
|
|
224
208
|
# @example
|
225
209
|
# class Tasks < ROM::Relation[:memory]
|
226
210
|
# schema do
|
227
|
-
# attribute :user_id, Types::
|
211
|
+
# attribute :user_id, Types::Integer
|
228
212
|
# attribute :name, Types::String
|
229
213
|
# end
|
230
214
|
# end
|
@@ -246,7 +230,7 @@ module ROM
|
|
246
230
|
#
|
247
231
|
# @api public
|
248
232
|
def aliased(name)
|
249
|
-
|
233
|
+
with(alias: name)
|
250
234
|
end
|
251
235
|
alias_method :as, :aliased
|
252
236
|
|
@@ -255,7 +239,7 @@ module ROM
|
|
255
239
|
# @example
|
256
240
|
# class Users < ROM::Relation[:memory]
|
257
241
|
# schema do
|
258
|
-
# attribute :id, Types::
|
242
|
+
# attribute :id, Types::Integer
|
259
243
|
# attribute :name, Types::String
|
260
244
|
# end
|
261
245
|
# end
|
@@ -318,7 +302,7 @@ module ROM
|
|
318
302
|
# @api public
|
319
303
|
def meta(opts = nil)
|
320
304
|
if opts
|
321
|
-
self.class.new(type.meta(opts))
|
305
|
+
self.class.new(type.meta(opts), options)
|
322
306
|
else
|
323
307
|
type.meta
|
324
308
|
end
|
@@ -330,7 +314,9 @@ module ROM
|
|
330
314
|
#
|
331
315
|
# @api public
|
332
316
|
def inspect
|
333
|
-
|
317
|
+
opts = options.reject { |k| %i[type name].include?(k) }
|
318
|
+
meta_and_opts = meta.merge(opts).map { |k, v| "#{k}=#{v.inspect}" }
|
319
|
+
%(#<#{self.class}[#{type.name}] name=#{name.inspect} #{meta_and_opts.join(' ')}>)
|
334
320
|
end
|
335
321
|
alias_method :pretty_inspect, :inspect
|
336
322
|
|
@@ -394,7 +380,7 @@ module ROM
|
|
394
380
|
#
|
395
381
|
# @api public
|
396
382
|
def to_ast
|
397
|
-
[:attribute, [name, type.to_ast(meta: false),
|
383
|
+
[:attribute, [name, type.to_ast(meta: false), meta_options_ast]]
|
398
384
|
end
|
399
385
|
|
400
386
|
# Return AST for the read type
|
@@ -403,18 +389,18 @@ module ROM
|
|
403
389
|
#
|
404
390
|
# @api public
|
405
391
|
def to_read_ast
|
406
|
-
[:attribute, [name, to_read_type.to_ast(meta: false),
|
392
|
+
[:attribute, [name, to_read_type.to_ast(meta: false), meta_options_ast]]
|
407
393
|
end
|
408
394
|
|
409
395
|
# @api private
|
410
|
-
def
|
411
|
-
|
412
|
-
ast = meta.select { |k, _|
|
396
|
+
def meta_options_ast
|
397
|
+
keys = %i[wrapped primary_key alias]
|
398
|
+
ast = meta.merge(options).select { |k, _| keys.include?(k) }
|
413
399
|
ast[:source] = source.to_sym if source
|
414
400
|
ast
|
415
401
|
end
|
416
402
|
|
417
|
-
memoize :to_ast, :to_read_ast, :
|
403
|
+
memoize :to_ast, :to_read_ast, :meta_options_ast
|
418
404
|
|
419
405
|
private
|
420
406
|
|
data/lib/rom/auto_curry.rb
CHANGED
data/lib/rom/cache.rb
CHANGED
data/lib/rom/command.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/core/deprecations'
|
2
4
|
require 'dry/core/class_attributes'
|
3
5
|
|
@@ -85,7 +87,7 @@ module ROM
|
|
85
87
|
# @api public
|
86
88
|
defines :relation
|
87
89
|
|
88
|
-
# @!method self.
|
90
|
+
# @!method self.result
|
89
91
|
# Get or set result type
|
90
92
|
#
|
91
93
|
# @overload result
|
@@ -101,7 +103,7 @@ module ROM
|
|
101
103
|
#
|
102
104
|
# @return [Symbol]
|
103
105
|
#
|
104
|
-
# @overload
|
106
|
+
# @overload result(identifier)
|
105
107
|
# Set result type
|
106
108
|
#
|
107
109
|
# @example
|
@@ -112,7 +114,7 @@ module ROM
|
|
112
114
|
# @api public
|
113
115
|
defines :result
|
114
116
|
|
115
|
-
# @!method self.
|
117
|
+
# @!method self.input
|
116
118
|
# Get or set input processing function. This is typically set during setup
|
117
119
|
# to relation's input_schema
|
118
120
|
#
|
@@ -314,7 +316,7 @@ module ROM
|
|
314
316
|
if curry_args.empty? && args.first.is_a?(Graph::InputEvaluator)
|
315
317
|
Lazy[self].new(self, *args)
|
316
318
|
else
|
317
|
-
self.class.build(relation, **options, curry_args: args)
|
319
|
+
self.class.build(relation, { **options, curry_args: args })
|
318
320
|
end
|
319
321
|
end
|
320
322
|
|
@@ -386,7 +388,7 @@ module ROM
|
|
386
388
|
#
|
387
389
|
# @api public
|
388
390
|
def new(new_relation)
|
389
|
-
self.class.build(new_relation, **options, source: relation)
|
391
|
+
self.class.build(new_relation, {**options, source: relation})
|
390
392
|
end
|
391
393
|
|
392
394
|
# Check if this command has any hooks
|