rom 2.0.2 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +35 -430
  3. data/LICENSE +1 -1
  4. data/README.md +83 -11
  5. data/lib/rom/version.rb +1 -1
  6. data/lib/rom.rb +3 -46
  7. metadata +30 -236
  8. data/.gitignore +0 -24
  9. data/.rspec +0 -3
  10. data/.rubocop.yml +0 -87
  11. data/.rubocop_todo.yml +0 -46
  12. data/.travis.yml +0 -28
  13. data/CODE_OF_CONDUCT.md +0 -13
  14. data/CONTRIBUTING.md +0 -1
  15. data/Gemfile +0 -41
  16. data/Guardfile +0 -24
  17. data/Rakefile +0 -22
  18. data/lib/rom/association_set.rb +0 -26
  19. data/lib/rom/command.rb +0 -173
  20. data/lib/rom/command_registry.rb +0 -153
  21. data/lib/rom/commands/class_interface.rb +0 -148
  22. data/lib/rom/commands/composite.rb +0 -54
  23. data/lib/rom/commands/create.rb +0 -13
  24. data/lib/rom/commands/delete.rb +0 -14
  25. data/lib/rom/commands/graph/builder.rb +0 -176
  26. data/lib/rom/commands/graph/class_interface.rb +0 -62
  27. data/lib/rom/commands/graph/input_evaluator.rb +0 -62
  28. data/lib/rom/commands/graph.rb +0 -103
  29. data/lib/rom/commands/lazy/create.rb +0 -23
  30. data/lib/rom/commands/lazy/delete.rb +0 -27
  31. data/lib/rom/commands/lazy/update.rb +0 -34
  32. data/lib/rom/commands/lazy.rb +0 -99
  33. data/lib/rom/commands/result.rb +0 -96
  34. data/lib/rom/commands/update.rb +0 -14
  35. data/lib/rom/commands.rb +0 -3
  36. data/lib/rom/configuration.rb +0 -88
  37. data/lib/rom/configuration_dsl/command.rb +0 -43
  38. data/lib/rom/configuration_dsl/command_dsl.rb +0 -35
  39. data/lib/rom/configuration_dsl/mapper.rb +0 -37
  40. data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -44
  41. data/lib/rom/configuration_dsl/relation.rb +0 -26
  42. data/lib/rom/configuration_dsl.rb +0 -78
  43. data/lib/rom/configuration_plugin.rb +0 -17
  44. data/lib/rom/constants.rb +0 -30
  45. data/lib/rom/container.rb +0 -231
  46. data/lib/rom/create_container.rb +0 -61
  47. data/lib/rom/environment.rb +0 -70
  48. data/lib/rom/gateway.rb +0 -154
  49. data/lib/rom/global/plugin_dsl.rb +0 -49
  50. data/lib/rom/global.rb +0 -60
  51. data/lib/rom/lint/enumerable_dataset.rb +0 -54
  52. data/lib/rom/lint/gateway.rb +0 -94
  53. data/lib/rom/lint/linter.rb +0 -78
  54. data/lib/rom/lint/spec.rb +0 -20
  55. data/lib/rom/lint/test.rb +0 -98
  56. data/lib/rom/mapper_registry.rb +0 -35
  57. data/lib/rom/memory/commands.rb +0 -58
  58. data/lib/rom/memory/dataset.rb +0 -98
  59. data/lib/rom/memory/gateway.rb +0 -64
  60. data/lib/rom/memory/relation.rb +0 -49
  61. data/lib/rom/memory/storage.rb +0 -59
  62. data/lib/rom/memory/types.rb +0 -9
  63. data/lib/rom/memory.rb +0 -4
  64. data/lib/rom/pipeline.rb +0 -106
  65. data/lib/rom/plugin.rb +0 -17
  66. data/lib/rom/plugin_base.rb +0 -31
  67. data/lib/rom/plugin_registry.rb +0 -173
  68. data/lib/rom/plugins/command/schema.rb +0 -37
  69. data/lib/rom/plugins/configuration/configuration_dsl.rb +0 -17
  70. data/lib/rom/plugins/relation/key_inference.rb +0 -46
  71. data/lib/rom/plugins/relation/registry_reader.rb +0 -32
  72. data/lib/rom/plugins/relation/view/dsl.rb +0 -32
  73. data/lib/rom/plugins/relation/view.rb +0 -95
  74. data/lib/rom/relation/class_interface.rb +0 -230
  75. data/lib/rom/relation/composite.rb +0 -46
  76. data/lib/rom/relation/curried.rb +0 -104
  77. data/lib/rom/relation/graph.rb +0 -115
  78. data/lib/rom/relation/loaded.rb +0 -118
  79. data/lib/rom/relation/materializable.rb +0 -66
  80. data/lib/rom/relation/name.rb +0 -102
  81. data/lib/rom/relation.rb +0 -172
  82. data/lib/rom/relation_registry.rb +0 -9
  83. data/lib/rom/schema/dsl.rb +0 -58
  84. data/lib/rom/schema.rb +0 -89
  85. data/lib/rom/setup/auto_registration.rb +0 -69
  86. data/lib/rom/setup/auto_registration_strategies/base.rb +0 -11
  87. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +0 -22
  88. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +0 -19
  89. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +0 -18
  90. data/lib/rom/setup/finalize/finalize_commands.rb +0 -47
  91. data/lib/rom/setup/finalize/finalize_mappers.rb +0 -36
  92. data/lib/rom/setup/finalize/finalize_relations.rb +0 -60
  93. data/lib/rom/setup/finalize.rb +0 -146
  94. data/lib/rom/setup.rb +0 -55
  95. data/lib/rom/support/configurable.rb +0 -80
  96. data/lib/rom/types.rb +0 -18
  97. data/log/.gitkeep +0 -0
  98. data/rakelib/benchmark.rake +0 -15
  99. data/rakelib/mutant.rake +0 -19
  100. data/rakelib/rubocop.rake +0 -18
  101. data/rom.gemspec +0 -26
  102. data/spec/fixtures/app/commands/create_user.rb +0 -2
  103. data/spec/fixtures/app/mappers/user_list.rb +0 -2
  104. data/spec/fixtures/app/my_commands/create_user.rb +0 -2
  105. data/spec/fixtures/app/my_mappers/user_list.rb +0 -2
  106. data/spec/fixtures/app/my_relations/users.rb +0 -2
  107. data/spec/fixtures/app/relations/users.rb +0 -2
  108. data/spec/fixtures/custom/commands/create_user.rb +0 -6
  109. data/spec/fixtures/custom/mappers/user_list.rb +0 -6
  110. data/spec/fixtures/custom/relations/users.rb +0 -6
  111. data/spec/fixtures/lib/persistence/commands/create_user.rb +0 -6
  112. data/spec/fixtures/lib/persistence/mappers/user_list.rb +0 -6
  113. data/spec/fixtures/lib/persistence/my_commands/create_user.rb +0 -6
  114. data/spec/fixtures/lib/persistence/my_mappers/user_list.rb +0 -6
  115. data/spec/fixtures/lib/persistence/my_relations/users.rb +0 -6
  116. data/spec/fixtures/lib/persistence/relations/users.rb +0 -6
  117. data/spec/integration/command_registry_spec.rb +0 -60
  118. data/spec/integration/commands/create_spec.rb +0 -177
  119. data/spec/integration/commands/delete_spec.rb +0 -67
  120. data/spec/integration/commands/error_handling_spec.rb +0 -25
  121. data/spec/integration/commands/graph_builder_spec.rb +0 -213
  122. data/spec/integration/commands/graph_spec.rb +0 -288
  123. data/spec/integration/commands/update_spec.rb +0 -109
  124. data/spec/integration/commands_spec.rb +0 -67
  125. data/spec/integration/mappers/combine_spec.rb +0 -117
  126. data/spec/integration/mappers/deep_embedded_spec.rb +0 -44
  127. data/spec/integration/mappers/definition_dsl_spec.rb +0 -206
  128. data/spec/integration/mappers/embedded_spec.rb +0 -62
  129. data/spec/integration/mappers/exclude_spec.rb +0 -27
  130. data/spec/integration/mappers/fold_spec.rb +0 -71
  131. data/spec/integration/mappers/group_spec.rb +0 -163
  132. data/spec/integration/mappers/overwrite_attributes_value_spec.rb +0 -51
  133. data/spec/integration/mappers/prefix_separator_spec.rb +0 -52
  134. data/spec/integration/mappers/prefix_spec.rb +0 -48
  135. data/spec/integration/mappers/prefixing_attributes_spec.rb +0 -37
  136. data/spec/integration/mappers/registering_custom_mappers_spec.rb +0 -28
  137. data/spec/integration/mappers/renaming_attributes_spec.rb +0 -125
  138. data/spec/integration/mappers/reusing_mappers_spec.rb +0 -43
  139. data/spec/integration/mappers/step_spec.rb +0 -119
  140. data/spec/integration/mappers/symbolizing_attributes_spec.rb +0 -77
  141. data/spec/integration/mappers/unfold_spec.rb +0 -92
  142. data/spec/integration/mappers/ungroup_spec.rb +0 -126
  143. data/spec/integration/mappers/unwrap_spec.rb +0 -93
  144. data/spec/integration/mappers/wrap_spec.rb +0 -155
  145. data/spec/integration/memory/commands/create_spec.rb +0 -23
  146. data/spec/integration/memory/commands/delete_spec.rb +0 -23
  147. data/spec/integration/memory/commands/update_spec.rb +0 -23
  148. data/spec/integration/multi_env_spec.rb +0 -69
  149. data/spec/integration/multi_repo_spec.rb +0 -46
  150. data/spec/integration/relations/default_dataset_spec.rb +0 -38
  151. data/spec/integration/relations/inheritance_spec.rb +0 -37
  152. data/spec/integration/relations/reading_spec.rb +0 -169
  153. data/spec/integration/relations/registry_dsl_spec.rb +0 -45
  154. data/spec/integration/repositories/extending_relations_spec.rb +0 -58
  155. data/spec/integration/repositories/setting_logger_spec.rb +0 -34
  156. data/spec/integration/setup_spec.rb +0 -160
  157. data/spec/shared/command_behavior.rb +0 -28
  158. data/spec/shared/command_graph.rb +0 -50
  159. data/spec/shared/container.rb +0 -9
  160. data/spec/shared/enumerable_dataset.rb +0 -52
  161. data/spec/shared/gateway_only.rb +0 -6
  162. data/spec/shared/materializable.rb +0 -36
  163. data/spec/shared/no_container.rb +0 -16
  164. data/spec/shared/one_behavior.rb +0 -26
  165. data/spec/shared/proxy.rb +0 -0
  166. data/spec/shared/users_and_tasks.rb +0 -10
  167. data/spec/spec_helper.rb +0 -52
  168. data/spec/support/constant_leak_finder.rb +0 -14
  169. data/spec/support/mutant.rb +0 -10
  170. data/spec/support/types.rb +0 -5
  171. data/spec/test/memory_repository_lint_test.rb +0 -27
  172. data/spec/unit/rom/association_set_spec.rb +0 -23
  173. data/spec/unit/rom/commands/graph_spec.rb +0 -191
  174. data/spec/unit/rom/commands/lazy_spec.rb +0 -307
  175. data/spec/unit/rom/commands/result_spec.rb +0 -70
  176. data/spec/unit/rom/commands_spec.rb +0 -165
  177. data/spec/unit/rom/configurable_spec.rb +0 -49
  178. data/spec/unit/rom/configuration_spec.rb +0 -61
  179. data/spec/unit/rom/container_spec.rb +0 -99
  180. data/spec/unit/rom/create_container_spec.rb +0 -151
  181. data/spec/unit/rom/environment_spec.rb +0 -123
  182. data/spec/unit/rom/gateway_spec.rb +0 -146
  183. data/spec/unit/rom/mapper_registry_spec.rb +0 -25
  184. data/spec/unit/rom/memory/commands_spec.rb +0 -43
  185. data/spec/unit/rom/memory/dataset_spec.rb +0 -31
  186. data/spec/unit/rom/memory/relation_spec.rb +0 -109
  187. data/spec/unit/rom/memory/repository_spec.rb +0 -12
  188. data/spec/unit/rom/memory/storage_spec.rb +0 -45
  189. data/spec/unit/rom/plugin_spec.rb +0 -150
  190. data/spec/unit/rom/plugins/command/schema_spec.rb +0 -66
  191. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +0 -85
  192. data/spec/unit/rom/plugins/relation/view_spec.rb +0 -51
  193. data/spec/unit/rom/relation/composite_spec.rb +0 -89
  194. data/spec/unit/rom/relation/curried_spec.rb +0 -52
  195. data/spec/unit/rom/relation/graph_spec.rb +0 -92
  196. data/spec/unit/rom/relation/lazy/combine_spec.rb +0 -165
  197. data/spec/unit/rom/relation/lazy_spec.rb +0 -214
  198. data/spec/unit/rom/relation/loaded_spec.rb +0 -53
  199. data/spec/unit/rom/relation/name_spec.rb +0 -58
  200. data/spec/unit/rom/relation/schema_spec.rb +0 -117
  201. data/spec/unit/rom/relation_spec.rb +0 -237
  202. data/spec/unit/rom/schema_spec.rb +0 -10
  203. data/spec/unit/rom/setup/auto_registration_spec.rb +0 -152
data/lib/rom/container.rb DELETED
@@ -1,231 +0,0 @@
1
- require 'rom/relation/loaded'
2
- require 'rom/commands/graph'
3
- require 'rom/commands/graph/builder'
4
- require 'rom/support/publisher'
5
-
6
- module ROM
7
- # ROM container is an isolated environment with no global state where all
8
- # components are registered. Container objects provide access to your
9
- # relations, commands and mappers. ROM containers are usually configured and
10
- # handled via framework integrations, although it is easy to use them
11
- # standalone.
12
- #
13
- # There are 3 types of container setup:
14
- #
15
- # * in-line setup - a simple block-based configuration which allows configuring
16
- # all components and gives you back a container instance. This type is suitable
17
- # for small scripts, or in some cases rake tasks
18
- # * multi-step setup - this type requires creating a configuration object,
19
- # registering component classes (ie relation classes) and passing the config
20
- # to container builder function. This type is suitable when your environment
21
- # is not typical and you need full control over component registration
22
- # * multi-step setup with auto-registration - same as multi-step but allows
23
- # you to configure auto-registration mechanism which will register component
24
- # classes for you, based on dir/file naming conventions. This is the most
25
- # common type of setup that's used by framework integrations
26
- #
27
- # @example in-line setup
28
- # rom = ROM.container(:sql, 'sqlite::memory') do |config|
29
- # config.default.create_table :users do
30
- # primary_key :id
31
- # column :name, String, null: false
32
- # end
33
- #
34
- # config.relation(:users) do
35
- # schema(infer: true)
36
- #
37
- # def by_name(name)
38
- # where(name: name)
39
- # end
40
- # end
41
- # end
42
- #
43
- # rom.relations[:users].insert(name: "Jane")
44
- #
45
- # rom.relations[:users].by_name("Jane").to_a
46
- # # [{:id=>1, :name=>"Jane"}]
47
- #
48
- # @example multi-step setup with explicit component classes
49
- # config = ROM::Configuration.new(:sql, 'sqlite::memory')
50
- #
51
- # config.default.create_table :users do
52
- # primary_key :id
53
- # column :name, String, null: false
54
- # end
55
- #
56
- # class Users < ROM::Relation[:sql]
57
- # schema(:users, infer: true)
58
- #
59
- # def by_name(name)
60
- # where(name: name)
61
- # end
62
- # end
63
- #
64
- # config.register_relation(Users)
65
- #
66
- # rom = ROM.container(config)
67
- #
68
- # rom.relations[:users].insert(name: "Jane")
69
- #
70
- # rom.relations[:users].by_name("Jane").to_a
71
- # # [{:id=>1, :name=>"Jane"}]
72
- #
73
- #
74
- # @example multi-step setup with auto-registration
75
- # config = ROM::Configuration.new(:sql, 'sqlite::memory')
76
- # config.auto_registration('./persistence', namespace: false)
77
- #
78
- # config.default.create_table :users do
79
- # primary_key :id
80
- # column :name, String, null: false
81
- # end
82
- #
83
- # # ./persistence/relations/users.rb
84
- # class Users < ROM::Relation[:sql]
85
- # schema(infer: true)
86
- #
87
- # def by_name(name)
88
- # where(name: name)
89
- # end
90
- # end
91
- #
92
- # rom = ROM.container(config)
93
- #
94
- # rom.relations[:users].insert(name: "Jane")
95
- #
96
- # rom.relations[:users].by_name("Jane").to_a
97
- # # [{:id=>1, :name=>"Jane"}]
98
- #
99
- # @api public
100
- class Container
101
- include ROM::Support::Publisher
102
- include Dry::Equalizer(:gateways, :relations, :mappers, :commands)
103
-
104
- # @return [Hash] configured gateways
105
- #
106
- # @api public
107
- attr_reader :gateways
108
-
109
- # @return [RelationRegistry] relation registry
110
- #
111
- # @api public
112
- attr_reader :relations
113
-
114
- # @return [Registry] command registry
115
- #
116
- # @api public
117
- attr_reader :commands
118
-
119
- # @return [Registry] mapper registry
120
- #
121
- # @api public
122
- attr_reader :mappers
123
-
124
- # @api private
125
- def initialize(gateways, relations, mappers, commands)
126
- @gateways = gateways
127
- @relations = relations
128
- @mappers = mappers
129
- @commands = commands
130
- end
131
-
132
- # Get relation instance identified by its name
133
- #
134
- # This method will use a custom mapper if it was configured. ie if you have
135
- # a relation called `:users` and a mapper configured for `:users` relation,
136
- # then by default this mapper will be used.
137
- #
138
- # @example
139
- # rom.relation(:users)
140
- # rom.relation(:users).by_name('Jane')
141
- #
142
- # # block syntax allows accessing lower-level query DSLs (usage is discouraged though)
143
- # rom.relation { |r| r.restrict(name: 'Jane') }
144
- #
145
- # # with mapping
146
- # rom.relation(:users).map_with(:presenter)
147
- #
148
- # # using multiple mappers
149
- # rom.relation(:users).page(1).map_with(:presenter, :json_serializer)
150
- #
151
- # @param [Symbol] name of the relation to load
152
- #
153
- # @yield [Relation]
154
- #
155
- # @return [Relation]
156
- #
157
- # @api public
158
- def relation(name, &block)
159
- relation =
160
- if block
161
- yield(relations[name])
162
- else
163
- relations[name]
164
- end
165
-
166
- if mappers.key?(name)
167
- relation.with(mappers: mappers[name])
168
- else
169
- relation
170
- end
171
- end
172
-
173
- # Returns commands registry for the given relation
174
- #
175
- # @example
176
- # # plain command without mapping
177
- # rom.command(:users).create
178
- #
179
- # # allows auto-mapping using registered mappers
180
- # rom.command(:users).as(:entity)
181
- #
182
- # # allows building up a command graph for nested input
183
- # command = rom.command([:users, [:create, [:tasks, [:create]]]])
184
- #
185
- # command.call(users: [{ name: 'Jane', tasks: [{ title: 'One' }] }])
186
- #
187
- # @param [Array,Symbol] options Either graph options or registered command name
188
- #
189
- # @return [Command, Command::Graph]
190
- #
191
- # @api public
192
- def command(options = nil)
193
- case options
194
- when Symbol
195
- name = options
196
- if mappers.key?(name)
197
- commands[name].with(mappers: mappers[name])
198
- else
199
- commands[name]
200
- end
201
- when Array
202
- graph = Commands::Graph.build(commands, options)
203
- name = graph.name
204
-
205
- if mappers.key?(name)
206
- graph.with(mappers: mappers[name])
207
- else
208
- graph
209
- end
210
- when nil
211
- Commands::Graph::Builder.new(self)
212
- else
213
- raise ArgumentError, "#{self.class}#command accepts a symbol or an array"
214
- end
215
- end
216
-
217
- # Disconnect all gateways
218
- #
219
- # @example
220
- # rom = ROM.container(:sql, 'sqlite://my_db.sqlite')
221
- # rom.relations[:users].insert(name: "Jane")
222
- # rom.disconnect
223
- #
224
- # @return [Hash<Symbol=>Gateway>] a hash with disconnected gateways
225
- #
226
- # @api public
227
- def disconnect
228
- gateways.each_value(&:disconnect)
229
- end
230
- end
231
- end
@@ -1,61 +0,0 @@
1
- require 'rom/configuration'
2
- require 'rom/environment'
3
- require 'rom/setup'
4
- require 'rom/setup/finalize'
5
-
6
- module ROM
7
- class CreateContainer
8
- include ROM::Support::Publisher
9
-
10
- attr_reader :container
11
-
12
- def initialize(environment, setup)
13
- @container = finalize(environment, setup)
14
- end
15
-
16
- private
17
-
18
- def finalize(environment, setup)
19
- environment.configure do |config|
20
- environment.gateways.each_key do |key|
21
- gateway_config = config.gateways[key]
22
- gateway_config.infer_relations = true unless gateway_config.key?(:infer_relations)
23
- end
24
- end
25
-
26
- finalize = Finalize.new(
27
- gateways: environment.gateways,
28
- gateway_map: environment.gateways_map,
29
- relation_classes: setup.relation_classes,
30
- command_classes: setup.command_classes,
31
- mappers: setup.mapper_classes,
32
- config: environment.config.dup.freeze
33
- )
34
-
35
- finalize.run!
36
- end
37
- end
38
-
39
- class InlineCreateContainer < CreateContainer
40
- def initialize(*args, &block)
41
- case args.first
42
- when Configuration
43
- environment = args.first.environment
44
- setup = args.first.setup
45
- when Environment
46
- environment = args.first
47
- setup = args[1]
48
- else
49
- configuration = Configuration.new(*args, &block)
50
- environment = configuration.environment
51
- setup = configuration.setup
52
- end
53
-
54
- super(environment, setup)
55
- end
56
- end
57
-
58
- def self.container(*args, &block)
59
- InlineCreateContainer.new(*args, &block).container
60
- end
61
- end
@@ -1,70 +0,0 @@
1
- require 'rom/support/configurable'
2
- require 'rom/gateway'
3
-
4
- module ROM
5
- # Core gateway configuration interface
6
- #
7
- # @api public
8
- class Environment
9
- include Configurable
10
-
11
- attr_reader :gateways, :gateways_map
12
-
13
- # @api public
14
- def initialize(*args)
15
- @gateways = {}
16
- @gateways_map = {}
17
-
18
- configure_gateways(*args) unless args.empty?
19
- end
20
-
21
- private
22
-
23
- def configure_gateways(*args)
24
- normalized_gateway_args = normalize_gateway_args(*args)
25
- normalized_gateways = normalize_gateways(normalized_gateway_args)
26
-
27
- @gateways, @gateways_map = normalized_gateways.values_at(:gateways, :map)
28
-
29
- normalized_gateway_args.each_with_object(config) do |(name, gateway_config), config|
30
- options = gateway_config.is_a?(Array) && gateway_config.last
31
- load_config(config.gateways[name], options) if options.is_a?(Hash)
32
- end
33
- end
34
-
35
-
36
- # @api private
37
- def normalize_gateway_args(*args)
38
- args.first.is_a?(Hash) ? args.first : {default: args}
39
- end
40
-
41
- # Build gateways using the setup interface
42
- #
43
- # @api private
44
- def normalize_gateways(gateways_config)
45
- gateways_config.each_with_object({map: {}, gateways: {}}) do |(name, spec), hash|
46
- identifier, *args = Array(spec)
47
-
48
- if identifier.is_a?(Gateway)
49
- gateway = identifier
50
- else
51
- gateway = Gateway.setup(identifier, *(args.flatten))
52
- hash[:map][gateway] = identifier
53
- end
54
-
55
- hash[:gateways][name] = gateway
56
- end
57
- end
58
-
59
- # @api private
60
- def load_config(config, hash)
61
- hash.each do |key, value|
62
- if value.is_a?(Hash)
63
- load_config(config[key], value)
64
- else
65
- config.send("#{key}=", value)
66
- end
67
- end
68
- end
69
- end
70
- end
data/lib/rom/gateway.rb DELETED
@@ -1,154 +0,0 @@
1
- module ROM
2
- # Abstract gateway class
3
- #
4
- # @api public
5
- class Gateway
6
- extend ClassMacros
7
-
8
- defines :adapter
9
-
10
- # Return connection object
11
- #
12
- # @return [Object] type varies depending on the gateway
13
- #
14
- # @api public
15
- attr_reader :connection
16
-
17
- # Setup a gateway
18
- #
19
- # @overload setup(type, *args)
20
- # Sets up a single-gateway given a gateway type.
21
- # For custom gateways, create an instance and pass it directly.
22
- #
23
- # @param [Symbol] type
24
- # @param [Array] *args
25
- #
26
- # @overload setup(gateway)
27
- # @param [Gateway] gateway
28
- #
29
- # @return [Gateway] a specific gateway subclass
30
- #
31
- # @example
32
- # module SuperDB
33
- # class Gateway < ROM::Gateway
34
- # def initialize(options)
35
- # end
36
- # end
37
- # end
38
- #
39
- # ROM.register_adapter(:super_db, SuperDB)
40
- #
41
- # Gateway.setup(:super_db, some: 'options')
42
- # # SuperDB::Gateway.new(some: 'options') is called
43
- #
44
- # # or alternatively
45
- # super_db = Gateway.setup(SuperDB::Gateway.new(some: 'options'))
46
- # Gateway.setup(super_db)
47
- #
48
- # @api public
49
- def self.setup(gateway_or_scheme, *args)
50
- case gateway_or_scheme
51
- when String
52
- raise ArgumentError, <<-STRING.gsub(/^ {10}/, '')
53
- URIs without an explicit scheme are not supported anymore.
54
- See https://github.com/rom-rb/rom/blob/master/CHANGELOG.md
55
- STRING
56
- when Symbol
57
- klass = class_from_symbol(gateway_or_scheme)
58
-
59
- if klass.instance_method(:initialize).arity == 0
60
- klass.new
61
- else
62
- klass.new(*args)
63
- end
64
- else
65
- if args.empty?
66
- gateway_or_scheme
67
- else
68
- raise ArgumentError, "Can't accept arguments when passing an instance"
69
- end
70
- end
71
- end
72
-
73
- # Get gateway subclass for a specific adapter
74
- #
75
- # @param [Symbol] type adapter identifier
76
- #
77
- # @return [Class]
78
- #
79
- # @api private
80
- def self.class_from_symbol(type)
81
- adapter = ROM.adapters.fetch(type) {
82
- begin
83
- require "rom/#{type}"
84
- rescue LoadError
85
- raise AdapterLoadError, "Failed to load adapter rom/#{type}"
86
- end
87
-
88
- ROM.adapters.fetch(type)
89
- }
90
-
91
- if adapter.const_defined?(:Gateway)
92
- adapter.const_get(:Gateway)
93
- else
94
- adapter.const_get(:Repository)
95
- end
96
- end
97
-
98
- # Returns the adapter, defined for the class
99
- #
100
- # @return [Symbol]
101
- #
102
- # @api public
103
- def adapter
104
- self.class.adapter || raise(
105
- MissingAdapterIdentifierError,
106
- "gateway class +#{self}+ is missing the adapter identifier"
107
- )
108
- end
109
-
110
- # A generic interface for setting up a logger
111
- #
112
- # @api public
113
- def use_logger(*)
114
- # noop
115
- end
116
-
117
- # A generic interface for returning default logger
118
- #
119
- # @api public
120
- def logger
121
- # noop
122
- end
123
-
124
- # Extension hook for adding gateway-specific behavior to a command class
125
- #
126
- # @param [Class] klass command class
127
- # @param [Object] _dataset dataset that will be used with this command class
128
- #
129
- # @return [Class]
130
- #
131
- # @api public
132
- def extend_command_class(klass, _dataset)
133
- klass
134
- end
135
-
136
- # Schema inference hook
137
- #
138
- # Every gateway that supports schema inference should implement this method
139
- #
140
- # @return [Array] array with datasets and their names
141
- #
142
- # @api private
143
- def schema
144
- []
145
- end
146
-
147
- # Disconnect is optional and it's a no-op by default
148
- #
149
- # @api public
150
- def disconnect
151
- # noop
152
- end
153
- end
154
- end
@@ -1,49 +0,0 @@
1
- require 'rom/support/constants'
2
-
3
- module ROM
4
- module Global
5
- # plugin registration DSL
6
- #
7
- # @private
8
- class PluginDSL
9
- # Default options passed to plugin registration
10
- #
11
- # @return [Hash]
12
- #
13
- # @api private
14
- attr_reader :defaults
15
-
16
- # Plugin registry
17
- #
18
- # @return [PluginRegistry]
19
- #
20
- # @api private
21
- attr_reader :registry
22
-
23
- # @api private
24
- def initialize(registry, defaults = EMPTY_HASH, &block)
25
- @registry = registry
26
- @defaults = defaults
27
- instance_exec(&block)
28
- end
29
-
30
- # Register a plugin
31
- #
32
- # @param [Symbol] name of the plugin
33
- # @param [Module] mod to include
34
- # @param [Hash] options
35
- #
36
- # @api public
37
- def register(name, mod, options = EMPTY_HASH)
38
- registry.register(name, mod, defaults.merge(options))
39
- end
40
-
41
- # Register plugins for a specific adapter
42
- #
43
- # @param [Symbol] adapter type
44
- def adapter(type, &block)
45
- self.class.new(registry, adapter: type, &block)
46
- end
47
- end
48
- end
49
- end
data/lib/rom/global.rb DELETED
@@ -1,60 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'rom/plugin_registry'
3
- require 'rom/global/plugin_dsl'
4
- require 'rom/support/deprecations'
5
-
6
- module ROM
7
- # Globally accessible public interface exposed via ROM module
8
- #
9
- # @api public
10
- module Global
11
- # Set base global registries in ROM constant
12
- #
13
- # @api private
14
- def self.extended(rom)
15
- super
16
-
17
- rom.instance_variable_set('@adapters', {})
18
- rom.instance_variable_set('@plugin_registry', PluginRegistry.new)
19
- end
20
-
21
- # An internal adapter identifier => adapter module map used by setup
22
- #
23
- # @return [Hash<Symbol=>Module>]
24
- #
25
- # @api private
26
- attr_reader :adapters
27
-
28
- # An internal identifier => plugin map used by the setup
29
- #
30
- # @return [Hash]
31
- #
32
- # @api private
33
- attr_reader :plugin_registry
34
-
35
- # Global plugin setup DSL
36
- #
37
- # @example
38
- # ROM.plugins do
39
- # register :publisher, Plugin::Publisher, type: :command
40
- # end
41
- #
42
- # @example
43
- def plugins(*args, &block)
44
- PluginDSL.new(plugin_registry, *args, &block)
45
- end
46
-
47
- # Register adapter namespace under a specified identifier
48
- #
49
- # @param [Symbol] identifier
50
- # @param [Class,Module] adapter
51
- #
52
- # @return [self]
53
- #
54
- # @api private
55
- def register_adapter(identifier, adapter)
56
- adapters[identifier] = adapter
57
- self
58
- end
59
- end
60
- end
@@ -1,54 +0,0 @@
1
- require 'rom/lint/linter'
2
-
3
- module ROM
4
- module Lint
5
- # Ensures that a [ROM::EnumerableDataset] extension correctly yields
6
- # arrays and tuples
7
- #
8
- # @api public
9
- class EnumerableDataset < ROM::Lint::Linter
10
- # The linted subject
11
- #
12
- # @api public
13
- attr_reader :dataset
14
-
15
- # The expected data
16
- #
17
- # @api public
18
- attr_reader :data
19
-
20
- # Create a linter for EnumerableDataset
21
- #
22
- # @param [EnumerableDataset] dataset the linted subject
23
- # @param [Object] data the expected data
24
- #
25
- # @api public
26
- def initialize(dataset, data)
27
- @dataset = dataset
28
- @data = data
29
- end
30
-
31
- # Lint: Ensure that +dataset+ yield tuples via +each+
32
- #
33
- # @api public
34
- def lint_each
35
- result = []
36
- dataset.each do |tuple|
37
- result << tuple
38
- end
39
- return if result == data
40
-
41
- complain "#{dataset.class}#each must yield tuples"
42
- end
43
-
44
- # Lint: Ensure that +dataset+'s array equals to expected +data+
45
- #
46
- # @api public
47
- def lint_to_a
48
- return if dataset.to_a == data
49
-
50
- complain "#{dataset.class}#to_a must cast dataset to an array"
51
- end
52
- end
53
- end
54
- end