rom 2.0.2 → 5.2.5

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 +122 -324
  3. data/LICENSE +17 -17
  4. data/README.md +91 -22
  5. data/lib/rom/version.rb +3 -1
  6. data/lib/rom.rb +4 -46
  7. metadata +42 -245
  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
@@ -1,34 +0,0 @@
1
- module ROM
2
- module Commands
3
- class Lazy
4
- class Update < Lazy
5
- def call(*args)
6
- first = args.first
7
- last = args.last
8
- size = args.size
9
-
10
- if size > 1 && last.is_a?(Array)
11
- last.map.with_index do |parent, index|
12
- children = evaluator.call(first, index)
13
-
14
- children.map do |child|
15
- command_proc[command, parent, child].call(child, parent)
16
- end
17
- end.reduce(:concat)
18
- else
19
- input = evaluator.call(first)
20
-
21
- if input.is_a?(Array)
22
- input.map.with_index do |item, index|
23
- command_proc[command, last, item].call(item, *args[1..size-1])
24
- end
25
- else
26
- command_proc[command, *(size > 1 ? [last, input] : [input])]
27
- .call(input, *args[1..size-1])
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,99 +0,0 @@
1
- require 'rom/commands/composite'
2
- require 'rom/commands/graph'
3
-
4
- module ROM
5
- module Commands
6
- # Lazy command wraps another command and evaluates its input when called
7
- #
8
- # @api private
9
- class Lazy
10
- include Dry::Equalizer(:command, :evaluator)
11
-
12
- # @attr_reader [Command] command The wrapped command
13
- attr_reader :command
14
-
15
- alias_method :unwrap, :command
16
-
17
- # @attr_reader [Proc] evaluator The proc that will evaluate the input
18
- attr_reader :evaluator
19
-
20
- attr_reader :command_proc
21
-
22
- # @api private
23
- def self.[](command)
24
- case command
25
- when Commands::Create then Lazy::Create
26
- when Commands::Update then Lazy::Update
27
- when Commands::Delete then Lazy::Delete
28
- else
29
- self
30
- end
31
- end
32
-
33
- # @api private
34
- def initialize(command, evaluator, command_proc = nil)
35
- @command = command
36
- @evaluator = evaluator
37
- @command_proc = command_proc || proc { |*| command }
38
- end
39
-
40
- # Evaluate command's input using the input proc and pass to command
41
- #
42
- # @return [Array,Hash]
43
- #
44
- # @api public
45
- def call(*args)
46
- raise NotImplementedError
47
- end
48
-
49
- # Compose a lazy command with another one
50
- #
51
- # @see Commands::Abstract#>>
52
- #
53
- # @return [Composite]
54
- #
55
- # @api public
56
- def >>(other)
57
- Composite.new(self, other)
58
- end
59
-
60
- # @see Abstract#combine
61
- #
62
- # @api public
63
- def combine(*others)
64
- Graph.new(self, others)
65
- end
66
-
67
- # @api private
68
- def lazy?
69
- true
70
- end
71
-
72
- # @api private
73
- def respond_to_missing?(name, include_private = false)
74
- super || command.respond_to?(name)
75
- end
76
-
77
- private
78
-
79
- # @api private
80
- def method_missing(name, *args, &block)
81
- if command.respond_to?(name)
82
- response = command.public_send(name, *args, &block)
83
-
84
- if response.instance_of?(command.class)
85
- self.class.new(response, evaluator, command_proc)
86
- else
87
- response
88
- end
89
- else
90
- super
91
- end
92
- end
93
- end
94
- end
95
- end
96
-
97
- require 'rom/commands/lazy/create'
98
- require 'rom/commands/lazy/update'
99
- require 'rom/commands/lazy/delete'
@@ -1,96 +0,0 @@
1
- module ROM
2
- module Commands
3
- # Abstract result class for success and error results
4
- #
5
- # @api public
6
- class Result
7
- # Return command execution result
8
- #
9
- # @api public
10
- attr_reader :value
11
-
12
- # Return potential command execution result error
13
- #
14
- # @api public
15
- attr_reader :error
16
-
17
- # Coerce result to an array
18
- #
19
- # @abstract
20
- #
21
- # @api public
22
- def to_ary
23
- raise NotImplementedError
24
- end
25
- alias_method :to_a, :to_ary
26
-
27
- # Return true if command successful
28
- #
29
- # @api public
30
- def success?
31
- is_a?(Success)
32
- end
33
-
34
- # Return true if command failed
35
- #
36
- # @api public
37
- def failure?
38
- is_a?(Failure)
39
- end
40
-
41
- # Success result has a value and no error
42
- #
43
- # @api public
44
- class Success < Result
45
- # @api private
46
- def initialize(value)
47
- @value = value.is_a?(self.class) ? value.value : value
48
- end
49
-
50
- # Call next command on continuation
51
- #
52
- # @api public
53
- def >(other)
54
- other.call(value)
55
- end
56
-
57
- # Return the value
58
- #
59
- # @return [Array]
60
- #
61
- # @api public
62
- def to_ary
63
- value.to_ary
64
- end
65
- end
66
-
67
- # Failure result has an error and no value
68
- #
69
- # @api public
70
- class Failure < Result
71
- # @api private
72
- def initialize(error)
73
- @error = error
74
- end
75
-
76
- # Do not call next command on continuation
77
- #
78
- # @return [self]
79
- #
80
- # @api public
81
- def >(_other)
82
- self
83
- end
84
-
85
- # Return the error
86
- #
87
- # @return [Array<CommandError>]
88
- #
89
- # @api public
90
- def to_ary
91
- error
92
- end
93
- end
94
- end
95
- end
96
- end
@@ -1,14 +0,0 @@
1
- require 'rom/command'
2
-
3
- module ROM
4
- module Commands
5
- # Update command
6
- #
7
- # This command updates all tuples in its relation with new attributes
8
- #
9
- # @abstract
10
- class Update < Command
11
- restrictable true
12
- end
13
- end
14
- end
data/lib/rom/commands.rb DELETED
@@ -1,3 +0,0 @@
1
- require 'rom/commands/create'
2
- require 'rom/commands/update'
3
- require 'rom/commands/delete'
@@ -1,88 +0,0 @@
1
- require 'rom/environment'
2
- require 'rom/setup'
3
- require 'rom/configuration_dsl'
4
-
5
- module ROM
6
- class Configuration
7
- extend Forwardable
8
- include ROM::ConfigurationDSL
9
-
10
- NoDefaultAdapterError = Class.new(StandardError)
11
-
12
- attr_reader :environment, :setup
13
-
14
- def_delegators :@setup, :register_relation, :register_command, :register_mapper,
15
- :relation_classes, :command_classes, :mapper_classes,
16
- :auto_registration
17
-
18
- def_delegators :@environment, :gateways, :gateways_map, :configure, :config
19
-
20
- # @api public
21
- def initialize(*args, &block)
22
- @environment = Environment.new(*args)
23
- @setup = Setup.new
24
-
25
- block.call(self) unless block.nil?
26
- end
27
-
28
- # Apply a plugin to the configuration
29
- #
30
- # @param [Mixed] The plugin identifier, usually a Symbol
31
- # @param [Hash] Plugin options
32
- #
33
- # @api public
34
- def use(plugin, options = {})
35
- if plugin.is_a?(Array)
36
- plugin.each { |p| use(p) }
37
- elsif plugin.is_a?(Hash)
38
- plugin.to_a.each { |p| use(*p) }
39
- else
40
- ROM.plugin_registry.configuration.fetch(plugin).apply_to(self, options)
41
- end
42
-
43
- self
44
- end
45
-
46
- # Return gateway identified by name
47
- #
48
- # @return [Gateway]
49
- #
50
- # @api private
51
- def [](name)
52
- gateways.fetch(name)
53
- end
54
-
55
- # Returns gateway if method is a name of a registered gateway
56
- #
57
- # @return [Gateway]
58
- #
59
- # @api private
60
- def method_missing(name, *)
61
- gateways.fetch(name) { super }
62
- end
63
-
64
- # Hook for respond_to? used internally
65
- #
66
- # @api private
67
- def respond_to?(name, include_all=false)
68
- gateways.has_key?(name) || super
69
- end
70
-
71
- # @api private
72
- def default_gateway
73
- @default_gateway ||= gateways[:default]
74
- end
75
-
76
- # @api private
77
- def adapter_for_gateway(gateway)
78
- ROM.adapters.select do |key, value|
79
- value.const_defined?(:Gateway) && gateway.kind_of?(value.const_get(:Gateway))
80
- end.keys.first
81
- end
82
-
83
- # @api private
84
- def default_adapter
85
- @default_adapter ||= adapter_for_gateway(default_gateway) || ROM.adapters.keys.first
86
- end
87
- end
88
- end
@@ -1,43 +0,0 @@
1
- require 'rom/support/constants'
2
-
3
- require 'rom/support/inflector'
4
- require 'rom/support/class_builder'
5
-
6
- module ROM
7
- module ConfigurationDSL
8
- # Setup DSL-specific command extensions
9
- #
10
- # @private
11
- class Command
12
- # Generate a command subclass
13
- #
14
- # This is used by Setup#commands DSL and its `define` block
15
- #
16
- # @api private
17
- def self.build_class(name, relation, options = EMPTY_HASH, &block)
18
- type = options.fetch(:type) { name }
19
- command_type = Inflector.classify(type)
20
- adapter = options.fetch(:adapter)
21
- parent = ROM::Command.adapter_namespace(adapter).const_get(command_type)
22
- class_name = generate_class_name(adapter, command_type, relation)
23
-
24
- ClassBuilder.new(name: class_name, parent: parent).call do |klass|
25
- klass.register_as(name)
26
- klass.relation(relation)
27
- klass.class_eval(&block) if block
28
- end
29
- end
30
-
31
- # Create a command subclass name based on adapter, type and relation
32
- #
33
- # @api private
34
- def self.generate_class_name(adapter, command_type, relation)
35
- pieces = ['ROM']
36
- pieces << Inflector.classify(adapter)
37
- pieces << 'Commands'
38
- pieces << "#{command_type}[#{Inflector.classify(relation)}s]"
39
- pieces.join('::')
40
- end
41
- end
42
- end
43
- end
@@ -1,35 +0,0 @@
1
- require 'rom/configuration_dsl/command'
2
-
3
- module ROM
4
- module ConfigurationDSL
5
- # Command `define` DSL used by Setup#commands
6
- #
7
- # @private
8
- class CommandDSL
9
- attr_reader :relation, :adapter, :command_classes
10
-
11
- # @api private
12
- def initialize(relation, adapter = nil, &block)
13
- @relation = relation
14
- @adapter = adapter
15
- @command_classes = []
16
- instance_exec(&block)
17
- end
18
-
19
- # Define a command class
20
- #
21
- # @param [Symbol] name of the command
22
- # @param [Hash] options
23
- # @option options [Symbol] :type The type of the command
24
- #
25
- # @return [Class] generated class
26
- #
27
- # @api public
28
- def define(name, options = EMPTY_HASH, &block)
29
- @command_classes << Command.build_class(
30
- name, relation, { adapter: adapter }.merge(options), &block
31
- )
32
- end
33
- end
34
- end
35
- end
@@ -1,37 +0,0 @@
1
- require 'rom/support/constants'
2
- require 'rom/support/class_builder'
3
-
4
- module ROM
5
- module ConfigurationDSL
6
- # Setup DSL-specific mapper extensions
7
- #
8
- # @private
9
- class Mapper
10
- # Generate a mapper subclass
11
- #
12
- # This is used by Setup#mappers DSL
13
- #
14
- # @api private
15
- def self.build_class(name, mapper_registry, options = EMPTY_HASH, &block)
16
- class_name = "ROM::Mapper[#{name}]"
17
-
18
- parent = options[:parent]
19
- inherit_header = options.fetch(:inherit_header) { ROM::Mapper.inherit_header }
20
-
21
- parent_class =
22
- if parent
23
- mapper_registry.detect { |klass| klass.relation == parent }
24
- else
25
- ROM::Mapper
26
- end
27
-
28
- ClassBuilder.new(name: class_name, parent: parent_class).call do |klass|
29
- klass.relation(name)
30
- klass.inherit_header(inherit_header)
31
-
32
- klass.class_eval(&block) if block
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,44 +0,0 @@
1
- require 'rom/support/constants'
2
- require 'rom/configuration_dsl/mapper'
3
-
4
- module ROM
5
- module ConfigurationDSL
6
- # Mapper definition DSL used by Setup DSL
7
- #
8
- # @private
9
- class MapperDSL
10
- attr_reader :registry, :mapper_classes, :mapper_classes
11
-
12
- # @api private
13
- def initialize(registry, mapper_classes, block)
14
- @registry = registry
15
- @mapper_classes = mapper_classes
16
- @defined_mappers = []
17
-
18
- instance_exec(&block)
19
-
20
- @mapper_classes = @defined_mappers
21
- end
22
-
23
- # Define a mapper class
24
- #
25
- # @param [Symbol] name of the mapper
26
- # @param [Hash] options
27
- #
28
- # @return [Class]
29
- #
30
- # @api public
31
- def define(name, options = EMPTY_HASH, &block)
32
- @defined_mappers << Mapper.build_class(name, (@mapper_classes + @defined_mappers), options, &block)
33
- self
34
- end
35
-
36
- # TODO
37
- #
38
- # @api public
39
- def register(relation, mappers)
40
- registry.register_mapper(relation => mappers)
41
- end
42
- end
43
- end
44
- end
@@ -1,26 +0,0 @@
1
- require 'rom/support/constants'
2
- require 'rom/support/class_builder'
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[#{Inflector.camelize(name)}]"
17
- adapter = options.fetch(:adapter)
18
-
19
- ClassBuilder.new(name: class_name, parent: ROM::Relation[adapter]).call do |klass|
20
- klass.gateway(options.fetch(:gateway, :default))
21
- klass.dataset(name)
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,78 +0,0 @@
1
- require 'rom/support/constants'
2
-
3
- require 'rom/configuration_dsl/relation'
4
- require 'rom/configuration_dsl/mapper_dsl'
5
- require 'rom/configuration_dsl/command_dsl'
6
-
7
- module ROM
8
- # This extends Configuration class with the DSL methods
9
- #
10
- # @api public
11
- module ConfigurationDSL
12
- # Relation definition DSL
13
- #
14
- # @example
15
- #
16
- # setup.relation(:users) do
17
- # def names
18
- # project(:name)
19
- # end
20
- # end
21
- #
22
- # @api public
23
- def relation(name, options = EMPTY_HASH, &block)
24
- klass_opts = { adapter: default_adapter }.merge(options)
25
- klass = Relation.build_class(name, klass_opts)
26
- klass.register_as(name)
27
- klass.class_eval(&block) if block
28
- register_relation(klass)
29
- klass
30
- end
31
-
32
- # Mapper definition DSL
33
- #
34
- # @example
35
- #
36
- # setup.mappers do
37
- # define(:users) do
38
- # model name: 'User'
39
- # end
40
- #
41
- # define(:names, parent: :users) do
42
- # exclude :id
43
- # end
44
- # end
45
- #
46
- # @api public
47
- def mappers(&block)
48
- register_mapper(*MapperDSL.new(self, mapper_classes, block).mapper_classes)
49
- end
50
-
51
- # Command definition DSL
52
- #
53
- # @example
54
- #
55
- # setup.commands(:users) do
56
- # define(:create) do
57
- # input NewUserParams
58
- # validator NewUserValidator
59
- # result :one
60
- # end
61
- #
62
- # define(:update) do
63
- # input UserParams
64
- # validator UserValidator
65
- # result :many
66
- # end
67
- #
68
- # define(:delete) do
69
- # result :many
70
- # end
71
- # end
72
- #
73
- # @api public
74
- def commands(name, &block)
75
- register_command(*CommandDSL.new(name, default_adapter, &block).command_classes)
76
- end
77
- end
78
- 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,30 +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
- DuplicateConfigurationError = Class.new(StandardError)
26
- DuplicateContainerError = Class.new(StandardError)
27
-
28
- InvalidOptionValueError = Class.new(StandardError)
29
- InvalidOptionKeyError = Class.new(StandardError)
30
- end