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
data/lib/rom/pipeline.rb DELETED
@@ -1,122 +0,0 @@
1
- module ROM
2
- # Data pipeline common interface
3
- #
4
- # @api private
5
- module Pipeline
6
- # Common `>>` operator extension
7
- #
8
- # @api private
9
- module Operator
10
- # Compose two relation with a left-to-right composition
11
- #
12
- # @example
13
- # users.by_name('Jane') >> tasks.for_users
14
- #
15
- # @param [Relation] other The right relation
16
- #
17
- # @return [Relation::Composite]
18
- #
19
- # @api public
20
- def >>(other)
21
- composite_class.new(self, other)
22
- end
23
-
24
- private
25
-
26
- # @api private
27
- def composite_class
28
- raise NotImplementedError
29
- end
30
- end
31
-
32
- include Operator
33
-
34
- # Send data through specified mappers
35
- #
36
- # @return [Relation::Composite]
37
- #
38
- # @api public
39
- def map_with(*names)
40
- [self, *names.map { |name| mappers[name] }]
41
- .reduce { |a, e| composite_class.new(a, e) }
42
- end
43
-
44
- # @api public
45
- def as(*names)
46
- new_meth = names[0].is_a?(Class) ? 'map_to' : 'map_with'
47
-
48
- msg = <<-STR
49
- Relation#as will change behavior in 4.0. Use `#{new_meth}` instead
50
- => Called at:
51
- #{caller.join("\n")}
52
- STR
53
-
54
- Dry::Core::Deprecations.warn(msg)
55
-
56
- map_with(*names)
57
- end
58
-
59
- # Forwards messages to the left side of a pipeline
60
- #
61
- # @api private
62
- module Proxy
63
- # @api private
64
- def respond_to_missing?(name, include_private = false)
65
- left.respond_to?(name) || super
66
- end
67
-
68
- private
69
-
70
- # Check if response from method missing should be decorated
71
- #
72
- # @api private
73
- def decorate?(response)
74
- response.is_a?(left.class)
75
- end
76
-
77
- # @api private
78
- def method_missing(name, *args, &block)
79
- if left.respond_to?(name)
80
- response = left.__send__(name, *args, &block)
81
-
82
- if decorate?(response)
83
- self.class.new(response, right)
84
- else
85
- response
86
- end
87
- else
88
- super
89
- end
90
- end
91
- end
92
-
93
- # Base composite class with left-to-right pipeline behavior
94
- #
95
- # @api private
96
- class Composite
97
- (Kernel.private_instance_methods - %i(respond_to_missing?)).each(&method(:undef_method))
98
-
99
- include Dry::Equalizer(:left, :right)
100
- include Proxy
101
-
102
- # @api private
103
- attr_reader :left
104
-
105
- # @api private
106
- attr_reader :right
107
-
108
- # @api private
109
- def initialize(left, right)
110
- @left = left
111
- @right = right
112
- end
113
-
114
- # Compose this composite with another object
115
- #
116
- # @api public
117
- def >>(other)
118
- self.class.new(self, other)
119
- end
120
- end
121
- end
122
- end
data/lib/rom/plugin.rb DELETED
@@ -1,20 +0,0 @@
1
- require 'rom/plugin_base'
2
- require 'rom/support/configurable'
3
-
4
- module ROM
5
- # Plugin is a simple object used to store plugin configurations
6
- #
7
- # @private
8
- class Plugin < PluginBase
9
- include Configurable
10
-
11
- # Apply this plugin to the provided class
12
- #
13
- # @param [Class] klass
14
- #
15
- # @api private
16
- def apply_to(klass)
17
- klass.send(:include, mod)
18
- end
19
- end
20
- end
@@ -1,40 +0,0 @@
1
- module ROM
2
- # Abstract plugin base
3
- #
4
- # @private
5
- class PluginBase
6
- # @return [Module] a module representing the plugin
7
- #
8
- # @api private
9
- attr_reader :mod
10
-
11
- # @return [Hash] configuration options
12
- #
13
- # @api private
14
- attr_reader :options
15
-
16
- # @api private
17
- attr_reader :type
18
-
19
- # @api private
20
- def initialize(mod, options)
21
- @mod = mod
22
- @options = options
23
- @type = options.fetch(:type)
24
- end
25
-
26
- # @api private
27
- def relation?
28
- type == :relation
29
- end
30
-
31
- # Apply this plugin to the provided class
32
- #
33
- # @param [Mixed] base
34
- #
35
- # @api private
36
- def apply_to(_base)
37
- raise NotImplementedError, "#{self.class}#apply_to not implemented"
38
- end
39
- end
40
- end
@@ -1,173 +0,0 @@
1
- require 'rom/registry'
2
-
3
- module ROM
4
- # Stores all registered plugins
5
- #
6
- # @api private
7
- class PluginRegistry
8
- # Internal registry for configuration plugins
9
- #
10
- # @return [ConfigurationPluginRegistry]
11
- #
12
- # @api private
13
- attr_reader :configuration
14
-
15
- # Internal registry for command plugins
16
- #
17
- # @return [InternalPluginRegistry]
18
- #
19
- # @api private
20
- attr_reader :commands
21
-
22
- # Internal registry for mapper plugins
23
- #
24
- # @return [InternalPluginRegistry]
25
- #
26
- # @api private
27
- attr_reader :mappers
28
-
29
- # Internal registry for relation plugins
30
- #
31
- # @return [InternalPluginRegistry]
32
- #
33
- # @api private
34
- attr_reader :relations
35
-
36
- # @api private
37
- def initialize
38
- @configuration = ConfigurationPluginRegistry.new
39
- @mappers = InternalPluginRegistry.new
40
- @commands = InternalPluginRegistry.new
41
- @relations = InternalPluginRegistry.new
42
- end
43
-
44
- # Register a plugin for future use
45
- #
46
- # @param [Symbol] name The registration name for the plugin
47
- # @param [Module] mod The plugin to register
48
- # @param [Hash] options optional configuration data
49
- # @option options [Symbol] :type What type of plugin this is (command,
50
- # relation or mapper)
51
- # @option options [Symbol] :adapter (:default) which adapter this plugin
52
- # applies to. Leave blank for all adapters
53
- def register(name, mod, options = EMPTY_HASH)
54
- type = options.fetch(:type)
55
- adapter = options.fetch(:adapter, :default)
56
-
57
- plugins_for(type, adapter).register(name, mod, options)
58
- end
59
-
60
- private
61
-
62
- # Determine which specific registry to use
63
- #
64
- # @api private
65
- def plugins_for(type, adapter)
66
- case type
67
- when :configuration then configuration
68
- when :command then commands.adapter(adapter)
69
- when :mapper then mappers.adapter(adapter)
70
- when :relation then relations.adapter(adapter)
71
- end
72
- end
73
- end
74
- # Abstract registry defining common behaviour
75
- #
76
- # @api private
77
- class PluginRegistryBase < Registry
78
- # Retrieve a registered plugin
79
- #
80
- # @param [Symbol] name The plugin to retrieve
81
- #
82
- # @return [Plugin]
83
- #
84
- # @api public
85
- def [](name)
86
- elements[name]
87
- end
88
- end
89
- # A registry storing environment specific plugins
90
- #
91
- # @api private
92
- class ConfigurationPluginRegistry < PluginRegistryBase
93
- # Assign a plugin to this environment registry
94
- #
95
- # @param [Symbol] name The registered plugin name
96
- # @param [Module] mod The plugin to register
97
- # @param [Hash] options optional configuration data
98
- #
99
- # @api private
100
- def register(name, mod, options)
101
- elements[name] = ConfigurationPlugin.new(mod, options)
102
- end
103
-
104
- # Return an environment plugin
105
- #
106
- # @param [Symbol] name The name of the environment plugin
107
- #
108
- # @raises [UnknownPluginError] if no plugin is found with the given name
109
- #
110
- # @api public
111
- def fetch(name)
112
- self[name] || raise(UnknownPluginError, name)
113
- end
114
- end
115
- # A registry storing adapter specific plugins
116
- #
117
- # @api private
118
- class AdapterPluginRegistry < PluginRegistryBase
119
- # Assign a plugin to this adapter registry
120
- #
121
- # @param [Symbol] name The registered plugin name
122
- # @param [Module] mod The plugin to register
123
- # @param [Hash] options optional configuration data
124
- #
125
- # @api private
126
- def register(name, mod, options)
127
- elements[name] = Plugin.new(mod, options)
128
- end
129
- end
130
-
131
- # Store a set of registries grouped by adapter
132
- #
133
- # @api private
134
- class InternalPluginRegistry
135
- # Return the existing registries
136
- #
137
- # @return [Hash]
138
- #
139
- # @api private
140
- attr_reader :registries
141
-
142
- # @api private
143
- def initialize
144
- @registries = Hash.new { |h, v| h[v] = AdapterPluginRegistry.new }
145
- end
146
-
147
- # Return the plugin registry for a specific adapter
148
- #
149
- # @param [Symbol] name The name of the adapter
150
- #
151
- # @return [AdapterRegistry]
152
- #
153
- # @api private
154
- def adapter(name)
155
- registries[name]
156
- end
157
-
158
- # Return the plugin for a given adapter
159
- #
160
- # @param [Symbol] name The name of the plugin
161
- # @param [Symbol] adapter_name (:default) The name of the adapter used
162
- #
163
- # @raises [UnknownPluginError] if no plugin is found with the given name
164
- #
165
- # @api public
166
- def fetch(name, adapter_name = :default)
167
- adapter(adapter_name)[name] || adapter(:default)[name] ||
168
- raise(UnknownPluginError, name)
169
- end
170
-
171
- alias_method :[], :fetch
172
- end
173
- end
@@ -1,37 +0,0 @@
1
- module ROM
2
- module Plugins
3
- module Command
4
- # @api private
5
- module Schema
6
- def self.included(klass)
7
- super
8
- klass.extend(ClassInterface)
9
- end
10
-
11
- # @api private
12
- module ClassInterface
13
- # @see Command.build
14
- # @api public
15
- def build(relation, options = {})
16
- if options.key?(:input) || !relation.schema?
17
- super
18
- else
19
- default_input = options.fetch(:input, input)
20
-
21
- input_handler =
22
- if default_input != Hash && relation.schema?
23
- -> tuple { relation.input_schema[input[tuple]] }
24
- elsif relation.schema?
25
- relation.input_schema
26
- else
27
- default_input
28
- end
29
-
30
- super(relation, options.merge(input: input_handler))
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,21 +0,0 @@
1
- require 'rom/configuration_dsl'
2
- require 'dry/core/deprecations'
3
-
4
- module ROM
5
- module ConfigurationPlugins
6
- # Provides macros for defining relations, mappers and commands
7
- #
8
- # @api public
9
- module ConfigurationDSL
10
-
11
- # @api private
12
- def self.apply(configuration, options = {})
13
- Dry::Core::Deprecations.announce(
14
- :macros,
15
- "Calling `use(:macros)` is no longer necessary. Macros are enabled by default.",
16
- tag: :rom
17
- )
18
- end
19
- end
20
- end
21
- end
@@ -1,51 +0,0 @@
1
- require 'dry/core/class_attributes'
2
-
3
- module ROM
4
- module Plugins
5
- module Relation
6
- # Experimental plugin for configuring relations with an external
7
- # instrumentation system like dry-monitor or ActiveSupport::Notifications
8
- #
9
- # @api public
10
- module Instrumentation
11
- extend Dry::Core::ClassAttributes
12
-
13
- # This hooks sets up a relation class with injectible notifications object
14
- #
15
- # @api private
16
- def self.included(klass)
17
- super
18
- klass.option :notifications
19
- klass.extend(ClassInterface)
20
- klass.prepend(mixin)
21
- klass.instrument(:to_a)
22
- end
23
-
24
- defines :mixin
25
- mixin Module.new
26
-
27
- module ClassInterface
28
- def instrument(*methods)
29
- (methods - Instrumentation.mixin.instance_methods).each do |meth|
30
- Instrumentation.mixin.send(:define_method, meth) do
31
- instrument { super() }
32
- end
33
- end
34
- end
35
- end
36
-
37
- # @api public
38
- def instrument(&block)
39
- notifications.instrument(self.class.adapter, name: name.relation, **notification_payload(self), &block)
40
- end
41
-
42
- private
43
-
44
- # @api private
45
- def notification_payload(relation)
46
- EMPTY_HASH
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,48 +0,0 @@
1
- require 'dry/core/inflector'
2
-
3
- module ROM
4
- module Plugins
5
- module Relation
6
- module KeyInference
7
- # Infer foreign_key name for this relation
8
- #
9
- # TODO: this should be configurable and handled by an injected policy
10
- #
11
- # @return [Symbol]
12
- #
13
- # @api private
14
- def foreign_key(other = nil)
15
- if other
16
- if schema?
17
- rel_name = other.respond_to?(:to_sym) ?
18
- ROM::Relation::Name[other.to_sym] : other.base_name
19
-
20
- key = schema.foreign_key(rel_name.dataset)
21
- key ? key.meta[:name] : __registry__[rel_name].foreign_key
22
- else
23
- relation = other.respond_to?(:to_sym) ?
24
- __registry__[other] : other
25
-
26
- relation.foreign_key
27
- end
28
- else
29
- :"#{Dry::Core::Inflector.singularize(name.dataset)}_id"
30
- end
31
- end
32
-
33
- # Return base name which defaults to name attribute
34
- #
35
- # @return [ROM::Relation::Name]
36
- #
37
- # @api private
38
- def base_name
39
- name
40
- end
41
- end
42
- end
43
- end
44
- end
45
-
46
- ROM.plugins do
47
- register :key_inference, ROM::Plugins::Relation::KeyInference, type: :relation
48
- end
@@ -1,33 +0,0 @@
1
- module ROM
2
- module Plugins
3
- module Relation
4
- EMPTY_REGISTRY = RelationRegistry.new.freeze
5
-
6
- # Allows relations to access all other relations through registry
7
- #
8
- # For now this plugin is always enabled
9
- #
10
- # @api public
11
- module RegistryReader
12
- # @api private
13
- def self.included(klass)
14
- super
15
- return if klass.instance_methods.include?(:__registry__)
16
- klass.option :__registry__, default: -> { EMPTY_REGISTRY }
17
- end
18
-
19
- # @api private
20
- def respond_to_missing?(name, _include_private = false)
21
- __registry__.key?(name) || super
22
- end
23
-
24
- private
25
-
26
- # @api private
27
- def method_missing(name, *)
28
- __registry__.fetch(name) { super }
29
- end
30
- end
31
- end
32
- end
33
- end
data/lib/rom/registry.rb DELETED
@@ -1,50 +0,0 @@
1
- module ROM
2
- # @api private
3
- class Registry
4
- include Enumerable
5
- include Dry::Equalizer(:elements)
6
-
7
- class ElementNotFoundError < KeyError
8
- def initialize(key, name)
9
- super("#{key.inspect} doesn't exist in #{name} registry")
10
- end
11
- end
12
-
13
- attr_reader :elements, :name
14
-
15
- def initialize(elements = {}, name = self.class.name)
16
- @elements = elements
17
- @name = name
18
- end
19
-
20
- def each(&block)
21
- return to_enum unless block
22
- elements.each { |element| yield(element) }
23
- end
24
-
25
- def key?(name)
26
- !name.nil? && elements.key?(name.to_sym)
27
- end
28
-
29
- def fetch(key)
30
- raise ArgumentError.new('key cannot be nil') if key.nil?
31
-
32
- elements.fetch(key.to_sym) do
33
- return yield if block_given?
34
-
35
- raise ElementNotFoundError.new(key, name)
36
- end
37
- end
38
- alias_method :[], :fetch
39
-
40
- def respond_to_missing?(name, include_private = false)
41
- elements.key?(name) || super
42
- end
43
-
44
- private
45
-
46
- def method_missing(name, *)
47
- elements.fetch(name) { super }
48
- end
49
- end
50
- end