rom-core 5.3.1 → 5.4.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/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 +17 -20
- 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
data/lib/rom/data_proxy.rb
CHANGED
@@ -56,9 +56,7 @@ module ROM
|
|
56
56
|
# @return [Proc]
|
57
57
|
#
|
58
58
|
# @api private
|
59
|
-
def row_proc
|
60
|
-
-> tuple { tuple }
|
61
|
-
end
|
59
|
+
def row_proc = -> tuple { tuple }
|
62
60
|
|
63
61
|
# Forward provided methods to the underlaying data object
|
64
62
|
#
|
@@ -77,18 +75,18 @@ module ROM
|
|
77
75
|
# FIXME: we should probably raise if one of the non-forwardable methods
|
78
76
|
# was provided
|
79
77
|
(methods - NON_FORWARDABLE).each do |method_name|
|
80
|
-
class_eval
|
81
|
-
def #{method_name}(
|
82
|
-
response = data.public_send(
|
83
|
-
|
84
|
-
if response.equal?(data)
|
85
|
-
self
|
86
|
-
elsif response.is_a?(data.class)
|
87
|
-
self.class.new(response)
|
88
|
-
else
|
89
|
-
response
|
90
|
-
end
|
91
|
-
end
|
78
|
+
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
79
|
+
def #{method_name}(...) # def find_all(...)
|
80
|
+
response = data.public_send(:#{method_name}, ...) # response = data.public_send(:find_all, ...)
|
81
|
+
#
|
82
|
+
if response.equal?(data) # if response.equal?(data)
|
83
|
+
self # self
|
84
|
+
elsif response.is_a?(data.class) # elsif response.is_a?(data.class)
|
85
|
+
self.class.new(response) # self.class.new(response)
|
86
|
+
else # else
|
87
|
+
response # response
|
88
|
+
end # end
|
89
|
+
end # end
|
92
90
|
RUBY
|
93
91
|
end
|
94
92
|
end
|
@@ -27,7 +27,7 @@ module ROM
|
|
27
27
|
# @api public
|
28
28
|
module EnumerableDataset
|
29
29
|
extend DataProxy::ClassMethods
|
30
|
-
include Enumerable
|
30
|
+
include ::Enumerable
|
31
31
|
|
32
32
|
# Coerce a dataset to an array
|
33
33
|
#
|
@@ -59,11 +59,11 @@ module ROM
|
|
59
59
|
chunk collect collect_concat drop_while find_all flat_map
|
60
60
|
grep map reject select sort sort_by take_while
|
61
61
|
].each do |method|
|
62
|
-
class_eval
|
63
|
-
def #{method}(
|
64
|
-
return to_enum unless
|
65
|
-
self.class.new(super(
|
66
|
-
end
|
62
|
+
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
63
|
+
def #{method}(...) # def collect(...)
|
64
|
+
return to_enum unless block_given? # return to_enum unless block_given?
|
65
|
+
self.class.new(super(...), **options) # self.class.new(super(...), **options)
|
66
|
+
end # end
|
67
67
|
RUBY
|
68
68
|
end
|
69
69
|
end
|
data/lib/rom/environment.rb
CHANGED
@@ -10,7 +10,9 @@ module ROM
|
|
10
10
|
class Environment
|
11
11
|
include Configurable
|
12
12
|
|
13
|
-
attr_reader :gateways
|
13
|
+
attr_reader :gateways
|
14
|
+
|
15
|
+
attr_reader :gateways_map
|
14
16
|
|
15
17
|
# @api private
|
16
18
|
def initialize(*args)
|
@@ -49,11 +51,9 @@ module ROM
|
|
49
51
|
|
50
52
|
if identifier.is_a?(Gateway)
|
51
53
|
gateway = identifier
|
52
|
-
elsif RUBY_VERSION >= "3.0"
|
53
|
-
kwargs = args.last.is_a?(Hash) ? args.pop : {}
|
54
|
-
gateway = Gateway.setup(identifier, *args.flatten, **kwargs)
|
55
54
|
else
|
56
|
-
|
55
|
+
kwargs = args.last.is_a?(::Hash) ? args.pop : {}
|
56
|
+
gateway = Gateway.setup(identifier, *args.flatten, **kwargs)
|
57
57
|
end
|
58
58
|
|
59
59
|
hash[:map][gateway] = name
|
data/lib/rom/gateway.rb
CHANGED
@@ -78,7 +78,7 @@ module ROM
|
|
78
78
|
# @return [Gateway] a specific gateway subclass
|
79
79
|
#
|
80
80
|
# @api public
|
81
|
-
def self.setup(gateway_or_scheme, *args)
|
81
|
+
def self.setup(gateway_or_scheme, *args, **kwargs)
|
82
82
|
case gateway_or_scheme
|
83
83
|
when String
|
84
84
|
raise ArgumentError, <<-STRING.gsub(/^ {10}/, '')
|
@@ -91,7 +91,7 @@ module ROM
|
|
91
91
|
if klass.instance_method(:initialize).arity.zero?
|
92
92
|
klass.new
|
93
93
|
else
|
94
|
-
klass.new(*args)
|
94
|
+
klass.new(*args, **kwargs)
|
95
95
|
end
|
96
96
|
else
|
97
97
|
raise ArgumentError, "Can't accept arguments when passing an instance" unless args.empty?
|
@@ -100,10 +100,6 @@ module ROM
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
class << self
|
104
|
-
ruby2_keywords(:setup) if respond_to?(:ruby2_keywords, true)
|
105
|
-
end
|
106
|
-
|
107
103
|
# Get gateway subclass for a specific adapter
|
108
104
|
#
|
109
105
|
# @param [Symbol] type Adapter identifier
|
@@ -176,15 +172,11 @@ module ROM
|
|
176
172
|
# the transaction was rolled back
|
177
173
|
#
|
178
174
|
# @api public
|
179
|
-
def transaction(opts = EMPTY_HASH, &
|
180
|
-
transaction_runner(opts).run(opts, &block)
|
181
|
-
end
|
175
|
+
def transaction(opts = EMPTY_HASH, &) = transaction_runner(opts).run(opts, &)
|
182
176
|
|
183
177
|
private
|
184
178
|
|
185
179
|
# @api private
|
186
|
-
def transaction_runner(_)
|
187
|
-
Transaction::NoOp
|
188
|
-
end
|
180
|
+
def transaction_runner(_) = Transaction::NoOp
|
189
181
|
end
|
190
182
|
end
|
@@ -21,10 +21,10 @@ module ROM
|
|
21
21
|
attr_reader :registry
|
22
22
|
|
23
23
|
# @api private
|
24
|
-
def initialize(registry, defaults = EMPTY_HASH, &
|
24
|
+
def initialize(registry, defaults = EMPTY_HASH, &)
|
25
25
|
@registry = registry
|
26
26
|
@defaults = defaults
|
27
|
-
instance_exec(&
|
27
|
+
instance_exec(&)
|
28
28
|
end
|
29
29
|
|
30
30
|
# Register a plugin
|
@@ -43,8 +43,8 @@ module ROM
|
|
43
43
|
# @param [Symbol] type The adapter identifier
|
44
44
|
#
|
45
45
|
# @api public
|
46
|
-
def adapter(type, &
|
47
|
-
self.class.new(registry, adapter: type, &
|
46
|
+
def adapter(type, &)
|
47
|
+
self.class.new(registry, adapter: type, &)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
data/lib/rom/global.rb
CHANGED
data/lib/rom/header/attribute.rb
CHANGED
data/lib/rom/header.rb
CHANGED
@@ -10,8 +10,8 @@ module ROM
|
|
10
10
|
#
|
11
11
|
# @private
|
12
12
|
class Header
|
13
|
-
include Enumerable
|
14
|
-
include Dry::Equalizer(:attributes, :model)
|
13
|
+
include ::Enumerable
|
14
|
+
include ::Dry::Equalizer(:attributes, :model)
|
15
15
|
|
16
16
|
# @return [Class] optional model associated with a header
|
17
17
|
#
|
@@ -54,9 +54,7 @@ module ROM
|
|
54
54
|
if input.instance_of?(self)
|
55
55
|
input
|
56
56
|
else
|
57
|
-
attributes = input.
|
58
|
-
h[pair.first] = Attribute.coerce(pair)
|
59
|
-
}
|
57
|
+
attributes = input.to_h { [_1.first, Attribute.coerce(_1)] }
|
60
58
|
|
61
59
|
new(attributes, options)
|
62
60
|
end
|
@@ -80,88 +78,68 @@ module ROM
|
|
80
78
|
# @yield [Attribute]
|
81
79
|
#
|
82
80
|
# @api private
|
83
|
-
def each
|
84
|
-
attributes.each_value { |attribute| yield(attribute) }
|
85
|
-
end
|
81
|
+
def each(&) = attributes.each_value(&)
|
86
82
|
|
87
83
|
# Return if there are any aliased attributes
|
88
84
|
#
|
89
85
|
# @api private
|
90
|
-
def aliased?
|
91
|
-
any?(&:aliased?)
|
92
|
-
end
|
86
|
+
def aliased? = any?(&:aliased?)
|
93
87
|
|
94
88
|
# Return attribute keys
|
95
89
|
#
|
96
90
|
# An attribute key corresponds to tuple attribute names
|
97
91
|
#
|
98
92
|
# @api private
|
99
|
-
def keys
|
100
|
-
attributes.keys
|
101
|
-
end
|
93
|
+
def keys = attributes.keys
|
102
94
|
|
103
95
|
# Return attribute identified by its name
|
104
96
|
#
|
105
97
|
# @return [Attribute]
|
106
98
|
#
|
107
99
|
# @api private
|
108
|
-
def [](name)
|
109
|
-
attributes.fetch(name)
|
110
|
-
end
|
100
|
+
def [](name) = attributes.fetch(name)
|
111
101
|
|
112
102
|
# Return all Combined attributes
|
113
103
|
#
|
114
104
|
# @return [Array<Combined>]
|
115
105
|
#
|
116
106
|
# @api private
|
117
|
-
def combined
|
118
|
-
by_type(Combined)
|
119
|
-
end
|
107
|
+
def combined = by_type(Combined)
|
120
108
|
|
121
109
|
# Returns all attributes that require preprocessing
|
122
110
|
#
|
123
111
|
# @return [Array<Group,Fold>]
|
124
112
|
#
|
125
113
|
# @api private
|
126
|
-
def preprocessed
|
127
|
-
by_type(Group, Fold)
|
128
|
-
end
|
114
|
+
def preprocessed = by_type(Group, Fold)
|
129
115
|
|
130
116
|
# Returns all attributes that require postprocessing
|
131
117
|
#
|
132
118
|
# @return [Array<Ungroup,Unfold>]
|
133
119
|
#
|
134
120
|
# @api private
|
135
|
-
def postprocessed
|
136
|
-
by_type(Ungroup, Unfold)
|
137
|
-
end
|
121
|
+
def postprocessed = by_type(Ungroup, Unfold)
|
138
122
|
|
139
123
|
# Return all Wrap attributes
|
140
124
|
#
|
141
125
|
# @return [Array<Wrap>]
|
142
126
|
#
|
143
127
|
# @api private
|
144
|
-
def wraps
|
145
|
-
by_type(Wrap)
|
146
|
-
end
|
128
|
+
def wraps = by_type(Wrap)
|
147
129
|
|
148
130
|
# Return all non-primitive attributes that don't require mapping
|
149
131
|
#
|
150
132
|
# @return [Array<Group,Fold,Ungroup,Unfold,Wrap,Unwrap>]
|
151
133
|
#
|
152
134
|
# @api private
|
153
|
-
def non_primitives
|
154
|
-
preprocessed + wraps
|
155
|
-
end
|
135
|
+
def non_primitives = preprocessed + wraps
|
156
136
|
|
157
137
|
# Return all primitive attributes that require mapping
|
158
138
|
#
|
159
139
|
# @return [Array<Attribute>]
|
160
140
|
#
|
161
141
|
# @api private
|
162
|
-
def primitives
|
163
|
-
to_a - non_primitives
|
164
|
-
end
|
142
|
+
def primitives = to_a - non_primitives
|
165
143
|
|
166
144
|
private
|
167
145
|
|
data/lib/rom/initializer.rb
CHANGED
@@ -8,18 +8,14 @@ module ROM
|
|
8
8
|
# @api private
|
9
9
|
module DefineWithHook
|
10
10
|
# @api private
|
11
|
-
def param(
|
12
|
-
super.tap { __define_with__ }
|
13
|
-
end
|
14
|
-
ruby2_keywords(:param) if respond_to?(:ruby2_keywords, true)
|
11
|
+
def param(*, **) = super.tap { __define_with__ }
|
15
12
|
|
16
13
|
# @api private
|
17
|
-
def option(
|
14
|
+
def option(*, **)
|
18
15
|
super.tap do
|
19
16
|
__define_with__ unless method_defined?(:with)
|
20
17
|
end
|
21
18
|
end
|
22
|
-
ruby2_keywords(:option) if respond_to?(:ruby2_keywords, true)
|
23
19
|
|
24
20
|
# @api private
|
25
21
|
def __define_with__
|
@@ -34,13 +30,13 @@ module ROM
|
|
34
30
|
undef_method(:with) if method_defined?(:with)
|
35
31
|
|
36
32
|
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
37
|
-
def with(**new_options)
|
38
|
-
if new_options.empty?
|
39
|
-
self
|
40
|
-
else
|
41
|
-
self.class.new(#{seq_names}**options, **new_options)
|
42
|
-
end
|
43
|
-
end
|
33
|
+
def with(**new_options) # def with(**new_options)
|
34
|
+
if new_options.empty? # if new_options.empty?
|
35
|
+
self # self
|
36
|
+
else # else
|
37
|
+
self.class.new(#{seq_names}**options, **new_options) # self.class.new(relation, **options, **new_options)
|
38
|
+
end # end
|
39
|
+
end # end
|
44
40
|
RUBY
|
45
41
|
end
|
46
42
|
end
|
@@ -64,8 +60,8 @@ module ROM
|
|
64
60
|
#
|
65
61
|
# @api public
|
66
62
|
def options
|
67
|
-
@__options__ ||= self.class.dry_initializer.definitions.values.
|
68
|
-
|
63
|
+
@__options__ ||= self.class.dry_initializer.definitions.values.to_h do |item|
|
64
|
+
[item.target, instance_variable_get(item.ivar)]
|
69
65
|
end
|
70
66
|
end
|
71
67
|
|
@@ -26,6 +26,7 @@ module ROM
|
|
26
26
|
#
|
27
27
|
# @api public
|
28
28
|
def initialize(dataset, data)
|
29
|
+
super()
|
29
30
|
@dataset = dataset
|
30
31
|
@data = data
|
31
32
|
end
|
@@ -35,7 +36,7 @@ module ROM
|
|
35
36
|
# @api public
|
36
37
|
def lint_each
|
37
38
|
result = []
|
38
|
-
dataset.each do |tuple|
|
39
|
+
dataset.each do |tuple| # rubocop:disable Style/MapIntoArray
|
39
40
|
result << tuple
|
40
41
|
end
|
41
42
|
return if result == data
|
data/lib/rom/lint/gateway.rb
CHANGED
@@ -35,6 +35,7 @@ module ROM
|
|
35
35
|
# @param [Class] gateway
|
36
36
|
# @param [String] uri optional
|
37
37
|
def initialize(identifier, gateway, uri = nil)
|
38
|
+
super()
|
38
39
|
@identifier = identifier
|
39
40
|
@gateway = gateway
|
40
41
|
@uri = uri
|
@@ -89,7 +90,8 @@ module ROM
|
|
89
90
|
# Lint: Ensure +gateway_instance+ returns adapter name
|
90
91
|
def lint_adapter_reader
|
91
92
|
if gateway_instance.adapter != identifier
|
92
|
-
complain "#{gateway_instance} must have the adapter
|
93
|
+
complain "#{gateway_instance} must have the adapter " \
|
94
|
+
"identifier set to #{identifier.inspect}"
|
93
95
|
end
|
94
96
|
rescue MissingAdapterIdentifierError
|
95
97
|
complain "#{gateway_instance} is missing the adapter identifier"
|
data/lib/rom/lint/linter.rb
CHANGED
@@ -18,7 +18,7 @@ module ROM
|
|
18
18
|
# @api public
|
19
19
|
class Linter
|
20
20
|
# A failure raised by +complain+
|
21
|
-
Failure = Class.new(StandardError)
|
21
|
+
Failure = ::Class.new(::StandardError)
|
22
22
|
|
23
23
|
# Iterate over all lint methods
|
24
24
|
#
|
@@ -52,7 +52,7 @@ module ROM
|
|
52
52
|
# @return [String]
|
53
53
|
#
|
54
54
|
# @api private
|
55
|
-
def self.lints
|
55
|
+
private_class_method def self.lints
|
56
56
|
public_instance_methods(true).grep(/^lint_/).map(&:to_s)
|
57
57
|
end
|
58
58
|
|
data/lib/rom/lint/test.rb
CHANGED
@@ -12,13 +12,11 @@ module ROM
|
|
12
12
|
# @param [String] name
|
13
13
|
#
|
14
14
|
# @api private
|
15
|
-
def define_test_method(name, &
|
15
|
+
def define_test_method(name, &)
|
16
16
|
define_method "test_#{name}" do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
raise Minitest::Assertion, f.message
|
21
|
-
end
|
17
|
+
instance_eval(&)
|
18
|
+
rescue ROM::Lint::Linter::Failure => e
|
19
|
+
raise Minitest::Assertion, e.message
|
22
20
|
end
|
23
21
|
end
|
24
22
|
end
|
@@ -13,10 +13,21 @@ module ROM
|
|
13
13
|
# TODO: break this madness down into smaller pieces
|
14
14
|
#
|
15
15
|
# @api private
|
16
|
+
# rubocop:disable Metrics/ClassLength
|
16
17
|
class AttributeDSL
|
17
18
|
include ModelDSL
|
18
19
|
|
19
|
-
attr_reader :attributes
|
20
|
+
attr_reader :attributes
|
21
|
+
|
22
|
+
attr_reader :options
|
23
|
+
|
24
|
+
attr_reader :copy_keys
|
25
|
+
|
26
|
+
attr_reader :symbolize_keys
|
27
|
+
|
28
|
+
attr_reader :reject_keys
|
29
|
+
|
30
|
+
attr_reader :steps
|
20
31
|
|
21
32
|
# @param [Array] attributes accumulator array
|
22
33
|
# @param [Hash] options
|
@@ -78,17 +89,17 @@ module ROM
|
|
78
89
|
# @api public
|
79
90
|
def attribute(name, options = EMPTY_HASH, &block)
|
80
91
|
with_attr_options(name, options) do |attr_options|
|
81
|
-
if options[:type] &&
|
92
|
+
if options[:type] && block_given?
|
82
93
|
raise ArgumentError,
|
83
94
|
"can't specify type and block at the same time"
|
84
95
|
end
|
85
|
-
attr_options[:coercer] = block if
|
96
|
+
attr_options[:coercer] = block if block_given?
|
86
97
|
add_attribute(name, attr_options)
|
87
98
|
end
|
88
99
|
end
|
89
100
|
|
90
101
|
def exclude(name)
|
91
|
-
attributes << [name,
|
102
|
+
attributes << [name, exclude: true]
|
92
103
|
end
|
93
104
|
|
94
105
|
# Perform transformations sequentially
|
@@ -101,8 +112,8 @@ module ROM
|
|
101
112
|
# end
|
102
113
|
#
|
103
114
|
# @api public
|
104
|
-
def step(options = EMPTY_HASH, &
|
105
|
-
steps << new(options, &
|
115
|
+
def step(options = EMPTY_HASH, &)
|
116
|
+
steps << new(options, &)
|
106
117
|
end
|
107
118
|
|
108
119
|
# Define an embedded attribute
|
@@ -129,7 +140,7 @@ module ROM
|
|
129
140
|
# its attributes
|
130
141
|
#
|
131
142
|
# @api public
|
132
|
-
def embedded(name, options, &
|
143
|
+
def embedded(name, options, &)
|
133
144
|
with_attr_options(name) do |attr_options|
|
134
145
|
mapper = options[:mapper]
|
135
146
|
|
@@ -139,7 +150,7 @@ module ROM
|
|
139
150
|
mapper, name, embedded_options.update(attr_options)
|
140
151
|
)
|
141
152
|
else
|
142
|
-
dsl = new(options, &
|
153
|
+
dsl = new(options, &)
|
143
154
|
attr_options.update(options)
|
144
155
|
add_attribute(
|
145
156
|
name, { header: dsl.header, type: :array }.update(attr_options)
|
@@ -167,7 +178,7 @@ module ROM
|
|
167
178
|
# @see AttributeDSL#embedded
|
168
179
|
#
|
169
180
|
# @api public
|
170
|
-
def wrap(*args, &
|
181
|
+
def wrap(*args, &)
|
171
182
|
ensure_mapper_configuration('wrap', args, block_given?)
|
172
183
|
|
173
184
|
with_name_or_options(*args) do |name, options, mapper|
|
@@ -176,7 +187,7 @@ module ROM
|
|
176
187
|
if mapper
|
177
188
|
attributes_from_mapper(mapper, name, wrap_options)
|
178
189
|
else
|
179
|
-
dsl(name, wrap_options, &
|
190
|
+
dsl(name, wrap_options, &)
|
180
191
|
end
|
181
192
|
end
|
182
193
|
end
|
@@ -200,14 +211,14 @@ module ROM
|
|
200
211
|
# @see AttributeDSL#embedded
|
201
212
|
#
|
202
213
|
# @api public
|
203
|
-
def unwrap(*args, &
|
214
|
+
def unwrap(*args, &)
|
204
215
|
with_name_or_options(*args) do |name, options, mapper|
|
205
216
|
unwrap_options = { type: :hash, unwrap: true }.update(options)
|
206
217
|
|
207
218
|
if mapper
|
208
219
|
attributes_from_mapper(mapper, name, unwrap_options)
|
209
220
|
else
|
210
|
-
dsl(name, unwrap_options, &
|
221
|
+
dsl(name, unwrap_options, &)
|
211
222
|
end
|
212
223
|
end
|
213
224
|
end
|
@@ -229,7 +240,7 @@ module ROM
|
|
229
240
|
# @see AttributeDSL#embedded
|
230
241
|
#
|
231
242
|
# @api public
|
232
|
-
def group(*args, &
|
243
|
+
def group(*args, &)
|
233
244
|
ensure_mapper_configuration('group', args, block_given?)
|
234
245
|
|
235
246
|
with_name_or_options(*args) do |name, options, mapper|
|
@@ -238,7 +249,7 @@ module ROM
|
|
238
249
|
if mapper
|
239
250
|
attributes_from_mapper(mapper, name, group_options)
|
240
251
|
else
|
241
|
-
dsl(name, group_options, &
|
252
|
+
dsl(name, group_options, &)
|
242
253
|
end
|
243
254
|
end
|
244
255
|
end
|
@@ -254,10 +265,10 @@ module ROM
|
|
254
265
|
# @see AttributeDSL#embedded
|
255
266
|
#
|
256
267
|
# @api public
|
257
|
-
def ungroup(*args, &
|
268
|
+
def ungroup(*args, &)
|
258
269
|
with_name_or_options(*args) do |name, options, *|
|
259
270
|
ungroup_options = { type: :array, ungroup: true }.update(options)
|
260
|
-
dsl(name, ungroup_options, &
|
271
|
+
dsl(name, ungroup_options, &)
|
261
272
|
end
|
262
273
|
end
|
263
274
|
|
@@ -274,10 +285,10 @@ module ROM
|
|
274
285
|
# @see AttributeDSL#embedded
|
275
286
|
#
|
276
287
|
# @api public
|
277
|
-
def fold(*args, &
|
288
|
+
def fold(*args, &)
|
278
289
|
with_name_or_options(*args) do |name, *|
|
279
290
|
fold_options = { type: :array, fold: true }
|
280
|
-
dsl(name, fold_options, &
|
291
|
+
dsl(name, fold_options, &)
|
281
292
|
end
|
282
293
|
end
|
283
294
|
|
@@ -330,8 +341,8 @@ module ROM
|
|
330
341
|
# @option options [Symbol] :type The type, either :array (default) or :hash
|
331
342
|
#
|
332
343
|
# @api public
|
333
|
-
def combine(name, options, &
|
334
|
-
dsl = new(options, &
|
344
|
+
def combine(name, options, &)
|
345
|
+
dsl = new(options, &)
|
335
346
|
|
336
347
|
attr_opts = {
|
337
348
|
type: options.fetch(:type, :array),
|
@@ -396,9 +407,9 @@ module ROM
|
|
396
407
|
# This is used by embedded, wrap and group
|
397
408
|
#
|
398
409
|
# @api private
|
399
|
-
def dsl(name_or_attrs, options, &
|
400
|
-
if
|
401
|
-
attributes_from_block(name_or_attrs, options, &
|
410
|
+
def dsl(name_or_attrs, options, &)
|
411
|
+
if block_given?
|
412
|
+
attributes_from_block(name_or_attrs, options, &)
|
402
413
|
else
|
403
414
|
attributes_from_hash(name_or_attrs, options)
|
404
415
|
end
|
@@ -409,8 +420,8 @@ module ROM
|
|
409
420
|
# Used by embedded, wrap and group
|
410
421
|
#
|
411
422
|
# @api private
|
412
|
-
def attributes_from_block(name, options, &
|
413
|
-
dsl = new(options, &
|
423
|
+
def attributes_from_block(name, options, &)
|
424
|
+
dsl = new(options, &)
|
414
425
|
header = dsl.header
|
415
426
|
add_attribute(name, options.update(header: header))
|
416
427
|
header.each { |attr| remove(attr.key) unless name == attr.key }
|
@@ -456,9 +467,9 @@ module ROM
|
|
456
467
|
# Embedded, wrap and group can override top-level options like `prefix`
|
457
468
|
#
|
458
469
|
# @api private
|
459
|
-
def new(options, &
|
470
|
+
def new(options, &)
|
460
471
|
dsl = self.class.new([], @options.merge(options))
|
461
|
-
dsl.instance_exec(&
|
472
|
+
dsl.instance_exec(&) if block_given?
|
462
473
|
dsl
|
463
474
|
end
|
464
475
|
|
@@ -476,5 +487,6 @@ module ROM
|
|
476
487
|
end
|
477
488
|
end
|
478
489
|
end
|
490
|
+
# rubocop:enable Metrics/ClassLength
|
479
491
|
end
|
480
492
|
end
|
data/lib/rom/mapper/builder.rb
CHANGED
@@ -11,7 +11,7 @@ module ROM
|
|
11
11
|
# This is used by Setup#mappers DSL
|
12
12
|
#
|
13
13
|
# @api private
|
14
|
-
def self.build_class(name, mapper_registry, options = EMPTY_HASH, &
|
14
|
+
def self.build_class(name, mapper_registry, options = EMPTY_HASH, &)
|
15
15
|
class_name = "ROM::Mapper[#{name}]"
|
16
16
|
|
17
17
|
parent = options[:parent]
|
@@ -29,7 +29,7 @@ module ROM
|
|
29
29
|
klass.relation(name)
|
30
30
|
klass.inherit_header(inherit_header)
|
31
31
|
|
32
|
-
klass.class_eval(&
|
32
|
+
klass.class_eval(&) if block_given?
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/lib/rom/mapper/dsl.rb
CHANGED
@@ -105,14 +105,13 @@ module ROM
|
|
105
105
|
# Delegate Attribute DSL method to the dsl instance
|
106
106
|
#
|
107
107
|
# @api private
|
108
|
-
def method_missing(name,
|
108
|
+
def method_missing(name, ...)
|
109
109
|
if dsl.respond_to?(name)
|
110
|
-
dsl.public_send(name,
|
110
|
+
dsl.public_send(name, ...)
|
111
111
|
else
|
112
112
|
super
|
113
113
|
end
|
114
114
|
end
|
115
|
-
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
116
115
|
end
|
117
116
|
end
|
118
117
|
end
|