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
data/lib/rom/registry.rb
CHANGED
data/lib/rom/relation.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/core/class_attributes'
|
2
4
|
|
3
5
|
require 'rom/struct'
|
@@ -279,7 +281,7 @@ module ROM
|
|
279
281
|
|
280
282
|
# Create a graph node for a given association identifier
|
281
283
|
#
|
282
|
-
# @param [Symbol, Relation::Name]
|
284
|
+
# @param [Symbol, Relation::Name] name
|
283
285
|
#
|
284
286
|
# @return [Relation]
|
285
287
|
#
|
@@ -292,7 +294,7 @@ module ROM
|
|
292
294
|
|
293
295
|
# Return a graph node prepared by the given association
|
294
296
|
#
|
295
|
-
# @param [Association] An association object
|
297
|
+
# @param [Association] assoc An association object
|
296
298
|
#
|
297
299
|
# @return [Relation]
|
298
300
|
#
|
data/lib/rom/relation/curried.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/equalizer'
|
2
4
|
|
3
5
|
require 'rom/types'
|
@@ -35,7 +37,7 @@ module ROM
|
|
35
37
|
|
36
38
|
# @!attribute [r] arity
|
37
39
|
# @return [Integer] View's arity
|
38
|
-
option :arity, type: Types::Strict::
|
40
|
+
option :arity, type: Types::Strict::Integer
|
39
41
|
|
40
42
|
# @!attribute [r] curry_args
|
41
43
|
# @return [Array] Arguments that will be passed to curried view
|
data/lib/rom/relation/graph.rb
CHANGED
data/lib/rom/relation/loaded.rb
CHANGED
data/lib/rom/relation/name.rb
CHANGED
data/lib/rom/relation/wrap.rb
CHANGED
data/lib/rom/schema.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/equalizer'
|
2
4
|
|
3
5
|
require 'rom/constants'
|
@@ -62,6 +64,19 @@ module ROM
|
|
62
64
|
|
63
65
|
DEFAULT_INFERRER = Inferrer.new(enabled: false).freeze
|
64
66
|
|
67
|
+
type_transformation = lambda do |key|
|
68
|
+
k = if key.default?
|
69
|
+
key.constructor { |value| value.nil? ? Undefined : value }
|
70
|
+
else
|
71
|
+
key
|
72
|
+
end
|
73
|
+
k.required(false)
|
74
|
+
end
|
75
|
+
|
76
|
+
HASH_SCHEMA = Types::Coercible::Hash.
|
77
|
+
schema(EMPTY_HASH).
|
78
|
+
with_type_transform(type_transformation)
|
79
|
+
|
65
80
|
extend Initializer
|
66
81
|
|
67
82
|
include Dry::Equalizer(:name, :attributes, :associations)
|
@@ -104,7 +119,7 @@ module ROM
|
|
104
119
|
|
105
120
|
alias_method :to_ary, :attributes
|
106
121
|
|
107
|
-
# Define a relation schema from plain rom types
|
122
|
+
# Define a relation schema from plain rom types and optional options
|
108
123
|
#
|
109
124
|
# Resulting schema will decorate plain rom types with adapter-specific types
|
110
125
|
# By default `Attribute` will be used
|
@@ -123,9 +138,27 @@ module ROM
|
|
123
138
|
) { |schema| yield(schema) if block_given? }
|
124
139
|
end
|
125
140
|
|
141
|
+
# Builds a representation of the information needed to create an
|
142
|
+
# attribute.
|
143
|
+
#
|
144
|
+
# This representation is consumed by `Schema.define` in order to create
|
145
|
+
# the actual attributes.
|
146
|
+
#
|
147
|
+
# @return [Hash] A hash with `:type` and `:options` keys.
|
148
|
+
#
|
149
|
+
# @api private
|
150
|
+
def self.build_attribute_info(type, options)
|
151
|
+
{
|
152
|
+
type: type,
|
153
|
+
options: options
|
154
|
+
}
|
155
|
+
end
|
156
|
+
|
126
157
|
# @api private
|
127
158
|
def self.attributes(attributes, attr_class)
|
128
|
-
attributes.map
|
159
|
+
attributes.map do |attr|
|
160
|
+
attr_class.new(attr[:type], attr.fetch(:options))
|
161
|
+
end
|
129
162
|
end
|
130
163
|
|
131
164
|
# @api private
|
@@ -389,7 +422,7 @@ module ROM
|
|
389
422
|
#
|
390
423
|
# @api private
|
391
424
|
def to_output_hash
|
392
|
-
|
425
|
+
HASH_SCHEMA.schema(
|
393
426
|
map { |attr| [attr.key, attr.to_read_type] }.to_h
|
394
427
|
)
|
395
428
|
end
|
@@ -403,7 +436,7 @@ module ROM
|
|
403
436
|
#
|
404
437
|
# @api private
|
405
438
|
def to_input_hash
|
406
|
-
|
439
|
+
HASH_SCHEMA.schema(
|
407
440
|
map { |attr| [attr.name, attr.to_write_type] }.to_h
|
408
441
|
)
|
409
442
|
end
|
@@ -451,8 +484,8 @@ module ROM
|
|
451
484
|
# @api private
|
452
485
|
def initialize_primary_key_names
|
453
486
|
if primary_key.size > 0
|
454
|
-
set!(:primary_key_name, primary_key[0].
|
455
|
-
set!(:primary_key_names, primary_key.map
|
487
|
+
set!(:primary_key_name, primary_key[0].name)
|
488
|
+
set!(:primary_key_names, primary_key.map(&:name))
|
456
489
|
end
|
457
490
|
end
|
458
491
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rom/support/inflector'
|
2
4
|
|
3
5
|
require 'rom/associations/definitions'
|
@@ -110,7 +112,7 @@ module ROM
|
|
110
112
|
# @param [Symbol] target The target relation identifier
|
111
113
|
# @param [Hash] options A hash with additional options
|
112
114
|
#
|
113
|
-
# @return [Associations::
|
115
|
+
# @return [Associations::ManyToMany]
|
114
116
|
#
|
115
117
|
# @see #one_to_many
|
116
118
|
#
|
@@ -127,7 +129,7 @@ module ROM
|
|
127
129
|
# @param [Symbol] target The target relation identifier
|
128
130
|
# @param [Hash] options A hash with additional options
|
129
131
|
#
|
130
|
-
# @return [Associations::
|
132
|
+
# @return [Associations::ManyToOne]
|
131
133
|
#
|
132
134
|
# @see #one_to_many
|
133
135
|
#
|
@@ -163,7 +165,7 @@ module ROM
|
|
163
165
|
#
|
164
166
|
# @see #one_to_one
|
165
167
|
#
|
166
|
-
# @return [Associations::
|
168
|
+
# @return [Associations::OneToOne]
|
167
169
|
#
|
168
170
|
# @api public
|
169
171
|
def has_one(target, options = {})
|
data/lib/rom/schema/dsl.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/equalizer'
|
2
4
|
|
3
5
|
require 'rom/types'
|
@@ -36,7 +38,10 @@ module ROM
|
|
36
38
|
option :adapter, default: -> { :default }
|
37
39
|
|
38
40
|
# @!attribute [r] attributes
|
39
|
-
# @return [Hash] A hash with
|
41
|
+
# @return [Hash<Symbol, Hash>] A hash with attribute names as
|
42
|
+
# keys and attribute representations as values.
|
43
|
+
#
|
44
|
+
# @see [Schema.build_attribute_info]
|
40
45
|
attr_reader :attributes
|
41
46
|
|
42
47
|
# @!attribute [r] plugins
|
@@ -61,18 +66,22 @@ module ROM
|
|
61
66
|
@definition = block
|
62
67
|
end
|
63
68
|
|
64
|
-
# Defines a relation attribute with its type
|
69
|
+
# Defines a relation attribute with its type and options.
|
70
|
+
#
|
71
|
+
# When only options are given, type is left as nil. It makes
|
72
|
+
# sense when it is used alongside an schema inferrer, which will
|
73
|
+
# populate the type.
|
65
74
|
#
|
66
75
|
# @see Relation.schema
|
67
76
|
#
|
68
77
|
# @api public
|
69
|
-
def attribute(name,
|
78
|
+
def attribute(name, type_or_options, options = EMPTY_HASH)
|
70
79
|
if attributes.key?(name)
|
71
80
|
::Kernel.raise ::ROM::AttributeAlreadyDefinedError,
|
72
81
|
"Attribute #{ name.inspect } already defined"
|
73
82
|
end
|
74
83
|
|
75
|
-
attributes[name] =
|
84
|
+
attributes[name] = build_attribute_info(name, type_or_options, options)
|
76
85
|
end
|
77
86
|
|
78
87
|
# Define associations for a relation
|
@@ -108,18 +117,38 @@ module ROM
|
|
108
117
|
@associations_dsl = AssociationsDSL.new(relation, &block)
|
109
118
|
end
|
110
119
|
|
111
|
-
# Builds a
|
120
|
+
# Builds a representation of the information needed to create an
|
121
|
+
# attribute. It returns a hash with `:type` and `:options` keys.
|
122
|
+
#
|
123
|
+
# @return [Hash]
|
124
|
+
#
|
125
|
+
# @see [Schema.build_attribute_info]
|
126
|
+
#
|
127
|
+
# @api private
|
128
|
+
def build_attribute_info(name, type_or_options, options = EMPTY_HASH)
|
129
|
+
type, options = if type_or_options.is_a?(::Hash)
|
130
|
+
[nil, type_or_options]
|
131
|
+
else
|
132
|
+
[build_type(type_or_options, options), options]
|
133
|
+
end
|
134
|
+
Schema.build_attribute_info(
|
135
|
+
type,
|
136
|
+
options.merge(name: name)
|
137
|
+
)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Builds a type instance from base type and meta options
|
112
141
|
#
|
113
142
|
# @return [Dry::Types::Type] Type instance
|
114
143
|
#
|
115
144
|
# @api private
|
116
|
-
def build_type(
|
145
|
+
def build_type(type, options = EMPTY_HASH)
|
117
146
|
if options[:read]
|
118
|
-
type.meta(
|
119
|
-
elsif type.optional? &&
|
120
|
-
type.meta(
|
147
|
+
type.meta(source: relation, read: options[:read])
|
148
|
+
elsif type.optional? && type.meta[:read]
|
149
|
+
type.meta(source: relation, read: type.meta[:read].optional)
|
121
150
|
else
|
122
|
-
type.meta(
|
151
|
+
type.meta(source: relation)
|
123
152
|
end
|
124
153
|
end
|
125
154
|
|
@@ -128,7 +157,8 @@ module ROM
|
|
128
157
|
# @api public
|
129
158
|
def primary_key(*names)
|
130
159
|
names.each do |name|
|
131
|
-
attributes[name]
|
160
|
+
attributes[name][:type] =
|
161
|
+
attributes[name][:type].meta(primary_key: true)
|
132
162
|
end
|
133
163
|
self
|
134
164
|
end
|
data/lib/rom/schema/inferrer.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/core/class_attributes'
|
2
4
|
|
3
5
|
module ROM
|
@@ -81,9 +83,25 @@ module ROM
|
|
81
83
|
|
82
84
|
# @api private
|
83
85
|
def merge_attributes(defined, inferred)
|
84
|
-
|
85
|
-
|
86
|
-
|
86
|
+
type_lookup = lambda do |attrs, name|
|
87
|
+
attrs.find { |a| a.name == name }.type
|
88
|
+
end
|
89
|
+
defined_with_type, defined_names =
|
90
|
+
defined.each_with_object([[], []]) do |attr, (attrs, names)|
|
91
|
+
attrs << if attr.type.nil?
|
92
|
+
attr.class.new(
|
93
|
+
type_lookup.(inferred, attr.name),
|
94
|
+
attr.options
|
95
|
+
)
|
96
|
+
else
|
97
|
+
attr
|
98
|
+
end
|
99
|
+
names << attr.name
|
100
|
+
end
|
101
|
+
|
102
|
+
defined_with_type + inferred.reject do |attr|
|
103
|
+
defined_names.include?(attr.name)
|
104
|
+
end
|
87
105
|
end
|
88
106
|
end
|
89
107
|
end
|
data/lib/rom/schema_plugin.rb
CHANGED
data/lib/rom/setup.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rom/types'
|
2
4
|
require 'rom/initializer'
|
3
5
|
|
@@ -9,7 +11,7 @@ module ROM
|
|
9
11
|
class Base
|
10
12
|
extend Initializer
|
11
13
|
|
12
|
-
PathnameType = Types.
|
14
|
+
PathnameType = Types.Instance(Pathname)
|
13
15
|
|
14
16
|
EXTENSION_REGEX = /\.rb\z/
|
15
17
|
|
data/lib/rom/setup/finalize.rb
CHANGED