rom 0.8.1 → 0.9.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +5 -1
- data/lib/rom.rb +35 -16
- data/lib/rom/command.rb +1 -9
- data/lib/rom/commands/graph/class_interface.rb +2 -2
- data/lib/rom/constants.rb +0 -6
- data/lib/rom/{env.rb → container.rb} +3 -3
- data/lib/rom/environment.rb +238 -0
- data/lib/rom/environment_plugin.rb +17 -0
- data/lib/rom/environment_plugins/auto_registration.rb +17 -0
- data/lib/rom/global.rb +0 -203
- data/lib/rom/mapper_registry.rb +2 -0
- data/lib/rom/pipeline.rb +2 -0
- data/lib/rom/plugin.rb +4 -18
- data/lib/rom/plugin_base.rb +31 -0
- data/lib/rom/plugin_registry.rb +54 -17
- data/lib/rom/relation.rb +54 -11
- data/lib/rom/relation/class_interface.rb +14 -21
- data/lib/rom/relation/curried.rb +36 -2
- data/lib/rom/relation/graph.rb +7 -0
- data/lib/rom/relation_registry.rb +4 -0
- data/lib/rom/setup.rb +9 -8
- data/lib/rom/setup/finalize.rb +5 -5
- data/lib/rom/version.rb +1 -1
- data/rom.gemspec +2 -0
- data/spec/integration/commands/create_spec.rb +1 -1
- data/spec/integration/commands/update_spec.rb +1 -1
- data/spec/integration/mappers/unwrap_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/rom/{env_spec.rb → container_spec.rb} +5 -5
- data/spec/unit/rom/plugin_spec.rb +0 -8
- data/spec/unit/rom/relation/composite_spec.rb +2 -2
- data/spec/unit/rom/relation/curried_spec.rb +53 -0
- data/spec/unit/rom/relation/graph_spec.rb +4 -0
- data/spec/unit/rom/relation/lazy/combine_spec.rb +6 -6
- data/spec/unit/rom/relation/lazy_spec.rb +4 -8
- data/spec/unit/rom/relation_spec.rb +0 -14
- data/spec/unit/rom/setup_spec.rb +1 -1
- metadata +52 -35
- data/lib/rom/header.rb +0 -193
- data/lib/rom/header/attribute.rb +0 -184
- data/lib/rom/mapper.rb +0 -103
- data/lib/rom/mapper/attribute_dsl.rb +0 -477
- data/lib/rom/mapper/dsl.rb +0 -119
- data/lib/rom/mapper/model_dsl.rb +0 -55
- data/lib/rom/model_builder.rb +0 -101
- data/lib/rom/processor.rb +0 -28
- data/lib/rom/processor/transproc.rb +0 -388
- data/lib/rom/relation/lazy.rb +0 -145
- data/lib/rom/support/array_dataset.rb +0 -41
- data/lib/rom/support/class_builder.rb +0 -44
- data/lib/rom/support/class_macros.rb +0 -56
- data/lib/rom/support/data_proxy.rb +0 -102
- data/lib/rom/support/deprecations.rb +0 -36
- data/lib/rom/support/enumerable_dataset.rb +0 -65
- data/lib/rom/support/inflector.rb +0 -73
- data/lib/rom/support/options.rb +0 -195
- data/lib/rom/support/registry.rb +0 -43
- data/spec/unit/rom/header_spec.rb +0 -102
- data/spec/unit/rom/mapper/dsl_spec.rb +0 -467
- data/spec/unit/rom/mapper_spec.rb +0 -84
- data/spec/unit/rom/model_builder_spec.rb +0 -46
- data/spec/unit/rom/processor/transproc_spec.rb +0 -448
- data/spec/unit/rom/support/array_dataset_spec.rb +0 -61
- data/spec/unit/rom/support/class_builder_spec.rb +0 -42
- data/spec/unit/rom/support/enumerable_dataset_spec.rb +0 -17
- data/spec/unit/rom/support/inflector_spec.rb +0 -89
- data/spec/unit/rom/support/options_spec.rb +0 -119
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae4a8d67f3c8c7869c5eafa16d721cc6c4ba90eb
|
4
|
+
data.tar.gz: d2c9c1cdcde7ade22ad695dea60bea91a05bea42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8c3ba712a476f5f326863890e3e4abc42154601501595fb44e321854610ee4fed2d047b6d4c15b56be746c322d641f48f72f1ade653fc96ae547e6370218bef
|
7
|
+
data.tar.gz: 728ea3d960c3f18e0e314706dd90e6f35e32aa5014755a0875ba0a1613caa29358cad2af2fe7bc2c2b55f7d7fdccc780b60d9be89b297da7a3550440dc9784b0
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -21,9 +21,13 @@ full power of your datastore.
|
|
21
21
|
Learn more:
|
22
22
|
|
23
23
|
* [Introduction](http://rom-rb.org/introduction/)
|
24
|
-
* [Guides](http://rom-rb.org/
|
24
|
+
* [Guides](http://rom-rb.org/guides/)
|
25
25
|
* [Tutorials](http://rom-rb.org/tutorials/)
|
26
26
|
|
27
|
+
## Support Campaign
|
28
|
+
|
29
|
+
You can support ROM's development via our [campaign on Bountysource](https://salt.bountysource.com/teams/rom-rb). Cheers!
|
30
|
+
|
27
31
|
## Adapters
|
28
32
|
|
29
33
|
* [rom-sql](https://github.com/rom-rb/rom-sql)
|
data/lib/rom.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'equalizer'
|
2
2
|
|
3
|
+
require 'rom-support'
|
3
4
|
require 'rom/version'
|
4
5
|
require 'rom/constants'
|
5
6
|
|
@@ -9,35 +10,53 @@ require 'rom/support/registry'
|
|
9
10
|
require 'rom/support/options'
|
10
11
|
require 'rom/support/class_macros'
|
11
12
|
require 'rom/support/class_builder'
|
13
|
+
require 'rom/support/guarded_inheritance_hook'
|
14
|
+
require 'rom/support/inheritance_hook'
|
12
15
|
|
13
16
|
# core parts
|
17
|
+
require 'rom/environment_plugin'
|
14
18
|
require 'rom/plugin'
|
15
19
|
require 'rom/relation'
|
16
|
-
require 'rom
|
20
|
+
require 'rom-mapper'
|
17
21
|
require 'rom/commands'
|
18
22
|
|
19
|
-
#
|
20
|
-
require 'rom/processor/transproc'
|
21
|
-
|
22
|
-
# support for global-style setup
|
23
|
+
# rom Global
|
23
24
|
require 'rom/global'
|
24
|
-
|
25
|
+
|
26
|
+
# rom environments
|
27
|
+
require 'rom/environment'
|
25
28
|
|
26
29
|
# TODO: consider to make this part optional and don't require it here
|
27
30
|
require 'rom/setup_dsl/setup'
|
28
31
|
|
29
|
-
#
|
30
|
-
require 'rom/
|
31
|
-
|
32
|
-
module ROM
|
33
|
-
extend Global
|
34
|
-
|
35
|
-
RelationRegistry = Class.new(Registry)
|
36
|
-
end
|
32
|
+
# container with registries
|
33
|
+
require 'rom/container'
|
37
34
|
|
38
35
|
# register core plugins
|
36
|
+
require 'rom/environment_plugins/auto_registration'
|
39
37
|
require 'rom/plugins/relation/registry_reader'
|
40
38
|
|
41
|
-
ROM
|
42
|
-
|
39
|
+
module ROM
|
40
|
+
extend Global
|
41
|
+
|
42
|
+
@environment = ROM::Environment.new
|
43
|
+
|
44
|
+
class << self
|
45
|
+
def method_missing(method, *args, &block)
|
46
|
+
if @environment.respond_to?(method)
|
47
|
+
@environment.__send__(method, *args, &block)
|
48
|
+
else
|
49
|
+
super
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def respond_to_missing?(method, _include_private = false)
|
54
|
+
@environment.respond_to?(method) || super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
plugins do
|
59
|
+
register :auto_registration, ROM::EnvironmentPlugins::AutoRegistration, type: :environment
|
60
|
+
register :registry_reader, ROM::Plugins::Relation::RegistryReader, type: :relation
|
61
|
+
end
|
43
62
|
end
|
data/lib/rom/command.rb
CHANGED
@@ -6,6 +6,7 @@ module ROM
|
|
6
6
|
# @private
|
7
7
|
class Command < Commands::Abstract
|
8
8
|
extend ClassMacros
|
9
|
+
extend ROM::Support::GuardedInheritanceHook
|
9
10
|
|
10
11
|
include Equalizer.new(:relation, :options)
|
11
12
|
|
@@ -15,15 +16,6 @@ module ROM
|
|
15
16
|
validator proc {}
|
16
17
|
result :many
|
17
18
|
|
18
|
-
# Registers Create/Update/Delete descendant classes during the setup phase
|
19
|
-
#
|
20
|
-
# @api private
|
21
|
-
def self.inherited(klass)
|
22
|
-
super
|
23
|
-
return if klass.superclass == ROM::Command
|
24
|
-
ROM.register_command(klass)
|
25
|
-
end
|
26
|
-
|
27
19
|
# Return adapter specific sub-class based on the adapter identifier
|
28
20
|
#
|
29
21
|
# This is a syntax sugar to make things consistent
|
@@ -7,9 +7,9 @@ module ROM
|
|
7
7
|
module ClassInterface
|
8
8
|
# Build a command graph recursively
|
9
9
|
#
|
10
|
-
# This is used by `
|
10
|
+
# This is used by `Container#command` when array with options is passed in
|
11
11
|
#
|
12
|
-
# @param [Registry] registry The command registry from
|
12
|
+
# @param [Registry] registry The command registry from container
|
13
13
|
# @param [Array] options The options array
|
14
14
|
# @param [Array] path The path for input evaluator proc
|
15
15
|
#
|
data/lib/rom/constants.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# Constants and errors common in the whole library
|
2
2
|
module ROM
|
3
|
-
Undefined = Object.new.freeze
|
4
|
-
|
5
3
|
AdapterLoadError = Class.new(StandardError)
|
6
4
|
|
7
5
|
class AdapterNotPresentError < StandardError
|
@@ -19,7 +17,6 @@ module ROM
|
|
19
17
|
CommandError = Class.new(StandardError)
|
20
18
|
TupleCountMismatchError = Class.new(CommandError)
|
21
19
|
MapperMissingError = Class.new(StandardError)
|
22
|
-
MapperMisconfiguredError = Class.new(StandardError)
|
23
20
|
UnknownPluginError = Class.new(StandardError)
|
24
21
|
UnsupportedRelationError = Class.new(StandardError)
|
25
22
|
|
@@ -37,7 +34,4 @@ module ROM
|
|
37
34
|
set_backtrace(err.backtrace)
|
38
35
|
end
|
39
36
|
end
|
40
|
-
|
41
|
-
EMPTY_ARRAY = [].freeze
|
42
|
-
EMPTY_HASH = {}.freeze
|
43
37
|
end
|
@@ -6,7 +6,7 @@ module ROM
|
|
6
6
|
# Exposes defined gateways, relations and mappers
|
7
7
|
#
|
8
8
|
# @api public
|
9
|
-
class
|
9
|
+
class Container
|
10
10
|
extend Deprecations
|
11
11
|
include Equalizer.new(:gateways, :relations, :mappers, :commands)
|
12
12
|
|
@@ -72,9 +72,9 @@ module ROM
|
|
72
72
|
end
|
73
73
|
|
74
74
|
if mappers.key?(name)
|
75
|
-
relation.
|
75
|
+
relation.with(mappers: mappers[name])
|
76
76
|
else
|
77
|
-
relation
|
77
|
+
relation
|
78
78
|
end
|
79
79
|
end
|
80
80
|
deprecate :read, :relation, "For mapping append `.map_with(:your_mapper_name)`"
|
@@ -0,0 +1,238 @@
|
|
1
|
+
require 'rom/setup'
|
2
|
+
require 'rom/repository'
|
3
|
+
|
4
|
+
module ROM
|
5
|
+
# Globally accessible public interface exposed via ROM module
|
6
|
+
#
|
7
|
+
# @api public
|
8
|
+
class Environment
|
9
|
+
# An internal gateway => identifier map used by the setup
|
10
|
+
#
|
11
|
+
# @return [Hash]
|
12
|
+
#
|
13
|
+
# @api private
|
14
|
+
attr_reader :gateways
|
15
|
+
|
16
|
+
# Setup object created during setup phase
|
17
|
+
#
|
18
|
+
# This gets set to nil after setup is finalized
|
19
|
+
#
|
20
|
+
# @return [Setup]
|
21
|
+
#
|
22
|
+
# @api private
|
23
|
+
attr_reader :boot
|
24
|
+
|
25
|
+
# Return ROM container configured by the setup
|
26
|
+
#
|
27
|
+
# @return [Container]
|
28
|
+
#
|
29
|
+
# @api public
|
30
|
+
attr_reader :container
|
31
|
+
alias_method :env, :container
|
32
|
+
|
33
|
+
# @api private
|
34
|
+
def initialize
|
35
|
+
@gateways = {}
|
36
|
+
end
|
37
|
+
|
38
|
+
# @api private
|
39
|
+
def adapters
|
40
|
+
ROM.adapters
|
41
|
+
end
|
42
|
+
|
43
|
+
# @api private
|
44
|
+
def plugin_registry
|
45
|
+
ROM.plugin_registry
|
46
|
+
end
|
47
|
+
|
48
|
+
# Apply
|
49
|
+
#
|
50
|
+
# @api public
|
51
|
+
def use(plugin)
|
52
|
+
plugin_registry.environment.fetch(plugin).apply_to(self)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Starts the setup process for relations, mappers and commands.
|
56
|
+
#
|
57
|
+
# @overload setup(type, *args)
|
58
|
+
# Sets up a single-gateway environment given a gateway type provided
|
59
|
+
# under the ROM umbrella. For custom gateways, create an instance and
|
60
|
+
# pass it directly.
|
61
|
+
#
|
62
|
+
# @param [Symbol] type
|
63
|
+
# @param [Array] *args
|
64
|
+
#
|
65
|
+
# @overload setup(gateway)
|
66
|
+
# @param [Gateway] gateway
|
67
|
+
#
|
68
|
+
# @overload setup(gateways)
|
69
|
+
# Sets up multiple gateways.
|
70
|
+
#
|
71
|
+
# @param [Hash{Symbol=>Symbol,Array}] gateways
|
72
|
+
#
|
73
|
+
# @return [Setup] boot object
|
74
|
+
#
|
75
|
+
# @example
|
76
|
+
# # Use the in-memory adapter shipped with ROM as the default gateway.
|
77
|
+
# rom = ROM::Environment.new
|
78
|
+
# env = rom.setup(:memory, 'memory://test')
|
79
|
+
# # Use `rom-sql` with an in-memory sqlite database as default gateway.
|
80
|
+
# rom.setup(:sql, 'sqlite::memory')
|
81
|
+
# # Registers a `default` and a `warehouse` gateway.
|
82
|
+
# env = rom.setup(
|
83
|
+
# default: [:sql, 'sqlite::memory'],
|
84
|
+
# warehouse: [:sql, 'postgres://localhost/warehouse']
|
85
|
+
# )
|
86
|
+
#
|
87
|
+
# @example A full environment
|
88
|
+
#
|
89
|
+
# rom = ROM::Environment.new
|
90
|
+
# rom.setup(:memory, 'memory://test')
|
91
|
+
#
|
92
|
+
# rom.relation(:users) do
|
93
|
+
# # ...
|
94
|
+
# end
|
95
|
+
#
|
96
|
+
# rom.mappers do
|
97
|
+
# define(:users) do
|
98
|
+
# # ...
|
99
|
+
# end
|
100
|
+
# end
|
101
|
+
#
|
102
|
+
# rom.commands(:users) do
|
103
|
+
# define(:create) do
|
104
|
+
# # ...
|
105
|
+
# end
|
106
|
+
# end
|
107
|
+
#
|
108
|
+
# rom.finalize # builds the container
|
109
|
+
# rom.container # returns the container registry
|
110
|
+
#
|
111
|
+
# @api public
|
112
|
+
def setup(*args, &block)
|
113
|
+
config = setup_config(*args)
|
114
|
+
@boot = Setup.new(setup_gateways(config), adapters.keys.first)
|
115
|
+
|
116
|
+
if block
|
117
|
+
@boot.instance_exec(&block)
|
118
|
+
@boot.finalize
|
119
|
+
else
|
120
|
+
@boot
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# Global relation setup DSL
|
125
|
+
#
|
126
|
+
# @example
|
127
|
+
# rom = ROM::Environment.new
|
128
|
+
# rom.setup(:memory)
|
129
|
+
#
|
130
|
+
# rom.relation(:users) do
|
131
|
+
# def by_name(name)
|
132
|
+
# restrict(name: name)
|
133
|
+
# end
|
134
|
+
# end
|
135
|
+
#
|
136
|
+
# @api public
|
137
|
+
def relation(*args, &block)
|
138
|
+
boot.relation(*args, &block)
|
139
|
+
end
|
140
|
+
|
141
|
+
# Global commands setup DSL
|
142
|
+
#
|
143
|
+
# @example
|
144
|
+
# rom = ROM::Environment.new
|
145
|
+
# rom.setup(:memory)
|
146
|
+
#
|
147
|
+
# rom.commands(:users) do
|
148
|
+
# define(:create) do
|
149
|
+
# # ..
|
150
|
+
# end
|
151
|
+
# end
|
152
|
+
#
|
153
|
+
# @api public
|
154
|
+
def commands(*args, &block)
|
155
|
+
boot.commands(*args, &block)
|
156
|
+
end
|
157
|
+
|
158
|
+
# Global mapper setup DSL
|
159
|
+
#
|
160
|
+
# @example
|
161
|
+
# rom = ROM::Environment.new
|
162
|
+
# rom.setup(:memory)
|
163
|
+
#
|
164
|
+
# rom.mappers do
|
165
|
+
# define(:uses) do
|
166
|
+
# # ..
|
167
|
+
# end
|
168
|
+
# end
|
169
|
+
#
|
170
|
+
# @api public
|
171
|
+
def mappers(*args, &block)
|
172
|
+
boot.mappers(*args, &block)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Finalize the setup and store default global container under
|
176
|
+
# ROM::Environmrnt#container
|
177
|
+
#
|
178
|
+
# @example
|
179
|
+
# rom = ROM::Environment.new
|
180
|
+
# rom.setup(:memory)
|
181
|
+
# rom.finalize # => rom
|
182
|
+
# rom.boot # => nil
|
183
|
+
# rom.container # => the container
|
184
|
+
#
|
185
|
+
# @return [ROM]
|
186
|
+
#
|
187
|
+
# @api public
|
188
|
+
def finalize
|
189
|
+
@container = boot.finalize
|
190
|
+
self
|
191
|
+
ensure
|
192
|
+
@boot = nil
|
193
|
+
end
|
194
|
+
|
195
|
+
# Relation subclass registration during setup phase
|
196
|
+
#
|
197
|
+
# @api private
|
198
|
+
def register_relation(klass)
|
199
|
+
boot.register_relation(klass) if boot
|
200
|
+
end
|
201
|
+
|
202
|
+
# Mapper subclass registration during setup phase
|
203
|
+
#
|
204
|
+
# @api private
|
205
|
+
def register_mapper(klass)
|
206
|
+
boot.register_mapper(klass) if boot
|
207
|
+
end
|
208
|
+
|
209
|
+
# Command subclass registration during setup phase
|
210
|
+
#
|
211
|
+
# @api private
|
212
|
+
def register_command(klass)
|
213
|
+
boot.register_command(klass) if boot
|
214
|
+
end
|
215
|
+
|
216
|
+
private
|
217
|
+
|
218
|
+
# Helper method to handle single- or multi-repo setup options
|
219
|
+
#
|
220
|
+
# @api private
|
221
|
+
def setup_config(*args)
|
222
|
+
args.first.is_a?(Hash) ? args.first : { default: args }
|
223
|
+
end
|
224
|
+
|
225
|
+
# Build gateways using the setup interface
|
226
|
+
#
|
227
|
+
# @api private
|
228
|
+
def setup_gateways(config)
|
229
|
+
config.each_with_object({}) do |(name, spec), hash|
|
230
|
+
identifier, *args = Array(spec)
|
231
|
+
gateway = Gateway.setup(identifier, *(args.flatten))
|
232
|
+
hash[name] = gateway
|
233
|
+
|
234
|
+
gateways[gateway] = identifier unless identifier.is_a?(Gateway)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rom/plugin_base'
|
2
|
+
|
3
|
+
module ROM
|
4
|
+
# EnvironmentPlugin is a simple object used to store environment plugin configurations
|
5
|
+
#
|
6
|
+
# @private
|
7
|
+
class EnvironmentPlugin < PluginBase
|
8
|
+
# Apply this plugin to the provided environment
|
9
|
+
#
|
10
|
+
# @param [ROM::Environment] environment
|
11
|
+
#
|
12
|
+
# @api private
|
13
|
+
def apply_to(environment)
|
14
|
+
mod.apply(environment)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|