rom 2.0.2 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +35 -430
  3. data/LICENSE +1 -1
  4. data/README.md +83 -11
  5. data/lib/rom/version.rb +1 -1
  6. data/lib/rom.rb +3 -46
  7. metadata +30 -236
  8. data/.gitignore +0 -24
  9. data/.rspec +0 -3
  10. data/.rubocop.yml +0 -87
  11. data/.rubocop_todo.yml +0 -46
  12. data/.travis.yml +0 -28
  13. data/CODE_OF_CONDUCT.md +0 -13
  14. data/CONTRIBUTING.md +0 -1
  15. data/Gemfile +0 -41
  16. data/Guardfile +0 -24
  17. data/Rakefile +0 -22
  18. data/lib/rom/association_set.rb +0 -26
  19. data/lib/rom/command.rb +0 -173
  20. data/lib/rom/command_registry.rb +0 -153
  21. data/lib/rom/commands/class_interface.rb +0 -148
  22. data/lib/rom/commands/composite.rb +0 -54
  23. data/lib/rom/commands/create.rb +0 -13
  24. data/lib/rom/commands/delete.rb +0 -14
  25. data/lib/rom/commands/graph/builder.rb +0 -176
  26. data/lib/rom/commands/graph/class_interface.rb +0 -62
  27. data/lib/rom/commands/graph/input_evaluator.rb +0 -62
  28. data/lib/rom/commands/graph.rb +0 -103
  29. data/lib/rom/commands/lazy/create.rb +0 -23
  30. data/lib/rom/commands/lazy/delete.rb +0 -27
  31. data/lib/rom/commands/lazy/update.rb +0 -34
  32. data/lib/rom/commands/lazy.rb +0 -99
  33. data/lib/rom/commands/result.rb +0 -96
  34. data/lib/rom/commands/update.rb +0 -14
  35. data/lib/rom/commands.rb +0 -3
  36. data/lib/rom/configuration.rb +0 -88
  37. data/lib/rom/configuration_dsl/command.rb +0 -43
  38. data/lib/rom/configuration_dsl/command_dsl.rb +0 -35
  39. data/lib/rom/configuration_dsl/mapper.rb +0 -37
  40. data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -44
  41. data/lib/rom/configuration_dsl/relation.rb +0 -26
  42. data/lib/rom/configuration_dsl.rb +0 -78
  43. data/lib/rom/configuration_plugin.rb +0 -17
  44. data/lib/rom/constants.rb +0 -30
  45. data/lib/rom/container.rb +0 -231
  46. data/lib/rom/create_container.rb +0 -61
  47. data/lib/rom/environment.rb +0 -70
  48. data/lib/rom/gateway.rb +0 -154
  49. data/lib/rom/global/plugin_dsl.rb +0 -49
  50. data/lib/rom/global.rb +0 -60
  51. data/lib/rom/lint/enumerable_dataset.rb +0 -54
  52. data/lib/rom/lint/gateway.rb +0 -94
  53. data/lib/rom/lint/linter.rb +0 -78
  54. data/lib/rom/lint/spec.rb +0 -20
  55. data/lib/rom/lint/test.rb +0 -98
  56. data/lib/rom/mapper_registry.rb +0 -35
  57. data/lib/rom/memory/commands.rb +0 -58
  58. data/lib/rom/memory/dataset.rb +0 -98
  59. data/lib/rom/memory/gateway.rb +0 -64
  60. data/lib/rom/memory/relation.rb +0 -49
  61. data/lib/rom/memory/storage.rb +0 -59
  62. data/lib/rom/memory/types.rb +0 -9
  63. data/lib/rom/memory.rb +0 -4
  64. data/lib/rom/pipeline.rb +0 -106
  65. data/lib/rom/plugin.rb +0 -17
  66. data/lib/rom/plugin_base.rb +0 -31
  67. data/lib/rom/plugin_registry.rb +0 -173
  68. data/lib/rom/plugins/command/schema.rb +0 -37
  69. data/lib/rom/plugins/configuration/configuration_dsl.rb +0 -17
  70. data/lib/rom/plugins/relation/key_inference.rb +0 -46
  71. data/lib/rom/plugins/relation/registry_reader.rb +0 -32
  72. data/lib/rom/plugins/relation/view/dsl.rb +0 -32
  73. data/lib/rom/plugins/relation/view.rb +0 -95
  74. data/lib/rom/relation/class_interface.rb +0 -230
  75. data/lib/rom/relation/composite.rb +0 -46
  76. data/lib/rom/relation/curried.rb +0 -104
  77. data/lib/rom/relation/graph.rb +0 -115
  78. data/lib/rom/relation/loaded.rb +0 -118
  79. data/lib/rom/relation/materializable.rb +0 -66
  80. data/lib/rom/relation/name.rb +0 -102
  81. data/lib/rom/relation.rb +0 -172
  82. data/lib/rom/relation_registry.rb +0 -9
  83. data/lib/rom/schema/dsl.rb +0 -58
  84. data/lib/rom/schema.rb +0 -89
  85. data/lib/rom/setup/auto_registration.rb +0 -69
  86. data/lib/rom/setup/auto_registration_strategies/base.rb +0 -11
  87. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +0 -22
  88. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +0 -19
  89. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +0 -18
  90. data/lib/rom/setup/finalize/finalize_commands.rb +0 -47
  91. data/lib/rom/setup/finalize/finalize_mappers.rb +0 -36
  92. data/lib/rom/setup/finalize/finalize_relations.rb +0 -60
  93. data/lib/rom/setup/finalize.rb +0 -146
  94. data/lib/rom/setup.rb +0 -55
  95. data/lib/rom/support/configurable.rb +0 -80
  96. data/lib/rom/types.rb +0 -18
  97. data/log/.gitkeep +0 -0
  98. data/rakelib/benchmark.rake +0 -15
  99. data/rakelib/mutant.rake +0 -19
  100. data/rakelib/rubocop.rake +0 -18
  101. data/rom.gemspec +0 -26
  102. data/spec/fixtures/app/commands/create_user.rb +0 -2
  103. data/spec/fixtures/app/mappers/user_list.rb +0 -2
  104. data/spec/fixtures/app/my_commands/create_user.rb +0 -2
  105. data/spec/fixtures/app/my_mappers/user_list.rb +0 -2
  106. data/spec/fixtures/app/my_relations/users.rb +0 -2
  107. data/spec/fixtures/app/relations/users.rb +0 -2
  108. data/spec/fixtures/custom/commands/create_user.rb +0 -6
  109. data/spec/fixtures/custom/mappers/user_list.rb +0 -6
  110. data/spec/fixtures/custom/relations/users.rb +0 -6
  111. data/spec/fixtures/lib/persistence/commands/create_user.rb +0 -6
  112. data/spec/fixtures/lib/persistence/mappers/user_list.rb +0 -6
  113. data/spec/fixtures/lib/persistence/my_commands/create_user.rb +0 -6
  114. data/spec/fixtures/lib/persistence/my_mappers/user_list.rb +0 -6
  115. data/spec/fixtures/lib/persistence/my_relations/users.rb +0 -6
  116. data/spec/fixtures/lib/persistence/relations/users.rb +0 -6
  117. data/spec/integration/command_registry_spec.rb +0 -60
  118. data/spec/integration/commands/create_spec.rb +0 -177
  119. data/spec/integration/commands/delete_spec.rb +0 -67
  120. data/spec/integration/commands/error_handling_spec.rb +0 -25
  121. data/spec/integration/commands/graph_builder_spec.rb +0 -213
  122. data/spec/integration/commands/graph_spec.rb +0 -288
  123. data/spec/integration/commands/update_spec.rb +0 -109
  124. data/spec/integration/commands_spec.rb +0 -67
  125. data/spec/integration/mappers/combine_spec.rb +0 -117
  126. data/spec/integration/mappers/deep_embedded_spec.rb +0 -44
  127. data/spec/integration/mappers/definition_dsl_spec.rb +0 -206
  128. data/spec/integration/mappers/embedded_spec.rb +0 -62
  129. data/spec/integration/mappers/exclude_spec.rb +0 -27
  130. data/spec/integration/mappers/fold_spec.rb +0 -71
  131. data/spec/integration/mappers/group_spec.rb +0 -163
  132. data/spec/integration/mappers/overwrite_attributes_value_spec.rb +0 -51
  133. data/spec/integration/mappers/prefix_separator_spec.rb +0 -52
  134. data/spec/integration/mappers/prefix_spec.rb +0 -48
  135. data/spec/integration/mappers/prefixing_attributes_spec.rb +0 -37
  136. data/spec/integration/mappers/registering_custom_mappers_spec.rb +0 -28
  137. data/spec/integration/mappers/renaming_attributes_spec.rb +0 -125
  138. data/spec/integration/mappers/reusing_mappers_spec.rb +0 -43
  139. data/spec/integration/mappers/step_spec.rb +0 -119
  140. data/spec/integration/mappers/symbolizing_attributes_spec.rb +0 -77
  141. data/spec/integration/mappers/unfold_spec.rb +0 -92
  142. data/spec/integration/mappers/ungroup_spec.rb +0 -126
  143. data/spec/integration/mappers/unwrap_spec.rb +0 -93
  144. data/spec/integration/mappers/wrap_spec.rb +0 -155
  145. data/spec/integration/memory/commands/create_spec.rb +0 -23
  146. data/spec/integration/memory/commands/delete_spec.rb +0 -23
  147. data/spec/integration/memory/commands/update_spec.rb +0 -23
  148. data/spec/integration/multi_env_spec.rb +0 -69
  149. data/spec/integration/multi_repo_spec.rb +0 -46
  150. data/spec/integration/relations/default_dataset_spec.rb +0 -38
  151. data/spec/integration/relations/inheritance_spec.rb +0 -37
  152. data/spec/integration/relations/reading_spec.rb +0 -169
  153. data/spec/integration/relations/registry_dsl_spec.rb +0 -45
  154. data/spec/integration/repositories/extending_relations_spec.rb +0 -58
  155. data/spec/integration/repositories/setting_logger_spec.rb +0 -34
  156. data/spec/integration/setup_spec.rb +0 -160
  157. data/spec/shared/command_behavior.rb +0 -28
  158. data/spec/shared/command_graph.rb +0 -50
  159. data/spec/shared/container.rb +0 -9
  160. data/spec/shared/enumerable_dataset.rb +0 -52
  161. data/spec/shared/gateway_only.rb +0 -6
  162. data/spec/shared/materializable.rb +0 -36
  163. data/spec/shared/no_container.rb +0 -16
  164. data/spec/shared/one_behavior.rb +0 -26
  165. data/spec/shared/proxy.rb +0 -0
  166. data/spec/shared/users_and_tasks.rb +0 -10
  167. data/spec/spec_helper.rb +0 -52
  168. data/spec/support/constant_leak_finder.rb +0 -14
  169. data/spec/support/mutant.rb +0 -10
  170. data/spec/support/types.rb +0 -5
  171. data/spec/test/memory_repository_lint_test.rb +0 -27
  172. data/spec/unit/rom/association_set_spec.rb +0 -23
  173. data/spec/unit/rom/commands/graph_spec.rb +0 -191
  174. data/spec/unit/rom/commands/lazy_spec.rb +0 -307
  175. data/spec/unit/rom/commands/result_spec.rb +0 -70
  176. data/spec/unit/rom/commands_spec.rb +0 -165
  177. data/spec/unit/rom/configurable_spec.rb +0 -49
  178. data/spec/unit/rom/configuration_spec.rb +0 -61
  179. data/spec/unit/rom/container_spec.rb +0 -99
  180. data/spec/unit/rom/create_container_spec.rb +0 -151
  181. data/spec/unit/rom/environment_spec.rb +0 -123
  182. data/spec/unit/rom/gateway_spec.rb +0 -146
  183. data/spec/unit/rom/mapper_registry_spec.rb +0 -25
  184. data/spec/unit/rom/memory/commands_spec.rb +0 -43
  185. data/spec/unit/rom/memory/dataset_spec.rb +0 -31
  186. data/spec/unit/rom/memory/relation_spec.rb +0 -109
  187. data/spec/unit/rom/memory/repository_spec.rb +0 -12
  188. data/spec/unit/rom/memory/storage_spec.rb +0 -45
  189. data/spec/unit/rom/plugin_spec.rb +0 -150
  190. data/spec/unit/rom/plugins/command/schema_spec.rb +0 -66
  191. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +0 -85
  192. data/spec/unit/rom/plugins/relation/view_spec.rb +0 -51
  193. data/spec/unit/rom/relation/composite_spec.rb +0 -89
  194. data/spec/unit/rom/relation/curried_spec.rb +0 -52
  195. data/spec/unit/rom/relation/graph_spec.rb +0 -92
  196. data/spec/unit/rom/relation/lazy/combine_spec.rb +0 -165
  197. data/spec/unit/rom/relation/lazy_spec.rb +0 -214
  198. data/spec/unit/rom/relation/loaded_spec.rb +0 -53
  199. data/spec/unit/rom/relation/name_spec.rb +0 -58
  200. data/spec/unit/rom/relation/schema_spec.rb +0 -117
  201. data/spec/unit/rom/relation_spec.rb +0 -237
  202. data/spec/unit/rom/schema_spec.rb +0 -10
  203. data/spec/unit/rom/setup/auto_registration_spec.rb +0 -152
@@ -1,54 +0,0 @@
1
- require 'rom/pipeline'
2
- require 'rom/support/constants'
3
-
4
- module ROM
5
- module Commands
6
- # Composite command that consists of left and right commands
7
- #
8
- # @api public
9
- class Composite < Pipeline::Composite
10
- # Calls the composite command
11
- #
12
- # Right command is called with a result from the left one
13
- #
14
- # @return [Object]
15
- #
16
- # @api public
17
- def call(*args)
18
- response = left.call(*args)
19
-
20
- if response.nil? || (many? && response.size == 0)
21
- return one? ? nil : EMPTY_ARRAY
22
- end
23
-
24
- if one? && !graph?
25
- if right.is_a?(Command) || right.is_a?(Commands::Composite)
26
- right.call([response].first)
27
- else
28
- right.call([response]).first
29
- end
30
- elsif one? && graph?
31
- right.call(response).first
32
- else
33
- right.call(response)
34
- end
35
- end
36
- alias_method :[], :call
37
-
38
- # @api private
39
- def graph?
40
- left.is_a?(Graph)
41
- end
42
-
43
- # @api private
44
- def result
45
- left.result
46
- end
47
-
48
- # @api private
49
- def decorate?(response)
50
- super || response.is_a?(Graph)
51
- end
52
- end
53
- end
54
- end
@@ -1,13 +0,0 @@
1
- require 'rom/command'
2
-
3
- module ROM
4
- module Commands
5
- # Create command
6
- #
7
- # This command inserts a new tuple into a relation
8
- #
9
- # @abstract
10
- class Create < Command
11
- end
12
- end
13
- end
@@ -1,14 +0,0 @@
1
- require 'rom/command'
2
-
3
- module ROM
4
- module Commands
5
- # Delete command
6
- #
7
- # This command removes tuples from its target relation
8
- #
9
- # @abstract
10
- class Delete < Command
11
- restrictable true
12
- end
13
- end
14
- end
@@ -1,176 +0,0 @@
1
- module ROM
2
- module Commands
3
- class Graph
4
- # Command graph builder DSL
5
- #
6
- # @api public
7
- class Builder
8
- # @api private
9
- UnspecifiedRelationError = Class.new(StandardError)
10
- DoubleRestrictionError = Class.new(StandardError)
11
-
12
- # @api private
13
- class Node
14
- # @api private
15
- Restriction = Struct.new(:relation, :proc)
16
-
17
- # @api private
18
- Command = Struct.new(:name, :relation, :key, :proc)
19
-
20
- # @api private
21
- def initialize
22
- @nodes = []
23
- end
24
-
25
- # @api public
26
- def to_ast
27
- []
28
- end
29
-
30
- # Any missing method called on this is treated as a ROM command
31
- #
32
- # @api private
33
- def method_missing(*args, &block)
34
- command(*args, &block)
35
- end
36
-
37
- # @api public
38
- def command(name, relation = nil, key = nil, proc = nil, &block)
39
- if relation.is_a?(Hash)
40
- key, relation = relation.to_a.first
41
- end
42
-
43
- raise UnspecifiedRelationError if relation.nil?
44
-
45
- if relation.is_a?(RestrictionNode)
46
- RestrictionNode.new(relation.restriction).command(name, from: key, &block)
47
- else
48
- key ||= relation
49
-
50
- command = Command.new(name, relation, key, proc)
51
- node = CommandNode.new(command)
52
- block.call(node) if block
53
- node
54
- end
55
- end
56
-
57
- # @api public
58
- def restrict(name, &block)
59
- RestrictionNode.new(Restriction.new(name, block), self)
60
- end
61
- end
62
-
63
- # @api private
64
- class CommandNode < Node
65
- # @api private
66
- def initialize(command = nil)
67
- @command = command
68
- @nodes = []
69
- end
70
-
71
- # Tiny bit of synctactic sugar
72
- #
73
- # @api public
74
- def each(&block)
75
- block.call(self)
76
- end
77
-
78
- # Return command ast from this union node
79
- #
80
- # @return [Array]
81
- #
82
- # @api private
83
- def to_ast
84
- if @command.proc
85
- command = [@command.name => @command.proc]
86
- else
87
- command = [@command.name]
88
- end
89
-
90
- key_relation_map = { @command.key => @command.relation }
91
-
92
- command << @nodes.map(&:to_ast) unless @nodes.empty?
93
-
94
- [key_relation_map, command]
95
- end
96
-
97
- # @api public
98
- def command(*args, &block)
99
- node = super
100
- @nodes << node
101
- node
102
- end
103
- end
104
-
105
- # @api private
106
- class RestrictionNode < Node
107
- attr_reader :restriction
108
-
109
- def initialize(restriction, parent_node = nil)
110
- super()
111
- @restriction = restriction
112
- @parent_node = parent_node
113
- end
114
-
115
- # @api public
116
- def command(name, options = {}, &block)
117
- relation = @restriction.relation
118
- key = options[:from] || relation
119
- proc = @restriction.proc
120
-
121
- if @parent_node
122
- @parent_node.command(name, relation, key, proc, &block)
123
- else
124
- super(name, relation, key, proc, &block)
125
- end
126
- end
127
-
128
- # @api private
129
- def restrict(*args, &block)
130
- raise DoubleRestrictionError
131
- end
132
- end
133
-
134
- # @api private
135
- class RootNode < Node
136
- def to_ast
137
- if @nodes.size > 0
138
- @nodes.first.to_ast
139
- else
140
- []
141
- end
142
- end
143
-
144
- def command(*args, &block)
145
- node = super
146
- @nodes << node
147
- node
148
- end
149
- end
150
-
151
- # @api private
152
- class BuilderNode < RootNode
153
- def initialize(container)
154
- super()
155
- @container = container
156
- end
157
-
158
- def command(*args, &block)
159
- super
160
- @container.command(to_ast)
161
- end
162
- end
163
-
164
- # @api public
165
- def initialize(container)
166
- @container = container
167
- end
168
-
169
- # @api private
170
- def method_missing(*args, &block)
171
- BuilderNode.new(@container).send(*args, &block)
172
- end
173
- end
174
- end
175
- end
176
- end
@@ -1,62 +0,0 @@
1
- require 'rom/commands/graph/input_evaluator'
2
-
3
- module ROM
4
- module Commands
5
- class Graph
6
- # Class methods for command Graph
7
- #
8
- # @api private
9
- module ClassInterface
10
- # Build a command graph recursively
11
- #
12
- # This is used by `Container#command` when array with options is passed in
13
- #
14
- # @param [Registry] registry The command registry from container
15
- # @param [Array] options The options array
16
- # @param [Array] path The path for input evaluator proc
17
- #
18
- # @return [Graph]
19
- #
20
- # @api private
21
- def build(registry, options, path = EMPTY_ARRAY)
22
- options.reduce { |spec, other| build_command(registry, spec, other, path) }
23
- end
24
-
25
- # @api private
26
- def build_command(registry, spec, other, path)
27
- cmd_opts, nodes = other
28
-
29
- key, relation =
30
- if spec.is_a?(Hash)
31
- spec.to_a.first
32
- else
33
- [spec, spec]
34
- end
35
-
36
- name, opts =
37
- if cmd_opts.is_a?(Hash)
38
- cmd_opts.to_a.first
39
- else
40
- [cmd_opts]
41
- end
42
-
43
- command = registry[relation][name]
44
- tuple_path = Array[*path] << key
45
- input_proc = InputEvaluator.build(tuple_path, nodes)
46
-
47
- command = command.with(input_proc, opts)
48
-
49
- if nodes
50
- if nodes.all? { |node| node.is_a?(Array) }
51
- command.combine(*nodes.map { |node| build(registry, node, tuple_path) })
52
- else
53
- command.combine(build(registry, nodes, tuple_path))
54
- end
55
- else
56
- command
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,62 +0,0 @@
1
- module ROM
2
- module Commands
3
- class Graph
4
- class InputEvaluator
5
- include Dry::Equalizer(:tuple_path, :excluded_keys)
6
-
7
- attr_reader :tuple_path
8
-
9
- attr_reader :excluded_keys
10
-
11
- attr_reader :exclude_proc
12
-
13
- def self.build(tuple_path, nodes)
14
- new(tuple_path, extract_excluded_keys(nodes))
15
- end
16
-
17
- def self.extract_excluded_keys(nodes)
18
- return unless nodes
19
-
20
- nodes
21
- .map { |item| item.is_a?(Array) && item.size > 1 ? item.first : item }
22
- .compact
23
- .map { |item| item.is_a?(Hash) ? item.keys.first : item }
24
- .reject { |item| item.is_a?(Array) }
25
- end
26
-
27
- def self.exclude_proc(excluded_keys)
28
- -> input { input.reject { |k, _| excluded_keys.include?(k) } }
29
- end
30
-
31
- def initialize(tuple_path, excluded_keys)
32
- @tuple_path = tuple_path
33
- @excluded_keys = excluded_keys
34
- @exclude_proc = self.class.exclude_proc(excluded_keys)
35
- end
36
-
37
- def call(*args)
38
- input, index = args
39
-
40
- value =
41
- begin
42
- if index
43
- tuple_path[0..tuple_path.size-2]
44
- .reduce(input) { |a, e| a.fetch(e) }
45
- .at(index)[tuple_path.last]
46
- else
47
- tuple_path.reduce(input) { |a, e| a.fetch(e) }
48
- end
49
- rescue KeyError => e
50
- raise KeyMissing, e.message
51
- end
52
-
53
- if excluded_keys
54
- value.is_a?(Array) ? value.map(&exclude_proc) : exclude_proc[value]
55
- else
56
- value
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,103 +0,0 @@
1
- require 'rom/pipeline'
2
- require 'rom/support/options'
3
- require 'rom/commands/graph/class_interface'
4
-
5
- module ROM
6
- module Commands
7
- # Command graph
8
- #
9
- # @api private
10
- class Graph
11
- include Dry::Equalizer(:root, :nodes)
12
-
13
- extend ClassInterface
14
-
15
- include Options
16
- include Pipeline
17
- include Pipeline::Proxy
18
-
19
- # @attr_reader [Command] root The root command
20
- attr_reader :root
21
-
22
- # @attr_reader [Array<Command>] nodes The child commands
23
- attr_reader :nodes
24
-
25
- # @attr_reader [Symbol] root's relation name
26
- attr_reader :name
27
-
28
- alias_method :left, :root
29
- alias_method :right, :nodes
30
-
31
- option :mappers, reader: true, default: proc { MapperRegistry.new }
32
-
33
- # @api private
34
- def initialize(root, nodes, options = EMPTY_HASH)
35
- super
36
- @root = root
37
- @nodes = nodes
38
- @name = root.name
39
- end
40
-
41
- # Calls root and all nodes with the result from root
42
- #
43
- # Graph results are mappable through `combine` operation in mapper DSL
44
- #
45
- # @example
46
- # create_user = rom.command(:users).create
47
- # create_task = rom.command(:tasks).create
48
- #
49
- # command = create_user
50
- # .with(name: 'Jane')
51
- # .combine(create_task.with(title: 'Task'))
52
- #
53
- # command.call
54
- #
55
- # @return [Array] nested array with command results
56
- #
57
- # @api public
58
- def call(*args)
59
- left = root.call(*args)
60
-
61
- right = nodes.map { |node|
62
- response =
63
- if node.lazy?
64
- node.call(args.first, left)
65
- else
66
- node.call(left)
67
- end
68
-
69
- if node.one? && !node.graph?
70
- [response]
71
- else
72
- response
73
- end
74
- }
75
-
76
- if one?
77
- [[left], right]
78
- else
79
- [left, right]
80
- end
81
- end
82
-
83
- # Return a new graph with updated options
84
- #
85
- # @api private
86
- def with(new_options)
87
- self.class.new(root, nodes, options.merge(new_options))
88
- end
89
-
90
- # @api private
91
- def graph?
92
- true
93
- end
94
-
95
- private
96
-
97
- # @api public
98
- def composite_class
99
- Command::Composite
100
- end
101
- end
102
- end
103
- end
@@ -1,23 +0,0 @@
1
- module ROM
2
- module Commands
3
- class Lazy
4
- class Create < 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
- command_proc[command, parent, children].call(children, parent)
14
- end.reduce(:concat)
15
- else
16
- input = evaluator.call(first)
17
- command.call(input, *args[1..size-1])
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,27 +0,0 @@
1
- module ROM
2
- module Commands
3
- class Lazy
4
- class Delete < 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
- raise NotImplementedError
12
- else
13
- input = evaluator.call(first)
14
-
15
- if input.is_a?(Array)
16
- input.map do |item|
17
- command_proc[command, *(size > 1 ? [last, item] : [input])].call
18
- end
19
- else
20
- command_proc[command, input].call
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -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'