rom-core 5.0.2 → 5.1.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/command.rb +0 -2
- data/lib/rom/command_compiler.rb +12 -6
- data/lib/rom/commands/class_interface.rb +1 -1
- data/lib/rom/configuration.rb +1 -3
- data/lib/rom/configuration_dsl.rb +11 -1
- data/lib/rom/{mapper → configuration_dsl}/mapper_dsl.rb +2 -2
- data/lib/rom/constants.rb +1 -1
- data/lib/rom/core.rb +9 -3
- data/lib/rom/{version.rb → core/version.rb} +1 -1
- data/lib/rom/mapper.rb +0 -1
- data/lib/rom/mapper/dsl.rb +1 -1
- data/lib/rom/plugin.rb +27 -9
- data/lib/rom/plugin_registry.rb +49 -104
- data/lib/rom/plugins.rb +20 -0
- data/lib/rom/registry.rb +16 -0
- data/lib/rom/relation/class_interface.rb +1 -1
- data/lib/rom/relation/combined.rb +1 -1
- data/lib/rom/relation/commands.rb +1 -1
- data/lib/rom/schema/associations_dsl.rb +1 -1
- data/lib/rom/schema/dsl.rb +7 -8
- data/lib/rom/schema_plugin.rb +2 -14
- data/lib/rom/setup/finalize.rb +1 -1
- data/lib/rom/setup/finalize/finalize_relations.rb +2 -2
- data/lib/rom/transformer.rb +62 -1
- metadata +16 -8
- data/lib/rom/configuration_plugin.rb +0 -19
- data/lib/rom/mapper/configuration_plugin.rb +0 -28
- data/lib/rom/plugin_base.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56abc0d6388e2082f26604f39229af054e25a5a1298485f6a609a7c8c7163ebd
|
4
|
+
data.tar.gz: 6ec5cb049f5793102d5f9287b48b607fb2e9bd9c8b2f92e045aef3fd45245e4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e197ca01ddf489798f0d4681bf5061ffaecdbcedf97a30fa909132382ce18854bccce3d90f48c6a6d5f3fc0060901a9713e5879a6b2f882e93d47bf980a59610
|
7
|
+
data.tar.gz: 23520577e017af6e42227c5c04e56f030d8b1a9b5db2554cf2d6b93e5365f5fb94bd374450e37c75cecc30b492abd22a3b8a078864e1f087ea90bfe3aaec13ce
|
data/lib/rom/command.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'dry/core/deprecations'
|
4
3
|
require 'dry/core/class_attributes'
|
5
4
|
|
6
5
|
require 'rom/types'
|
@@ -33,7 +32,6 @@ module ROM
|
|
33
32
|
include Commands
|
34
33
|
include Pipeline::Operator
|
35
34
|
|
36
|
-
|
37
35
|
# @!method self.adapter
|
38
36
|
# Get or set adapter identifier
|
39
37
|
#
|
data/lib/rom/command_compiler.rb
CHANGED
@@ -181,20 +181,26 @@ module ROM
|
|
181
181
|
#
|
182
182
|
# @param [Symbol] rel_name A relation identifier from the container registry
|
183
183
|
# @param [Symbol] type The command type
|
184
|
-
# @param [Hash]
|
184
|
+
# @param [Hash] rel_meta Meta information from relation AST
|
185
185
|
# @param [Symbol] parent_relation Optional parent relation identifier
|
186
186
|
#
|
187
187
|
# @return [ROM::Command]
|
188
188
|
#
|
189
189
|
# @api private
|
190
|
-
def register_command(rel_name, type,
|
190
|
+
def register_command(rel_name, type, rel_meta, parent_relation = nil)
|
191
191
|
relation = relations[rel_name]
|
192
192
|
|
193
193
|
type.create_class(rel_name, type) do |klass|
|
194
|
-
klass.result(
|
194
|
+
klass.result(rel_meta.fetch(:combine_type, result))
|
195
195
|
|
196
|
-
|
197
|
-
|
196
|
+
klass.input(meta.fetch(:input, relation.input_schema))
|
197
|
+
|
198
|
+
meta.each do |name, value|
|
199
|
+
klass.public_send(name, value)
|
200
|
+
end
|
201
|
+
|
202
|
+
if rel_meta[:combine_type]
|
203
|
+
setup_associates(klass, relation, rel_meta, parent_relation)
|
198
204
|
end
|
199
205
|
|
200
206
|
plugins.each do |plugin|
|
@@ -211,7 +217,7 @@ module ROM
|
|
211
217
|
|
212
218
|
klass.extend_for_relation(relation) if klass.restrictable
|
213
219
|
|
214
|
-
registry[rel_name][type] = klass.build(relation
|
220
|
+
registry[rel_name][type] = klass.build(relation)
|
215
221
|
end
|
216
222
|
end
|
217
223
|
|
@@ -112,7 +112,7 @@ module ROM
|
|
112
112
|
#
|
113
113
|
# @api public
|
114
114
|
def use(plugin, options = EMPTY_HASH)
|
115
|
-
ROM.plugin_registry.
|
115
|
+
ROM.plugin_registry[:command].fetch(plugin, adapter).apply_to(self, options)
|
116
116
|
end
|
117
117
|
|
118
118
|
# Extend a command class with relation view methods
|
data/lib/rom/configuration.rb
CHANGED
@@ -54,8 +54,6 @@ module ROM
|
|
54
54
|
@notifications = Notifications.event_bus(:configuration)
|
55
55
|
@setup = Setup.new(notifications)
|
56
56
|
|
57
|
-
use :mappers # enable mappers by default
|
58
|
-
|
59
57
|
block.call(self) if block
|
60
58
|
end
|
61
59
|
|
@@ -73,7 +71,7 @@ module ROM
|
|
73
71
|
elsif plugin.is_a?(Hash)
|
74
72
|
plugin.to_a.each { |p| use(*p) }
|
75
73
|
else
|
76
|
-
ROM.plugin_registry
|
74
|
+
ROM.plugin_registry[:configuration].fetch(plugin).apply_to(self, options)
|
77
75
|
end
|
78
76
|
|
79
77
|
self
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'rom/configuration_dsl/relation'
|
4
4
|
require 'rom/configuration_dsl/command_dsl'
|
5
|
+
require 'rom/configuration_dsl/mapper_dsl'
|
5
6
|
|
6
7
|
module ROM
|
7
8
|
# This extends Configuration class with the DSL methods
|
@@ -51,6 +52,13 @@ module ROM
|
|
51
52
|
register_command(*CommandDSL.new(name, default_adapter, &block).command_classes)
|
52
53
|
end
|
53
54
|
|
55
|
+
# Mapper definition DSL
|
56
|
+
#
|
57
|
+
# @api public
|
58
|
+
def mappers(&block)
|
59
|
+
register_mapper(*MapperDSL.new(self, mapper_classes, block).mapper_classes)
|
60
|
+
end
|
61
|
+
|
54
62
|
# Configures a plugin for a specific adapter to be enabled for all relations
|
55
63
|
#
|
56
64
|
# @example
|
@@ -70,7 +78,9 @@ module ROM
|
|
70
78
|
# @api public
|
71
79
|
def plugin(adapter, spec, &block)
|
72
80
|
type, name = spec.flatten(1)
|
73
|
-
plugin = plugin_registry
|
81
|
+
plugin = plugin_registry[type].adapter(adapter).fetch(name) do
|
82
|
+
plugin_registry[type].fetch(name)
|
83
|
+
end
|
74
84
|
|
75
85
|
if block
|
76
86
|
register_plugin(plugin.configure(&block))
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'rom/mapper/builder'
|
4
4
|
|
5
5
|
module ROM
|
6
|
-
|
6
|
+
module ConfigurationDSL
|
7
7
|
# Mapper definition DSL used by Setup DSL
|
8
8
|
#
|
9
9
|
# @private
|
@@ -30,7 +30,7 @@ module ROM
|
|
30
30
|
#
|
31
31
|
# @api public
|
32
32
|
def define(name, options = EMPTY_HASH, &block)
|
33
|
-
@defined_mappers << Builder.build_class(name, (@mapper_classes + @defined_mappers), options, &block)
|
33
|
+
@defined_mappers << Mapper::Builder.build_class(name, (@mapper_classes + @defined_mappers), options, &block)
|
34
34
|
self
|
35
35
|
end
|
36
36
|
|
data/lib/rom/constants.rb
CHANGED
data/lib/rom/core.rb
CHANGED
@@ -7,13 +7,11 @@ require 'rom/version'
|
|
7
7
|
require 'rom/constants'
|
8
8
|
|
9
9
|
# core parts
|
10
|
-
require 'rom/configuration_plugin'
|
11
10
|
require 'rom/plugin'
|
12
11
|
require 'rom/schema_plugin'
|
13
12
|
require 'rom/relation'
|
14
13
|
require 'rom/mapper'
|
15
14
|
require 'rom/processor/transproc'
|
16
|
-
require 'rom/mapper/configuration_plugin'
|
17
15
|
require 'rom/commands'
|
18
16
|
|
19
17
|
# rom Global
|
@@ -28,6 +26,15 @@ require 'rom/container'
|
|
28
26
|
# container factory
|
29
27
|
require 'rom/create_container'
|
30
28
|
|
29
|
+
# register known plugin types
|
30
|
+
require 'rom/schema_plugin'
|
31
|
+
|
32
|
+
ROM::Plugins.register(:command)
|
33
|
+
ROM::Plugins.register(:mapper)
|
34
|
+
ROM::Plugins.register(:relation)
|
35
|
+
ROM::Plugins.register(:schema, plugin_type: ROM::SchemaPlugin)
|
36
|
+
ROM::Plugins.register(:configuration, adapter: false)
|
37
|
+
|
31
38
|
# register core plugins
|
32
39
|
require 'rom/plugins/relation/registry_reader'
|
33
40
|
require 'rom/plugins/relation/instrumentation'
|
@@ -39,7 +46,6 @@ module ROM
|
|
39
46
|
extend Global
|
40
47
|
|
41
48
|
plugins do
|
42
|
-
register :mappers, ROM::Mapper::ConfigurationPlugin, type: :configuration
|
43
49
|
register :timestamps, ROM::Plugins::Schema::Timestamps, type: :schema
|
44
50
|
register :registry_reader, ROM::Plugins::Relation::RegistryReader, type: :relation
|
45
51
|
register :instrumentation, ROM::Plugins::Relation::Instrumentation, type: :relation
|
data/lib/rom/mapper.rb
CHANGED
data/lib/rom/mapper/dsl.rb
CHANGED
@@ -40,7 +40,7 @@ module ROM
|
|
40
40
|
def use(plugin, options = {})
|
41
41
|
adapter = options.fetch(:adapter, :default)
|
42
42
|
|
43
|
-
ROM.plugin_registry.
|
43
|
+
ROM.plugin_registry[:mapper].fetch(plugin, adapter).apply_to(self)
|
44
44
|
end
|
45
45
|
|
46
46
|
# Return base_relation used for creating mapper registry
|
data/lib/rom/plugin.rb
CHANGED
@@ -1,26 +1,44 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'rom/initializer'
|
3
4
|
require 'rom/constants'
|
4
|
-
require 'rom/plugin_base'
|
5
5
|
require 'rom/support/configurable'
|
6
6
|
|
7
7
|
module ROM
|
8
8
|
# Plugin is a simple object used to store plugin configurations
|
9
9
|
#
|
10
10
|
# @private
|
11
|
-
class Plugin
|
11
|
+
class Plugin
|
12
|
+
extend Initializer
|
12
13
|
include Configurable
|
13
14
|
|
14
|
-
#
|
15
|
+
# @!attribute [r] name
|
16
|
+
# @return [Symbol] plugin name
|
17
|
+
# @api private
|
18
|
+
param :name
|
19
|
+
|
20
|
+
# @!attribute [r] mod
|
21
|
+
# @return [Module] a module representing the plugin
|
22
|
+
# @api private
|
23
|
+
param :mod
|
24
|
+
|
25
|
+
# @!attribute [r] type
|
26
|
+
# @return [Symbol] plugin type
|
27
|
+
# @api private
|
28
|
+
option :type
|
29
|
+
|
30
|
+
# Apply this plugin to the target
|
15
31
|
#
|
16
|
-
# @param [Class]
|
32
|
+
# @param [Class,Object] target
|
17
33
|
#
|
18
34
|
# @api private
|
19
|
-
def apply_to(
|
20
|
-
if mod.respond_to?(:
|
21
|
-
|
22
|
-
|
23
|
-
|
35
|
+
def apply_to(target, options = EMPTY_HASH)
|
36
|
+
if mod.respond_to?(:apply)
|
37
|
+
mod.apply(target, options)
|
38
|
+
elsif mod.respond_to?(:new)
|
39
|
+
target.include(mod.new(options))
|
40
|
+
elsif target.is_a?(::Module)
|
41
|
+
target.include(mod)
|
24
42
|
end
|
25
43
|
end
|
26
44
|
end
|
data/lib/rom/plugin_registry.rb
CHANGED
@@ -1,54 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'concurrent/map'
|
3
4
|
require 'rom/registry'
|
5
|
+
require 'rom/plugins'
|
4
6
|
|
5
7
|
module ROM
|
6
8
|
# Stores all registered plugins
|
7
9
|
#
|
8
10
|
# @api private
|
9
11
|
class PluginRegistry
|
10
|
-
# Internal registry for configuration plugins
|
11
|
-
#
|
12
|
-
# @return [ConfigurationPluginRegistry]
|
13
|
-
#
|
14
|
-
# @api private
|
15
|
-
attr_reader :configuration
|
16
|
-
|
17
|
-
# Internal registry for command plugins
|
18
|
-
#
|
19
|
-
# @return [InternalPluginRegistry]
|
20
|
-
#
|
21
|
-
# @api private
|
22
|
-
attr_reader :commands
|
23
|
-
|
24
|
-
# Internal registry for mapper plugins
|
25
|
-
#
|
26
|
-
# @return [InternalPluginRegistry]
|
27
|
-
#
|
28
|
-
# @api private
|
29
|
-
attr_reader :mappers
|
30
|
-
|
31
|
-
# Internal registry for relation plugins
|
32
|
-
#
|
33
|
-
# @return [InternalPluginRegistry]
|
34
|
-
#
|
35
12
|
# @api private
|
36
|
-
attr_reader :
|
37
|
-
|
38
|
-
# Internal registry for schema plugins
|
39
|
-
#
|
40
|
-
# @return [InternalPluginRegistry]
|
41
|
-
#
|
42
|
-
# @api private
|
43
|
-
attr_reader :schemas
|
13
|
+
attr_reader :types
|
44
14
|
|
45
15
|
# @api private
|
46
16
|
def initialize
|
47
|
-
@
|
48
|
-
@mappers = InternalPluginRegistry.new
|
49
|
-
@commands = InternalPluginRegistry.new
|
50
|
-
@relations = InternalPluginRegistry.new
|
51
|
-
@schemas = InternalPluginRegistry.new(SchemaPlugin)
|
17
|
+
@types = ::Concurrent::Map.new
|
52
18
|
end
|
53
19
|
|
54
20
|
# Register a plugin for future use
|
@@ -61,24 +27,35 @@ module ROM
|
|
61
27
|
# @option options [Symbol] :adapter (:default) which adapter this plugin
|
62
28
|
# applies to. Leave blank for all adapters
|
63
29
|
def register(name, mod, options = EMPTY_HASH)
|
64
|
-
type
|
65
|
-
|
30
|
+
type(options.fetch(:type)).register(name, mod, options)
|
31
|
+
end
|
66
32
|
|
67
|
-
|
33
|
+
# @api private
|
34
|
+
def type(type)
|
35
|
+
types.fetch_or_store(type) do
|
36
|
+
if Plugins[type][:adapter]
|
37
|
+
AdapterPluginsContainer.new(type)
|
38
|
+
else
|
39
|
+
PluginsContainer.new({}, type: type)
|
40
|
+
end
|
41
|
+
end
|
68
42
|
end
|
69
43
|
|
70
|
-
private
|
44
|
+
# @api private
|
45
|
+
def [](type)
|
46
|
+
types.fetch(singularize(type))
|
47
|
+
end
|
71
48
|
|
72
|
-
#
|
49
|
+
# Old API compatibility
|
73
50
|
#
|
74
51
|
# @api private
|
75
|
-
def
|
52
|
+
def singularize(type)
|
76
53
|
case type
|
77
|
-
when :
|
78
|
-
when :
|
79
|
-
when :
|
80
|
-
when :
|
81
|
-
|
54
|
+
when :relations then :relation
|
55
|
+
when :commands then :command
|
56
|
+
when :mappers then :mapper
|
57
|
+
when :schemas then :schema
|
58
|
+
else type
|
82
59
|
end
|
83
60
|
end
|
84
61
|
end
|
@@ -86,23 +63,12 @@ module ROM
|
|
86
63
|
# Abstract registry defining common behaviour
|
87
64
|
#
|
88
65
|
# @api private
|
89
|
-
class
|
90
|
-
include Dry::Equalizer(:elements, :
|
66
|
+
class PluginsContainer < Registry
|
67
|
+
include Dry::Equalizer(:elements, :type)
|
91
68
|
|
92
69
|
# @!attribute [r] plugin_type
|
93
70
|
# @return [Class] Typically ROM::PluginBase or its descendant
|
94
|
-
option :
|
95
|
-
|
96
|
-
# Retrieve a registered plugin
|
97
|
-
#
|
98
|
-
# @param [Symbol] name The plugin to retrieve
|
99
|
-
#
|
100
|
-
# @return [Plugin]
|
101
|
-
#
|
102
|
-
# @api public
|
103
|
-
def [](name)
|
104
|
-
elements[name]
|
105
|
-
end
|
71
|
+
option :type
|
106
72
|
|
107
73
|
# Assign a plugin to this environment registry
|
108
74
|
#
|
@@ -112,52 +78,19 @@ module ROM
|
|
112
78
|
#
|
113
79
|
# @api private
|
114
80
|
def register(name, mod, options)
|
115
|
-
elements[name] = plugin_type.new(mod, options)
|
81
|
+
elements[name] = plugin_type.new(name, mod, options)
|
116
82
|
end
|
117
83
|
|
118
|
-
# Returns plugin name by instance
|
119
|
-
#
|
120
|
-
# @return [Symbol] Plugin name
|
121
|
-
#
|
122
84
|
# @api private
|
123
|
-
def
|
124
|
-
|
125
|
-
tuple[0] if tuple
|
85
|
+
def plugin_type
|
86
|
+
Plugins[type][:plugin_type]
|
126
87
|
end
|
127
88
|
end
|
128
89
|
|
129
|
-
# A registry storing environment specific plugins
|
130
|
-
#
|
131
|
-
# @api private
|
132
|
-
class ConfigurationPluginRegistry < PluginRegistryBase
|
133
|
-
# @api private
|
134
|
-
def initialize(*args, **kwargs)
|
135
|
-
super(*args, **kwargs, plugin_type: ConfigurationPlugin)
|
136
|
-
end
|
137
|
-
|
138
|
-
# Return an environment plugin
|
139
|
-
#
|
140
|
-
# @param [Symbol] name The name of the environment plugin
|
141
|
-
#
|
142
|
-
# @raise [UnknownPluginError] if no plugin is found with the given name
|
143
|
-
#
|
144
|
-
# @api public
|
145
|
-
def fetch(name)
|
146
|
-
self[name] || raise(UnknownPluginError, name)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
# A registry storing adapter specific plugins
|
151
|
-
#
|
152
|
-
# @api private
|
153
|
-
class AdapterPluginRegistry < PluginRegistryBase
|
154
|
-
option :plugin_type, default: -> { Plugin }
|
155
|
-
end
|
156
|
-
|
157
90
|
# Store a set of registries grouped by adapter
|
158
91
|
#
|
159
92
|
# @api private
|
160
|
-
class
|
93
|
+
class AdapterPluginsContainer
|
161
94
|
# Return the existing registries
|
162
95
|
#
|
163
96
|
# @return [Hash]
|
@@ -166,8 +99,12 @@ module ROM
|
|
166
99
|
attr_reader :registries
|
167
100
|
|
168
101
|
# @api private
|
169
|
-
|
170
|
-
|
102
|
+
attr_reader :type
|
103
|
+
|
104
|
+
# @api private
|
105
|
+
def initialize(type)
|
106
|
+
@registries = ::Hash.new { |h, v| h[v] = PluginsContainer.new({}, type: type) }
|
107
|
+
@type = type
|
171
108
|
end
|
172
109
|
|
173
110
|
# Return the plugin registry for a specific adapter
|
@@ -181,6 +118,11 @@ module ROM
|
|
181
118
|
registries[name]
|
182
119
|
end
|
183
120
|
|
121
|
+
# @api private
|
122
|
+
def register(name, mod, options)
|
123
|
+
adapter(options.fetch(:adapter, :default)).register(name, mod, options)
|
124
|
+
end
|
125
|
+
|
184
126
|
# Return the plugin for a given adapter
|
185
127
|
#
|
186
128
|
# @param [Symbol] name The name of the plugin
|
@@ -190,8 +132,11 @@ module ROM
|
|
190
132
|
#
|
191
133
|
# @api public
|
192
134
|
def fetch(name, adapter_name = :default)
|
193
|
-
adapter(adapter_name)
|
194
|
-
|
135
|
+
adapter(adapter_name).fetch(name) do
|
136
|
+
adapter(:default).fetch(name) do
|
137
|
+
raise(UnknownPluginError, name)
|
138
|
+
end
|
139
|
+
end
|
195
140
|
end
|
196
141
|
|
197
142
|
alias_method :[], :fetch
|
data/lib/rom/plugins.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry/container'
|
4
|
+
require 'rom/plugin'
|
5
|
+
|
6
|
+
module ROM
|
7
|
+
# Registry of all known plugin types (command, relation, mapper, etc)
|
8
|
+
#
|
9
|
+
# @api private
|
10
|
+
module Plugins
|
11
|
+
extend ::Dry::Container::Mixin
|
12
|
+
|
13
|
+
class << self
|
14
|
+
# @api private
|
15
|
+
def register(entity_type, plugin_type: Plugin, adapter: true)
|
16
|
+
super(entity_type, plugin_type: plugin_type, adapter: adapter)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/rom/registry.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'dry/equalizer'
|
4
|
+
require 'dry/core/cache'
|
5
|
+
require 'dry/core/class_builder'
|
4
6
|
|
5
7
|
require 'rom/initializer'
|
6
8
|
require 'rom/cache'
|
@@ -10,6 +12,7 @@ module ROM
|
|
10
12
|
# @api private
|
11
13
|
class Registry
|
12
14
|
extend Initializer
|
15
|
+
extend Dry::Core::Cache
|
13
16
|
|
14
17
|
include Enumerable
|
15
18
|
include Dry::Equalizer(:elements)
|
@@ -34,6 +37,15 @@ module ROM
|
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
40
|
+
# @api private
|
41
|
+
def self.[](identifier)
|
42
|
+
fetch_or_store(identifier) do
|
43
|
+
Dry::Core::ClassBuilder
|
44
|
+
.new(parent: self, name: "#{name}[:#{identifier}]")
|
45
|
+
.call
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
37
49
|
# @api private
|
38
50
|
def self.element_not_found_error
|
39
51
|
ElementNotFoundError
|
@@ -80,6 +92,10 @@ module ROM
|
|
80
92
|
end
|
81
93
|
alias_method :[], :fetch
|
82
94
|
|
95
|
+
def type
|
96
|
+
self.class.name
|
97
|
+
end
|
98
|
+
|
83
99
|
# @api private
|
84
100
|
def respond_to_missing?(name, include_private = false)
|
85
101
|
elements.key?(name) || super
|
@@ -249,7 +249,7 @@ module ROM
|
|
249
249
|
#
|
250
250
|
# @api public
|
251
251
|
def use(plugin, options = EMPTY_HASH)
|
252
|
-
ROM.plugin_registry.
|
252
|
+
ROM.plugin_registry[:relation].fetch(plugin, adapter).apply_to(self, options)
|
253
253
|
end
|
254
254
|
|
255
255
|
# Build default mapper registry
|
@@ -22,7 +22,7 @@ module ROM
|
|
22
22
|
# @api public
|
23
23
|
def self.new(relation, nodes)
|
24
24
|
struct_ns = relation.options[:struct_namespace]
|
25
|
-
new_nodes = nodes.map { |node| node.struct_namespace(struct_ns) }
|
25
|
+
new_nodes = nodes.uniq.map { |node| node.struct_namespace(struct_ns) }
|
26
26
|
|
27
27
|
root =
|
28
28
|
if relation.is_a?(self)
|
@@ -19,7 +19,7 @@ module ROM
|
|
19
19
|
# users.command(:create, result: many)
|
20
20
|
#
|
21
21
|
# @example build a command which uses a specific plugin
|
22
|
-
# users.command(:create,
|
22
|
+
# users.command(:create, use: :timestamps)
|
23
23
|
#
|
24
24
|
# @example build a command which sends results through a custom mapper
|
25
25
|
# users.command(:create, mapper: :my_mapper_identifier)
|
data/lib/rom/schema/dsl.rb
CHANGED
@@ -165,20 +165,19 @@ module ROM
|
|
165
165
|
|
166
166
|
# Enables for the schema
|
167
167
|
#
|
168
|
-
# @param [Symbol]
|
168
|
+
# @param [Symbol] plugin_name Plugin name
|
169
169
|
# @param [Hash] options Plugin options
|
170
170
|
#
|
171
171
|
# @api public
|
172
|
-
def use(
|
173
|
-
|
174
|
-
app_plugin(
|
172
|
+
def use(plugin_name, options = ::ROM::EMPTY_HASH)
|
173
|
+
plugin = ::ROM.plugin_registry[:schema].fetch(plugin_name, adapter)
|
174
|
+
app_plugin(plugin, options)
|
175
175
|
end
|
176
176
|
|
177
177
|
# @api private
|
178
178
|
def app_plugin(plugin, options = ::ROM::EMPTY_HASH)
|
179
|
-
plugin_name = ::ROM.plugin_registry.schemas.adapter(adapter).plugin_name(plugin)
|
180
179
|
plugin.extend_dsl(self)
|
181
|
-
@plugins[
|
180
|
+
@plugins[plugin.name] = [plugin, plugin.config.to_hash.merge(options)]
|
182
181
|
end
|
183
182
|
|
184
183
|
# @api private
|
@@ -187,9 +186,9 @@ module ROM
|
|
187
186
|
instance_exec(&definition) if definition
|
188
187
|
|
189
188
|
schema_class.define(relation, opts) do |schema|
|
190
|
-
plugins.values.each
|
189
|
+
plugins.values.each do |plugin, options|
|
191
190
|
plugin.apply_to(schema, options)
|
192
|
-
|
191
|
+
end
|
193
192
|
end
|
194
193
|
end
|
195
194
|
|
data/lib/rom/schema_plugin.rb
CHANGED
@@ -1,22 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'rom/
|
3
|
+
require 'rom/plugin'
|
4
4
|
|
5
5
|
module ROM
|
6
6
|
# @api private
|
7
|
-
class SchemaPlugin <
|
8
|
-
include Configurable
|
9
|
-
|
10
|
-
# Apply this plugin to the provided configuration
|
11
|
-
#
|
12
|
-
# @param [ROM::Schema] schema A schema instance for extension
|
13
|
-
# @param [Hash] options Extension options
|
14
|
-
#
|
15
|
-
# @api private
|
16
|
-
def apply_to(schema, options = EMPTY_HASH)
|
17
|
-
mod.apply(schema, options) if mod.respond_to?(:apply)
|
18
|
-
end
|
19
|
-
|
7
|
+
class SchemaPlugin < Plugin
|
20
8
|
# Extends a DSL instance with a module provided by the plugin
|
21
9
|
#
|
22
10
|
# @param [ROM::Schema::DSL] dsl
|
data/lib/rom/setup/finalize.rb
CHANGED
@@ -126,12 +126,12 @@ module ROM
|
|
126
126
|
|
127
127
|
# @api private
|
128
128
|
def relation_plugins
|
129
|
-
@plugins.select
|
129
|
+
@plugins.select { |p| p.type == :relation }
|
130
130
|
end
|
131
131
|
|
132
132
|
# @api private
|
133
133
|
def schema_plugins
|
134
|
-
@plugins.select
|
134
|
+
@plugins.select { |p| p.type == :schema }
|
135
135
|
end
|
136
136
|
|
137
137
|
# @api private
|
data/lib/rom/transformer.rb
CHANGED
@@ -13,7 +13,68 @@ module ROM
|
|
13
13
|
class Transformer < Transproc::Transformer[ROM::Processor::Transproc::Functions]
|
14
14
|
extend Dry::Core::ClassAttributes
|
15
15
|
|
16
|
-
|
16
|
+
# @!method self.register_as
|
17
|
+
# Get or set registration name
|
18
|
+
#
|
19
|
+
# @overload register_as
|
20
|
+
# Return the registration name
|
21
|
+
# @return [Symbol]
|
22
|
+
#
|
23
|
+
# @overload register_as(name)
|
24
|
+
# Configure registration name
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# class MyMapper < ROM::Transformer
|
28
|
+
# relation :users
|
29
|
+
# register_as :my_mapper
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# @param name [Symbol] The registration name
|
33
|
+
defines :register_as
|
34
|
+
|
35
|
+
# Configure relation for the transformer
|
36
|
+
#
|
37
|
+
# @example with a custom name
|
38
|
+
# class UsersMapper < ROM::Transformer
|
39
|
+
# relation :users, as: :json_serializer
|
40
|
+
#
|
41
|
+
# map do
|
42
|
+
# rename_keys user_id: :id
|
43
|
+
# deep_stringify_keys
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# users.map_with(:json_serializer)
|
48
|
+
#
|
49
|
+
# @param name [Symbol]
|
50
|
+
# @param options [Hash]
|
51
|
+
# @option options :as [Symbol] Mapper identifier
|
52
|
+
#
|
53
|
+
# @api public
|
54
|
+
def self.relation(name = Undefined, options = EMPTY_HASH)
|
55
|
+
return @relation if name.equal?(Undefined) && defined?(@relation)
|
56
|
+
register_as(options.fetch(:as, name))
|
57
|
+
@relation = name
|
58
|
+
end
|
59
|
+
|
60
|
+
# Define transformation pipeline
|
61
|
+
#
|
62
|
+
# @example
|
63
|
+
# class UsersMapper < ROM::Transformer
|
64
|
+
# map do
|
65
|
+
# rename_keys user_id: :id
|
66
|
+
# deep_stringify_keys
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# @return [self]
|
71
|
+
#
|
72
|
+
# @api public
|
73
|
+
def self.map(&block)
|
74
|
+
define! do
|
75
|
+
map_array(&block)
|
76
|
+
end
|
77
|
+
end
|
17
78
|
|
18
79
|
# This is needed to make transformers compatible with rom setup
|
19
80
|
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -135,6 +135,9 @@ dependencies:
|
|
135
135
|
- - "~>"
|
136
136
|
- !ruby/object:Gem::Version
|
137
137
|
version: '1.0'
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 1.1.0
|
138
141
|
type: :runtime
|
139
142
|
prerelease: false
|
140
143
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -142,6 +145,9 @@ dependencies:
|
|
142
145
|
- - "~>"
|
143
146
|
- !ruby/object:Gem::Version
|
144
147
|
version: '1.0'
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 1.1.0
|
145
151
|
- !ruby/object:Gem::Dependency
|
146
152
|
name: rake
|
147
153
|
requirement: !ruby/object:Gem::Requirement
|
@@ -220,11 +226,12 @@ files:
|
|
220
226
|
- lib/rom/configuration_dsl.rb
|
221
227
|
- lib/rom/configuration_dsl/command.rb
|
222
228
|
- lib/rom/configuration_dsl/command_dsl.rb
|
229
|
+
- lib/rom/configuration_dsl/mapper_dsl.rb
|
223
230
|
- lib/rom/configuration_dsl/relation.rb
|
224
|
-
- lib/rom/configuration_plugin.rb
|
225
231
|
- lib/rom/constants.rb
|
226
232
|
- lib/rom/container.rb
|
227
233
|
- lib/rom/core.rb
|
234
|
+
- lib/rom/core/version.rb
|
228
235
|
- lib/rom/create_container.rb
|
229
236
|
- lib/rom/data_proxy.rb
|
230
237
|
- lib/rom/enumerable_dataset.rb
|
@@ -243,9 +250,7 @@ files:
|
|
243
250
|
- lib/rom/mapper.rb
|
244
251
|
- lib/rom/mapper/attribute_dsl.rb
|
245
252
|
- lib/rom/mapper/builder.rb
|
246
|
-
- lib/rom/mapper/configuration_plugin.rb
|
247
253
|
- lib/rom/mapper/dsl.rb
|
248
|
-
- lib/rom/mapper/mapper_dsl.rb
|
249
254
|
- lib/rom/mapper/model_dsl.rb
|
250
255
|
- lib/rom/mapper_compiler.rb
|
251
256
|
- lib/rom/mapper_registry.rb
|
@@ -267,8 +272,8 @@ files:
|
|
267
272
|
- lib/rom/open_struct.rb
|
268
273
|
- lib/rom/pipeline.rb
|
269
274
|
- lib/rom/plugin.rb
|
270
|
-
- lib/rom/plugin_base.rb
|
271
275
|
- lib/rom/plugin_registry.rb
|
276
|
+
- lib/rom/plugins.rb
|
272
277
|
- lib/rom/plugins/command/schema.rb
|
273
278
|
- lib/rom/plugins/command/timestamps.rb
|
274
279
|
- lib/rom/plugins/relation/instrumentation.rb
|
@@ -314,11 +319,14 @@ files:
|
|
314
319
|
- lib/rom/transaction.rb
|
315
320
|
- lib/rom/transformer.rb
|
316
321
|
- lib/rom/types.rb
|
317
|
-
- lib/rom/version.rb
|
318
322
|
homepage: http://rom-rb.org
|
319
323
|
licenses:
|
320
324
|
- MIT
|
321
|
-
metadata:
|
325
|
+
metadata:
|
326
|
+
source_code_uri: https://github.com/rom-rb/rom/tree/master/core
|
327
|
+
documentation_uri: https://api.rom-rb.org/rom/
|
328
|
+
mailing_list_uri: https://discourse.rom-rb.org/
|
329
|
+
bug_tracker_uri: https://github.com/rom-rb/rom/issues
|
322
330
|
post_install_message:
|
323
331
|
rdoc_options: []
|
324
332
|
require_paths:
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rom/plugin_base'
|
4
|
-
|
5
|
-
module ROM
|
6
|
-
# ConfigurationPlugin is a simple object used to store configuration plugin configurations
|
7
|
-
#
|
8
|
-
# @private
|
9
|
-
class ConfigurationPlugin < PluginBase
|
10
|
-
# Apply this plugin to the provided configuration
|
11
|
-
#
|
12
|
-
# @param [ROM::Configuration] configuration
|
13
|
-
#
|
14
|
-
# @api private
|
15
|
-
def apply_to(configuration, options = {})
|
16
|
-
mod.apply(configuration, options)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rom/mapper/mapper_dsl'
|
4
|
-
|
5
|
-
module ROM
|
6
|
-
class Mapper
|
7
|
-
# Model DSL allows setting a model class
|
8
|
-
#
|
9
|
-
# @private
|
10
|
-
module ConfigurationPlugin
|
11
|
-
# Mapper definition DSL used by Setup DSL
|
12
|
-
#
|
13
|
-
# @private
|
14
|
-
|
15
|
-
def self.apply(configuration, options = {})
|
16
|
-
configuration.extend Methods
|
17
|
-
configuration
|
18
|
-
end
|
19
|
-
|
20
|
-
module Methods
|
21
|
-
def mappers(&block)
|
22
|
-
register_mapper(*MapperDSL.new(self, mapper_classes, block).mapper_classes)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/lib/rom/plugin_base.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ROM
|
4
|
-
# Abstract plugin base
|
5
|
-
#
|
6
|
-
# @private
|
7
|
-
class PluginBase
|
8
|
-
# @return [Module] a module representing the plugin
|
9
|
-
#
|
10
|
-
# @api private
|
11
|
-
attr_reader :mod
|
12
|
-
|
13
|
-
# @return [Hash] configuration options
|
14
|
-
#
|
15
|
-
# @api private
|
16
|
-
attr_reader :options
|
17
|
-
|
18
|
-
# @api private
|
19
|
-
attr_reader :type
|
20
|
-
|
21
|
-
# @api private
|
22
|
-
def initialize(mod, options)
|
23
|
-
@mod = mod
|
24
|
-
@options = options
|
25
|
-
@type = options.fetch(:type)
|
26
|
-
end
|
27
|
-
|
28
|
-
# @api private
|
29
|
-
def relation?
|
30
|
-
type == :relation
|
31
|
-
end
|
32
|
-
|
33
|
-
# @api private
|
34
|
-
def schema?
|
35
|
-
type == :schema
|
36
|
-
end
|
37
|
-
|
38
|
-
# Apply this plugin to the provided class
|
39
|
-
#
|
40
|
-
# @param [Mixed] _base
|
41
|
-
#
|
42
|
-
# @api private
|
43
|
-
def apply_to(_base)
|
44
|
-
raise NotImplementedError, "#{self.class}#apply_to not implemented"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|