rom 2.0.2 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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/pipeline.rb DELETED
@@ -1,106 +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
- alias_method :as, :map_with
44
-
45
- # Forwards messages to the left side of a pipeline
46
- #
47
- # @api private
48
- module Proxy
49
- # @api private
50
- def respond_to_missing?(name, include_private = false)
51
- left.respond_to?(name) || super
52
- end
53
-
54
- private
55
-
56
- # Check if response from method missing should be decorated
57
- #
58
- # @api private
59
- def decorate?(response)
60
- response.is_a?(left.class)
61
- end
62
-
63
- # @api private
64
- def method_missing(name, *args, &block)
65
- if left.respond_to?(name)
66
- response = left.__send__(name, *args, &block)
67
-
68
- if decorate?(response)
69
- self.class.new(response, right)
70
- else
71
- response
72
- end
73
- else
74
- super
75
- end
76
- end
77
- end
78
-
79
- # Base composite class with left-to-right pipeline behavior
80
- #
81
- # @api private
82
- class Composite
83
- include Dry::Equalizer(:left, :right)
84
- include Proxy
85
-
86
- # @api private
87
- attr_reader :left
88
-
89
- # @api private
90
- attr_reader :right
91
-
92
- # @api private
93
- def initialize(left, right)
94
- @left = left
95
- @right = right
96
- end
97
-
98
- # Compose this composite with another object
99
- #
100
- # @api public
101
- def >>(other)
102
- self.class.new(self, other)
103
- end
104
- end
105
- end
106
- end
data/lib/rom/plugin.rb DELETED
@@ -1,17 +0,0 @@
1
- require 'rom/plugin_base'
2
-
3
- module ROM
4
- # Plugin is a simple object used to store plugin configurations
5
- #
6
- # @private
7
- class Plugin < PluginBase
8
- # Apply this plugin to the provided class
9
- #
10
- # @param [Class] klass
11
- #
12
- # @api private
13
- def apply_to(klass)
14
- klass.send(:include, mod)
15
- end
16
- end
17
- end
@@ -1,31 +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
- def initialize(mod, options)
18
- @mod = mod
19
- @options = options
20
- end
21
-
22
- # Apply this plugin to the provided class
23
- #
24
- # @param [Mixed] base
25
- #
26
- # @api private
27
- def apply_to(_base)
28
- raise NotImplementedError, "#{self.class}#apply_to not implemented"
29
- end
30
- end
31
- end
@@ -1,173 +0,0 @@
1
- require 'rom/support/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.schema_hash[input[tuple]] }
24
- elsif relation.schema?
25
- relation.schema_hash
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,17 +0,0 @@
1
- require 'rom/configuration_dsl'
2
- require 'rom/support/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
- ROM::Deprecations.announce(:macros, "Calling `use(:macros)` is no longer necessary. Macros are enabled by default.")
14
- end
15
- end
16
- end
17
- end
@@ -1,46 +0,0 @@
1
- module ROM
2
- module Plugins
3
- module Relation
4
- module KeyInference
5
- # Infer foreign_key name for this relation
6
- #
7
- # TODO: this should be configurable and handled by an injected policy
8
- #
9
- # @return [Symbol]
10
- #
11
- # @api private
12
- def foreign_key(other = nil)
13
- if other
14
- if schema
15
- rel_name = other.respond_to?(:to_sym) ?
16
- ROM::Relation::Name[other.to_sym] : other.base_name
17
-
18
- key = schema.foreign_key(rel_name.dataset)
19
- key ? key.meta[:name] : __registry__[rel_name].foreign_key
20
- else
21
- relation = other.respond_to?(:to_sym) ?
22
- __registry__[other] : other
23
-
24
- relation.foreign_key
25
- end
26
- else
27
- :"#{Inflector.singularize(name.dataset)}_id"
28
- end
29
- end
30
-
31
- # Return base name which defaults to name attribute
32
- #
33
- # @return [ROM::Relation::Name]
34
- #
35
- # @api private
36
- def base_name
37
- name
38
- end
39
- end
40
- end
41
- end
42
- end
43
-
44
- ROM.plugins do
45
- register :key_inference, ROM::Plugins::Relation::KeyInference, type: :relation
46
- end
@@ -1,32 +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
- klass.option :__registry__, type: RelationRegistry, default: EMPTY_REGISTRY, reader: true
16
- end
17
-
18
- # @api private
19
- def respond_to_missing?(name, _include_private = false)
20
- __registry__.key?(name) || super
21
- end
22
-
23
- private
24
-
25
- # @api private
26
- def method_missing(name, *)
27
- __registry__.fetch(name) { super }
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,32 +0,0 @@
1
- module ROM
2
- module Plugins
3
- module Relation
4
- module View
5
- class DSL
6
- attr_reader :name
7
-
8
- attr_reader :attributes
9
-
10
- attr_reader :relation_block
11
-
12
- def initialize(name, &block)
13
- @name = name
14
- instance_eval(&block)
15
- end
16
-
17
- def header(*args, &block)
18
- @attributes = args.size > 0 ? args.first : block
19
- end
20
-
21
- def relation(&block)
22
- @relation_block = lambda(&block)
23
- end
24
-
25
- def call
26
- [name, attributes, relation_block]
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,95 +0,0 @@
1
- require 'rom/plugins/relation/view/dsl'
2
-
3
- module ROM
4
- module Plugins
5
- module Relation
6
- module View
7
- def self.included(klass)
8
- super
9
-
10
- klass.class_eval do
11
- extend ClassInterface
12
-
13
- option :view, reader: true
14
- option :attributes
15
-
16
- def self.attributes
17
- @__attributes__ ||= {}
18
- end
19
- end
20
- end
21
-
22
- # Return column names that will be selected for this relation
23
- #
24
- # By default we use dataset columns but first we look at configured
25
- # attributes by `view` DSL
26
- #
27
- # @return [Array<Symbol>]
28
- #
29
- # @api private
30
- def attributes(view_name = view)
31
- if options.key?(:attributes)
32
- options[:attributes]
33
- else
34
- header = self.class.attributes
35
- .fetch(view_name, self.class.attributes.fetch(:base))
36
-
37
- if header.is_a?(Proc)
38
- instance_exec(&header)
39
- else
40
- header
41
- end
42
- end
43
- end
44
-
45
- module ClassInterface
46
- # Define a relation view with a specific header
47
- #
48
- # With headers defined all the mappers will be inferred automatically
49
- #
50
- # @example
51
- # class Users < ROM::Relation[:sql]
52
- # view(:by_name, [:id, :name]) do |name|
53
- # where(name: name)
54
- # end
55
- #
56
- # view(:listing, [:id, :name, :email]) do
57
- # select(:id, :name, :email).order(:name)
58
- # end
59
- # end
60
- #
61
- # @api public
62
- def view(*args, &block)
63
- if args.size == 1 && block.arity > 0
64
- raise ArgumentError, "header must be set as second argument"
65
- end
66
-
67
- name, names, relation_block =
68
- if args.size == 1
69
- DSL.new(*args, &block).call
70
- else
71
- [*args, block]
72
- end
73
-
74
- attributes[name] = names
75
-
76
- if relation_block.arity > 0
77
- auto_curry_guard do
78
- define_method(name, &relation_block)
79
- auto_curry(name) { with(view: name) }
80
- end
81
- else
82
- define_method(name) do
83
- instance_exec(&relation_block).with(view: name)
84
- end
85
- end
86
- end
87
- end
88
- end
89
- end
90
- end
91
- end
92
-
93
- ROM.plugins do
94
- register :view, ROM::Plugins::Relation::View, type: :relation
95
- end