rom 3.3.3 → 4.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2 -599
  3. data/lib/rom/version.rb +1 -1
  4. data/lib/rom.rb +3 -44
  5. metadata +19 -295
  6. data/.gitignore +0 -24
  7. data/.rspec +0 -3
  8. data/.rubocop.yml +0 -87
  9. data/.rubocop_todo.yml +0 -46
  10. data/.travis.yml +0 -24
  11. data/.yardopts +0 -2
  12. data/CODE_OF_CONDUCT.md +0 -13
  13. data/CONTRIBUTING.md +0 -1
  14. data/Gemfile +0 -54
  15. data/Guardfile +0 -24
  16. data/Rakefile +0 -28
  17. data/lib/rom/array_dataset.rb +0 -44
  18. data/lib/rom/association_set.rb +0 -49
  19. data/lib/rom/auto_curry.rb +0 -55
  20. data/lib/rom/command.rb +0 -494
  21. data/lib/rom/command_registry.rb +0 -148
  22. data/lib/rom/commands/class_interface.rb +0 -270
  23. data/lib/rom/commands/composite.rb +0 -53
  24. data/lib/rom/commands/create.rb +0 -13
  25. data/lib/rom/commands/delete.rb +0 -14
  26. data/lib/rom/commands/graph/builder.rb +0 -176
  27. data/lib/rom/commands/graph/class_interface.rb +0 -62
  28. data/lib/rom/commands/graph/input_evaluator.rb +0 -62
  29. data/lib/rom/commands/graph.rb +0 -95
  30. data/lib/rom/commands/lazy/create.rb +0 -23
  31. data/lib/rom/commands/lazy/delete.rb +0 -27
  32. data/lib/rom/commands/lazy/update.rb +0 -34
  33. data/lib/rom/commands/lazy.rb +0 -99
  34. data/lib/rom/commands/result.rb +0 -96
  35. data/lib/rom/commands/update.rb +0 -14
  36. data/lib/rom/commands.rb +0 -3
  37. data/lib/rom/configuration.rb +0 -90
  38. data/lib/rom/configuration_dsl/command.rb +0 -41
  39. data/lib/rom/configuration_dsl/command_dsl.rb +0 -35
  40. data/lib/rom/configuration_dsl/mapper.rb +0 -36
  41. data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -43
  42. data/lib/rom/configuration_dsl/relation.rb +0 -26
  43. data/lib/rom/configuration_dsl.rb +0 -107
  44. data/lib/rom/configuration_plugin.rb +0 -17
  45. data/lib/rom/constants.rb +0 -36
  46. data/lib/rom/container.rb +0 -233
  47. data/lib/rom/create_container.rb +0 -60
  48. data/lib/rom/data_proxy.rb +0 -94
  49. data/lib/rom/enumerable_dataset.rb +0 -68
  50. data/lib/rom/environment.rb +0 -70
  51. data/lib/rom/gateway.rb +0 -196
  52. data/lib/rom/global/plugin_dsl.rb +0 -47
  53. data/lib/rom/global.rb +0 -58
  54. data/lib/rom/initializer.rb +0 -26
  55. data/lib/rom/lint/enumerable_dataset.rb +0 -54
  56. data/lib/rom/lint/gateway.rb +0 -120
  57. data/lib/rom/lint/linter.rb +0 -78
  58. data/lib/rom/lint/spec.rb +0 -20
  59. data/lib/rom/lint/test.rb +0 -98
  60. data/lib/rom/mapper_registry.rb +0 -35
  61. data/lib/rom/memory/commands.rb +0 -56
  62. data/lib/rom/memory/dataset.rb +0 -97
  63. data/lib/rom/memory/gateway.rb +0 -64
  64. data/lib/rom/memory/relation.rb +0 -62
  65. data/lib/rom/memory/schema.rb +0 -13
  66. data/lib/rom/memory/storage.rb +0 -59
  67. data/lib/rom/memory/types.rb +0 -9
  68. data/lib/rom/memory.rb +0 -4
  69. data/lib/rom/pipeline.rb +0 -122
  70. data/lib/rom/plugin.rb +0 -20
  71. data/lib/rom/plugin_base.rb +0 -40
  72. data/lib/rom/plugin_registry.rb +0 -173
  73. data/lib/rom/plugins/command/schema.rb +0 -37
  74. data/lib/rom/plugins/configuration/configuration_dsl.rb +0 -21
  75. data/lib/rom/plugins/relation/instrumentation.rb +0 -51
  76. data/lib/rom/plugins/relation/key_inference.rb +0 -48
  77. data/lib/rom/plugins/relation/registry_reader.rb +0 -33
  78. data/lib/rom/registry.rb +0 -50
  79. data/lib/rom/relation/class_interface.rb +0 -356
  80. data/lib/rom/relation/composite.rb +0 -46
  81. data/lib/rom/relation/curried.rb +0 -109
  82. data/lib/rom/relation/graph.rb +0 -125
  83. data/lib/rom/relation/loaded.rb +0 -127
  84. data/lib/rom/relation/materializable.rb +0 -66
  85. data/lib/rom/relation/name.rb +0 -102
  86. data/lib/rom/relation/view_dsl.rb +0 -64
  87. data/lib/rom/relation.rb +0 -250
  88. data/lib/rom/relation_registry.rb +0 -9
  89. data/lib/rom/schema/attribute.rb +0 -390
  90. data/lib/rom/schema/dsl.rb +0 -67
  91. data/lib/rom/schema.rb +0 -407
  92. data/lib/rom/setup/auto_registration.rb +0 -74
  93. data/lib/rom/setup/auto_registration_strategies/base.rb +0 -16
  94. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +0 -63
  95. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +0 -20
  96. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +0 -18
  97. data/lib/rom/setup/finalize/finalize_commands.rb +0 -47
  98. data/lib/rom/setup/finalize/finalize_mappers.rb +0 -36
  99. data/lib/rom/setup/finalize/finalize_relations.rb +0 -83
  100. data/lib/rom/setup/finalize.rb +0 -152
  101. data/lib/rom/setup.rb +0 -65
  102. data/lib/rom/support/configurable.rb +0 -85
  103. data/lib/rom/transaction.rb +0 -24
  104. data/lib/rom/types.rb +0 -49
  105. data/log/.gitkeep +0 -0
  106. data/rakelib/benchmark.rake +0 -15
  107. data/rakelib/mutant.rake +0 -19
  108. data/rakelib/rubocop.rake +0 -18
  109. data/rom.gemspec +0 -25
  110. data/spec/fixtures/app/commands/create_user.rb +0 -2
  111. data/spec/fixtures/app/mappers/user_list.rb +0 -2
  112. data/spec/fixtures/app/my_commands/create_user.rb +0 -2
  113. data/spec/fixtures/app/my_mappers/user_list.rb +0 -2
  114. data/spec/fixtures/app/my_relations/users.rb +0 -2
  115. data/spec/fixtures/app/relations/users.rb +0 -2
  116. data/spec/fixtures/custom/commands/create_user.rb +0 -6
  117. data/spec/fixtures/custom/mappers/user_list.rb +0 -6
  118. data/spec/fixtures/custom/relations/users.rb +0 -6
  119. data/spec/fixtures/custom_namespace/commands/create_customer.rb +0 -8
  120. data/spec/fixtures/custom_namespace/mappers/customer_list.rb +0 -8
  121. data/spec/fixtures/custom_namespace/relations/customers.rb +0 -8
  122. data/spec/fixtures/lib/persistence/commands/create_user.rb +0 -6
  123. data/spec/fixtures/lib/persistence/mappers/user_list.rb +0 -6
  124. data/spec/fixtures/lib/persistence/my_commands/create_user.rb +0 -6
  125. data/spec/fixtures/lib/persistence/my_mappers/user_list.rb +0 -6
  126. data/spec/fixtures/lib/persistence/my_relations/users.rb +0 -6
  127. data/spec/fixtures/lib/persistence/relations/users.rb +0 -6
  128. data/spec/fixtures/wrong/commands/create_customer.rb +0 -8
  129. data/spec/fixtures/wrong/mappers/customer_list.rb +0 -8
  130. data/spec/fixtures/wrong/relations/customers.rb +0 -8
  131. data/spec/integration/command_registry_spec.rb +0 -47
  132. data/spec/integration/commands/create_spec.rb +0 -157
  133. data/spec/integration/commands/delete_spec.rb +0 -67
  134. data/spec/integration/commands/error_handling_spec.rb +0 -25
  135. data/spec/integration/commands/graph_builder_spec.rb +0 -213
  136. data/spec/integration/commands/graph_spec.rb +0 -294
  137. data/spec/integration/commands/update_spec.rb +0 -86
  138. data/spec/integration/commands_spec.rb +0 -67
  139. data/spec/integration/gateways/extending_relations_spec.rb +0 -58
  140. data/spec/integration/gateways/setting_logger_spec.rb +0 -34
  141. data/spec/integration/mappers/combine_spec.rb +0 -117
  142. data/spec/integration/mappers/deep_embedded_spec.rb +0 -44
  143. data/spec/integration/mappers/definition_dsl_spec.rb +0 -206
  144. data/spec/integration/mappers/embedded_spec.rb +0 -62
  145. data/spec/integration/mappers/exclude_spec.rb +0 -27
  146. data/spec/integration/mappers/fold_spec.rb +0 -71
  147. data/spec/integration/mappers/group_spec.rb +0 -163
  148. data/spec/integration/mappers/overwrite_attributes_value_spec.rb +0 -51
  149. data/spec/integration/mappers/prefix_separator_spec.rb +0 -52
  150. data/spec/integration/mappers/prefix_spec.rb +0 -48
  151. data/spec/integration/mappers/prefixing_attributes_spec.rb +0 -37
  152. data/spec/integration/mappers/registering_custom_mappers_spec.rb +0 -28
  153. data/spec/integration/mappers/renaming_attributes_spec.rb +0 -125
  154. data/spec/integration/mappers/reusing_mappers_spec.rb +0 -43
  155. data/spec/integration/mappers/step_spec.rb +0 -119
  156. data/spec/integration/mappers/symbolizing_attributes_spec.rb +0 -77
  157. data/spec/integration/mappers/unfold_spec.rb +0 -92
  158. data/spec/integration/mappers/ungroup_spec.rb +0 -126
  159. data/spec/integration/mappers/unwrap_spec.rb +0 -93
  160. data/spec/integration/mappers/wrap_spec.rb +0 -155
  161. data/spec/integration/memory/commands/create_spec.rb +0 -23
  162. data/spec/integration/memory/commands/delete_spec.rb +0 -23
  163. data/spec/integration/memory/commands/update_spec.rb +0 -23
  164. data/spec/integration/multi_env_spec.rb +0 -69
  165. data/spec/integration/multi_repo_spec.rb +0 -46
  166. data/spec/integration/relations/default_dataset_spec.rb +0 -38
  167. data/spec/integration/relations/inheritance_spec.rb +0 -37
  168. data/spec/integration/relations/reading_spec.rb +0 -169
  169. data/spec/integration/relations/registry_dsl_spec.rb +0 -45
  170. data/spec/integration/setup_spec.rb +0 -193
  171. data/spec/shared/command_behavior.rb +0 -28
  172. data/spec/shared/command_graph.rb +0 -54
  173. data/spec/shared/container.rb +0 -9
  174. data/spec/shared/enumerable_dataset.rb +0 -52
  175. data/spec/shared/gateway_only.rb +0 -6
  176. data/spec/shared/materializable.rb +0 -36
  177. data/spec/shared/no_container.rb +0 -16
  178. data/spec/shared/one_behavior.rb +0 -26
  179. data/spec/shared/proxy.rb +0 -0
  180. data/spec/shared/users_and_tasks.rb +0 -10
  181. data/spec/spec_helper.rb +0 -59
  182. data/spec/support/constant_leak_finder.rb +0 -14
  183. data/spec/support/mutant.rb +0 -10
  184. data/spec/support/schema.rb +0 -14
  185. data/spec/support/types.rb +0 -5
  186. data/spec/test/memory_repository_lint_test.rb +0 -27
  187. data/spec/unit/rom/array_dataset_spec.rb +0 -59
  188. data/spec/unit/rom/association_set_spec.rb +0 -48
  189. data/spec/unit/rom/auto_curry_spec.rb +0 -71
  190. data/spec/unit/rom/commands/graph_spec.rb +0 -192
  191. data/spec/unit/rom/commands/lazy_spec.rb +0 -310
  192. data/spec/unit/rom/commands/pre_and_post_processors_spec.rb +0 -343
  193. data/spec/unit/rom/commands/result_spec.rb +0 -70
  194. data/spec/unit/rom/commands_spec.rb +0 -188
  195. data/spec/unit/rom/configurable_spec.rb +0 -49
  196. data/spec/unit/rom/configuration_spec.rb +0 -61
  197. data/spec/unit/rom/container_spec.rb +0 -109
  198. data/spec/unit/rom/create_container_spec.rb +0 -151
  199. data/spec/unit/rom/enumerable_dataset_spec.rb +0 -15
  200. data/spec/unit/rom/environment_spec.rb +0 -123
  201. data/spec/unit/rom/gateway_spec.rb +0 -146
  202. data/spec/unit/rom/mapper_registry_spec.rb +0 -25
  203. data/spec/unit/rom/memory/commands_spec.rb +0 -43
  204. data/spec/unit/rom/memory/dataset_spec.rb +0 -31
  205. data/spec/unit/rom/memory/gateway_spec.rb +0 -12
  206. data/spec/unit/rom/memory/inheritance_spec.rb +0 -32
  207. data/spec/unit/rom/memory/relation_spec.rb +0 -121
  208. data/spec/unit/rom/memory/storage_spec.rb +0 -45
  209. data/spec/unit/rom/plugin_spec.rb +0 -150
  210. data/spec/unit/rom/plugins/command/schema_spec.rb +0 -66
  211. data/spec/unit/rom/plugins/relation/instrumentation_spec.rb +0 -44
  212. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +0 -85
  213. data/spec/unit/rom/registry_spec.rb +0 -86
  214. data/spec/unit/rom/relation/attribute_reader_spec.rb +0 -17
  215. data/spec/unit/rom/relation/call_spec.rb +0 -51
  216. data/spec/unit/rom/relation/composite_spec.rb +0 -106
  217. data/spec/unit/rom/relation/curried_spec.rb +0 -67
  218. data/spec/unit/rom/relation/graph_spec.rb +0 -106
  219. data/spec/unit/rom/relation/lazy/combine_spec.rb +0 -165
  220. data/spec/unit/rom/relation/lazy/graph_spec.rb +0 -165
  221. data/spec/unit/rom/relation/lazy_spec.rb +0 -214
  222. data/spec/unit/rom/relation/loaded_spec.rb +0 -53
  223. data/spec/unit/rom/relation/name_spec.rb +0 -58
  224. data/spec/unit/rom/relation/output_schema_spec.rb +0 -28
  225. data/spec/unit/rom/relation/schema_spec.rb +0 -259
  226. data/spec/unit/rom/relation/view_spec.rb +0 -158
  227. data/spec/unit/rom/relation_spec.rb +0 -252
  228. data/spec/unit/rom/schema/accessing_attributes_spec.rb +0 -52
  229. data/spec/unit/rom/schema/append_spec.rb +0 -17
  230. data/spec/unit/rom/schema/exclude_spec.rb +0 -15
  231. data/spec/unit/rom/schema/finalize_spec.rb +0 -59
  232. data/spec/unit/rom/schema/key_predicate_spec.rb +0 -15
  233. data/spec/unit/rom/schema/merge_spec.rb +0 -17
  234. data/spec/unit/rom/schema/prefix_spec.rb +0 -16
  235. data/spec/unit/rom/schema/project_spec.rb +0 -15
  236. data/spec/unit/rom/schema/rename_spec.rb +0 -22
  237. data/spec/unit/rom/schema/type_spec.rb +0 -49
  238. data/spec/unit/rom/schema/uniq_spec.rb +0 -21
  239. data/spec/unit/rom/schema/wrap_spec.rb +0 -18
  240. data/spec/unit/rom/schema_spec.rb +0 -10
  241. data/spec/unit/rom/setup/auto_registration_spec.rb +0 -214
@@ -1,36 +0,0 @@
1
- require 'dry/core/class_builder'
2
-
3
- module ROM
4
- module ConfigurationDSL
5
- # Setup DSL-specific mapper extensions
6
- #
7
- # @private
8
- class Mapper
9
- # Generate a mapper subclass
10
- #
11
- # This is used by Setup#mappers DSL
12
- #
13
- # @api private
14
- def self.build_class(name, mapper_registry, options = EMPTY_HASH, &block)
15
- class_name = "ROM::Mapper[#{name}]"
16
-
17
- parent = options[:parent]
18
- inherit_header = options.fetch(:inherit_header) { ROM::Mapper.inherit_header }
19
-
20
- parent_class =
21
- if parent
22
- mapper_registry.detect { |klass| klass.relation == parent }
23
- else
24
- ROM::Mapper
25
- end
26
-
27
- Dry::Core::ClassBuilder.new(name: class_name, parent: parent_class).call do |klass|
28
- klass.relation(name)
29
- klass.inherit_header(inherit_header)
30
-
31
- klass.class_eval(&block) if block
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,43 +0,0 @@
1
- require 'rom/configuration_dsl/mapper'
2
-
3
- module ROM
4
- module ConfigurationDSL
5
- # Mapper definition DSL used by Setup DSL
6
- #
7
- # @private
8
- class MapperDSL
9
- attr_reader :registry, :mapper_classes, :mapper_classes
10
-
11
- # @api private
12
- def initialize(registry, mapper_classes, block)
13
- @registry = registry
14
- @mapper_classes = mapper_classes
15
- @defined_mappers = []
16
-
17
- instance_exec(&block)
18
-
19
- @mapper_classes = @defined_mappers
20
- end
21
-
22
- # Define a mapper class
23
- #
24
- # @param [Symbol] name of the mapper
25
- # @param [Hash] options
26
- #
27
- # @return [Class]
28
- #
29
- # @api public
30
- def define(name, options = EMPTY_HASH, &block)
31
- @defined_mappers << Mapper.build_class(name, (@mapper_classes + @defined_mappers), options, &block)
32
- self
33
- end
34
-
35
- # TODO
36
- #
37
- # @api public
38
- def register(relation, mappers)
39
- registry.register_mapper(relation => mappers)
40
- end
41
- end
42
- end
43
- end
@@ -1,26 +0,0 @@
1
- require 'dry/core/class_builder'
2
- require 'dry/core/inflector'
3
-
4
- module ROM
5
- module ConfigurationDSL
6
- # Setup DSL-specific relation extensions
7
- #
8
- # @private
9
- class Relation
10
- # Generate a relation subclass
11
- #
12
- # This is used by Setup#relation DSL
13
- #
14
- # @api private
15
- def self.build_class(name, options = EMPTY_HASH)
16
- class_name = "ROM::Relation[#{Dry::Core::Inflector.camelize(name)}]"
17
- adapter = options.fetch(:adapter)
18
-
19
- Dry::Core::ClassBuilder.new(name: class_name, parent: ROM::Relation[adapter]).call do |klass|
20
- klass.gateway(options.fetch(:gateway, :default))
21
- klass.dataset(name, deprecation: false)
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,107 +0,0 @@
1
- require 'rom/configuration_dsl/relation'
2
- require 'rom/configuration_dsl/mapper_dsl'
3
- require 'rom/configuration_dsl/command_dsl'
4
-
5
- module ROM
6
- # This extends Configuration class with the DSL methods
7
- #
8
- # @api public
9
- module ConfigurationDSL
10
- # Relation definition DSL
11
- #
12
- # @example
13
- #
14
- # setup.relation(:users) do
15
- # def names
16
- # project(:name)
17
- # end
18
- # end
19
- #
20
- # @api public
21
- def relation(name, options = EMPTY_HASH, &block)
22
- klass_opts = { adapter: default_adapter }.merge(options)
23
- klass = Relation.build_class(name, klass_opts)
24
- klass.register_as(name, deprecation: false)
25
- klass.class_eval(&block) if block
26
- register_relation(klass)
27
- klass
28
- end
29
-
30
- # Mapper definition DSL
31
- #
32
- # @example
33
- #
34
- # setup.mappers do
35
- # define(:users) do
36
- # model name: 'User'
37
- # end
38
- #
39
- # define(:names, parent: :users) do
40
- # exclude :id
41
- # end
42
- # end
43
- #
44
- # @api public
45
- def mappers(&block)
46
- register_mapper(*MapperDSL.new(self, mapper_classes, block).mapper_classes)
47
- end
48
-
49
- # Command definition DSL
50
- #
51
- # @example
52
- #
53
- # setup.commands(:users) do
54
- # define(:create) do
55
- # input NewUserParams
56
- # result :one
57
- # end
58
- #
59
- # define(:update) do
60
- # input UserParams
61
- # result :many
62
- # end
63
- #
64
- # define(:delete) do
65
- # result :many
66
- # end
67
- # end
68
- #
69
- # @api public
70
- def commands(name, &block)
71
- register_command(*CommandDSL.new(name, default_adapter, &block).command_classes)
72
- end
73
-
74
- # Configures a plugin for a specific adapter to be enabled for all relations
75
- #
76
- # @example
77
- # config = ROM::Configuration.new(:sql, 'sqlite::memory')
78
- #
79
- # config.plugin(:sql, relations: :instrumentation) do |p|
80
- # p.notifications = MyNotificationsBackend
81
- # end
82
- #
83
- # config.plugin(:sql, relations: :pagination)
84
- #
85
- # @param [Symbol] adapter The adapter identifier
86
- # @param [Hash<Symbol=>Symbol>] spec Component identifier => plugin identifier
87
- #
88
- # @return [Plugin]
89
- #
90
- # @api public
91
- def plugin(adapter, spec, &block)
92
- type, name = spec.flatten(1)
93
- plugin = plugin_registry.send(type).adapter(adapter).fetch(name) { plugin_registry.send(type).fetch(name) }
94
-
95
- if block
96
- register_plugin(plugin.configure(&block))
97
- else
98
- register_plugin(plugin)
99
- end
100
- end
101
-
102
- # @api private
103
- def plugin_registry
104
- ROM.plugin_registry
105
- end
106
- end
107
- end
@@ -1,17 +0,0 @@
1
- require 'rom/plugin_base'
2
-
3
- module ROM
4
- # ConfigurationPlugin is a simple object used to store configuration plugin configurations
5
- #
6
- # @private
7
- class ConfigurationPlugin < PluginBase
8
- # Apply this plugin to the provided configuration
9
- #
10
- # @param [ROM::Configuration] configuration
11
- #
12
- # @api private
13
- def apply_to(configuration, options = {})
14
- mod.apply(configuration, options)
15
- end
16
- end
17
- end
data/lib/rom/constants.rb DELETED
@@ -1,36 +0,0 @@
1
- # Constants and errors common in the whole library
2
- module ROM
3
- AdapterLoadError = Class.new(StandardError)
4
-
5
- class AdapterNotPresentError < StandardError
6
- def initialize(adapter, component)
7
- super(
8
- "Failed to find #{component} class for #{adapter} adapter. " \
9
- "Make sure ROM setup was started and the adapter identifier is correct."
10
- )
11
- end
12
- end
13
-
14
- EnvAlreadyFinalizedError = Class.new(StandardError)
15
- RelationAlreadyDefinedError = Class.new(StandardError)
16
- NoRelationError = Class.new(StandardError)
17
- CommandError = Class.new(StandardError)
18
- KeyMissing = Class.new(ROM::CommandError)
19
- TupleCountMismatchError = Class.new(CommandError)
20
- MapperMissingError = Class.new(StandardError)
21
- UnknownPluginError = Class.new(StandardError)
22
- UnsupportedRelationError = Class.new(StandardError)
23
- MissingAdapterIdentifierError = Class.new(StandardError)
24
-
25
- MissingSchemaClassError = Class.new(StandardError) do
26
- def initialize(klass)
27
- super("#{klass.inspect} relation is missing schema_class")
28
- end
29
- end
30
-
31
- DuplicateConfigurationError = Class.new(StandardError)
32
- DuplicateContainerError = Class.new(StandardError)
33
-
34
- InvalidOptionValueError = Class.new(StandardError)
35
- InvalidOptionKeyError = Class.new(StandardError)
36
- end
data/lib/rom/container.rb DELETED
@@ -1,233 +0,0 @@
1
- require 'dry/core/deprecations'
2
-
3
- require 'rom/relation/loaded'
4
- require 'rom/commands/graph'
5
- require 'rom/commands/graph/builder'
6
-
7
- module ROM
8
- # ROM container is an isolated environment with no global state where all
9
- # components are registered. Container objects provide access to your
10
- # relations, commands and mappers. ROM containers are usually configured and
11
- # handled via framework integrations, although it is easy to use them
12
- # standalone.
13
- #
14
- # There are 3 types of container setup:
15
- #
16
- # * Setup DSL - a simple block-based configuration which allows configuring
17
- # all components and gives you back a container instance. This type is suitable
18
- # for small scripts, or in some cases rake tasks
19
- # * Explicit setup - this type requires creating a configuration object,
20
- # registering component classes (ie relation classes) and passing the config
21
- # to container builder function. This type is suitable when your environment
22
- # is not typical and you need full control over component registration
23
- # * Explicit setup with auto-registration - same as explicit setup but allows
24
- # you to configure auto-registration mechanism which will register component
25
- # classes for you, based on dir/file naming conventions. This is the most
26
- # common type of setup that's used by framework integrations
27
- #
28
- # @example in-line setup
29
- # rom = ROM.container(:sql, 'sqlite::memory') do |config|
30
- # config.default.create_table :users do
31
- # primary_key :id
32
- # column :name, String, null: false
33
- # end
34
- #
35
- # config.relation(:users) do
36
- # schema(infer: true)
37
- #
38
- # def by_name(name)
39
- # where(name: name)
40
- # end
41
- # end
42
- # end
43
- #
44
- # rom.relations[:users].insert(name: "Jane")
45
- #
46
- # rom.relations[:users].by_name("Jane").to_a
47
- # # [{:id=>1, :name=>"Jane"}]
48
- #
49
- # @example multi-step setup with explicit component classes
50
- # config = ROM::Configuration.new(:sql, 'sqlite::memory')
51
- #
52
- # config.default.create_table :users do
53
- # primary_key :id
54
- # column :name, String, null: false
55
- # end
56
- #
57
- # class Users < ROM::Relation[:sql]
58
- # schema(:users, infer: true)
59
- #
60
- # def by_name(name)
61
- # where(name: name)
62
- # end
63
- # end
64
- #
65
- # config.register_relation(Users)
66
- #
67
- # rom = ROM.container(config)
68
- #
69
- # rom.relations[:users].insert(name: "Jane")
70
- #
71
- # rom.relations[:users].by_name("Jane").to_a
72
- # # [{:id=>1, :name=>"Jane"}]
73
- #
74
- #
75
- # @example multi-step setup with auto-registration
76
- # config = ROM::Configuration.new(:sql, 'sqlite::memory')
77
- # config.auto_registration('./persistence', namespace: false)
78
- #
79
- # config.default.create_table :users do
80
- # primary_key :id
81
- # column :name, String, null: false
82
- # end
83
- #
84
- # # ./persistence/relations/users.rb
85
- # class Users < ROM::Relation[:sql]
86
- # schema(infer: true)
87
- #
88
- # def by_name(name)
89
- # where(name: name)
90
- # end
91
- # end
92
- #
93
- # rom = ROM.container(config)
94
- #
95
- # rom.relations[:users].insert(name: "Jane")
96
- #
97
- # rom.relations[:users].by_name("Jane").to_a
98
- # # [{:id=>1, :name=>"Jane"}]
99
- #
100
- # @api public
101
- class Container
102
- extend Dry::Core::Deprecations[:rom]
103
-
104
- include Dry::Equalizer(:gateways, :relations, :mappers, :commands)
105
-
106
- # @!attribute [r] gateways
107
- # @return [Hash] A hash with configured gateways
108
- attr_reader :gateways
109
-
110
- # @!attribute [r] relations
111
- # @return [RelationRegistry] The relation registry
112
- attr_reader :relations
113
-
114
- # @!attribute [r] gateways
115
- # @return [CommandRegistry] The command registry
116
- attr_reader :commands
117
-
118
- # @!attribute [r] mappers
119
- # @return [Hash] A hash with configured custom mappers
120
- attr_reader :mappers
121
-
122
- # @api private
123
- def initialize(gateways, relations, mappers, commands)
124
- @gateways = gateways
125
- @relations = relations
126
- @mappers = mappers
127
- @commands = commands
128
- end
129
-
130
- # Get relation instance identified by its name
131
- #
132
- # This method will use a custom mapper if it was configured. ie if you have
133
- # a relation called `:users` and a mapper configured for `:users` relation,
134
- # then by default this mapper will be used.
135
- #
136
- # @example
137
- # rom.relation(:users)
138
- # rom.relation(:users).by_name('Jane')
139
- #
140
- # # block syntax allows accessing lower-level query DSLs (usage is discouraged though)
141
- # rom.relation { |r| r.restrict(name: 'Jane') }
142
- #
143
- # # with mapping
144
- # rom.relation(:users).map_with(:presenter)
145
- #
146
- # # using multiple mappers
147
- # rom.relation(:users).page(1).map_with(:presenter, :json_serializer)
148
- #
149
- # @param [Symbol] name of the relation to load
150
- #
151
- # @yield [Relation]
152
- #
153
- # @return [Relation]
154
- #
155
- # @api public
156
- def relation(name, &block)
157
- Dry::Core::Deprecations.warn("#{self.class}#relation is deprecated and will be removed in 4.0\n\n#{caller[0..5].join("\n")}")
158
-
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
- Dry::Core::Deprecations.warn("#{self.class}#command is deprecated and will be removed in 4.0\n\n#{caller[0..5].join("\n")}")
194
-
195
- case options
196
- when Symbol
197
- name = options
198
- if mappers.key?(name)
199
- commands[name].with(mappers: mappers[name])
200
- else
201
- commands[name]
202
- end
203
- when Array
204
- graph = Commands::Graph.build(commands, options)
205
- name = graph.name
206
-
207
- if mappers.key?(name)
208
- graph.with(mappers: mappers[name])
209
- else
210
- graph
211
- end
212
- when nil
213
- Commands::Graph::Builder.new(self)
214
- else
215
- raise ArgumentError, "#{self.class}#command accepts a symbol or an array"
216
- end
217
- end
218
-
219
- # Disconnect all gateways
220
- #
221
- # @example
222
- # rom = ROM.container(:sql, 'sqlite://my_db.sqlite')
223
- # rom.relations[:users].insert(name: "Jane")
224
- # rom.disconnect
225
- #
226
- # @return [Hash<Symbol=>Gateway>] a hash with disconnected gateways
227
- #
228
- # @api public
229
- def disconnect
230
- gateways.each_value(&:disconnect)
231
- end
232
- end
233
- end
@@ -1,60 +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
- attr_reader :container
9
-
10
- def initialize(environment, setup)
11
- @container = finalize(environment, setup)
12
- end
13
-
14
- private
15
-
16
- def finalize(environment, setup)
17
- environment.configure do |config|
18
- environment.gateways.each_key do |key|
19
- gateway_config = config.gateways[key]
20
- gateway_config.infer_relations = true unless gateway_config.key?(:infer_relations)
21
- end
22
- end
23
-
24
- finalize = Finalize.new(
25
- gateways: environment.gateways,
26
- gateway_map: environment.gateways_map,
27
- relation_classes: setup.relation_classes,
28
- command_classes: setup.command_classes,
29
- mappers: setup.mapper_classes,
30
- plugins: setup.plugins,
31
- config: environment.config.dup.freeze
32
- )
33
-
34
- finalize.run!
35
- end
36
- end
37
-
38
- class InlineCreateContainer < CreateContainer
39
- def initialize(*args, &block)
40
- case args.first
41
- when Configuration
42
- environment = args.first.environment
43
- setup = args.first.setup
44
- when Environment
45
- environment = args.first
46
- setup = args[1]
47
- else
48
- configuration = Configuration.new(*args, &block)
49
- environment = configuration.environment
50
- setup = configuration.setup
51
- end
52
-
53
- super(environment, setup)
54
- end
55
- end
56
-
57
- def self.container(*args, &block)
58
- InlineCreateContainer.new(*args, &block).container
59
- end
60
- end
@@ -1,94 +0,0 @@
1
- module ROM
2
- # Helper module for dataset classes
3
- #
4
- # It provides a constructor accepting data, header and an optional row_proc.
5
- # This module is used internally by EnumerableDataset and ArrayDataset.
6
- #
7
- # @private
8
- module DataProxy
9
- NON_FORWARDABLE = [
10
- :each, :to_a, :to_ary, :kind_of?, :instance_of?, :is_a?
11
- ].freeze
12
-
13
- # Wrapped data array
14
- #
15
- # @return [Object] Data object for the iterator
16
- #
17
- # @api private
18
- attr_reader :data
19
-
20
- # @return [Proc] tuple processing proc
21
- #
22
- # @api private
23
- attr_reader :row_proc
24
-
25
- # Extends the class with `forward` DSL and Equalizer using `data` attribute
26
- #
27
- # @see ClassMethods#forward
28
- #
29
- # @api private
30
- def self.included(klass)
31
- klass.class_eval do
32
- extend ClassMethods
33
-
34
- include Dry::Equalizer(:data)
35
-
36
- option :row_proc, default: -> { self.class.row_proc }
37
- end
38
- end
39
-
40
- # Iterate over data using row_proc
41
- #
42
- # @return [Enumerator] if block is not given
43
- #
44
- # @api private
45
- def each
46
- return to_enum unless block_given?
47
- data.each { |tuple| yield(row_proc[tuple]) }
48
- end
49
-
50
- module ClassMethods
51
- # Default no-op tuple proc
52
- #
53
- # @return [Proc]
54
- #
55
- # @api private
56
- def row_proc
57
- -> tuple { tuple }
58
- end
59
-
60
- # Forward provided methods to the underlaying data object
61
- #
62
- # @example
63
- #
64
- # class MyDataset
65
- # include DataProxy
66
- #
67
- # forward(:find_all, :map)
68
- # end
69
- #
70
- # @return [undefined]
71
- #
72
- # @api public
73
- def forward(*methods)
74
- # FIXME: we should probably raise if one of the non-forwardable methods
75
- # was provided
76
- (methods - NON_FORWARDABLE).each do |method_name|
77
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
78
- def #{method_name}(*args, &block)
79
- response = data.public_send(#{method_name.inspect}, *args, &block)
80
-
81
- if response.equal?(data)
82
- self
83
- elsif response.is_a?(data.class)
84
- self.class.new(response)
85
- else
86
- response
87
- end
88
- end
89
- RUBY
90
- end
91
- end
92
- end
93
- end
94
- end