rom 3.3.3 → 4.0.0.beta1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -599
- data/lib/rom/version.rb +1 -1
- data/lib/rom.rb +3 -44
- metadata +19 -295
- data/.gitignore +0 -24
- data/.rspec +0 -3
- data/.rubocop.yml +0 -87
- data/.rubocop_todo.yml +0 -46
- data/.travis.yml +0 -24
- data/.yardopts +0 -2
- data/CODE_OF_CONDUCT.md +0 -13
- data/CONTRIBUTING.md +0 -1
- data/Gemfile +0 -54
- data/Guardfile +0 -24
- data/Rakefile +0 -28
- data/lib/rom/array_dataset.rb +0 -44
- data/lib/rom/association_set.rb +0 -49
- data/lib/rom/auto_curry.rb +0 -55
- data/lib/rom/command.rb +0 -494
- data/lib/rom/command_registry.rb +0 -148
- data/lib/rom/commands/class_interface.rb +0 -270
- data/lib/rom/commands/composite.rb +0 -53
- data/lib/rom/commands/create.rb +0 -13
- data/lib/rom/commands/delete.rb +0 -14
- data/lib/rom/commands/graph/builder.rb +0 -176
- data/lib/rom/commands/graph/class_interface.rb +0 -62
- data/lib/rom/commands/graph/input_evaluator.rb +0 -62
- data/lib/rom/commands/graph.rb +0 -95
- data/lib/rom/commands/lazy/create.rb +0 -23
- data/lib/rom/commands/lazy/delete.rb +0 -27
- data/lib/rom/commands/lazy/update.rb +0 -34
- data/lib/rom/commands/lazy.rb +0 -99
- data/lib/rom/commands/result.rb +0 -96
- data/lib/rom/commands/update.rb +0 -14
- data/lib/rom/commands.rb +0 -3
- data/lib/rom/configuration.rb +0 -90
- data/lib/rom/configuration_dsl/command.rb +0 -41
- data/lib/rom/configuration_dsl/command_dsl.rb +0 -35
- data/lib/rom/configuration_dsl/mapper.rb +0 -36
- data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -43
- data/lib/rom/configuration_dsl/relation.rb +0 -26
- data/lib/rom/configuration_dsl.rb +0 -107
- data/lib/rom/configuration_plugin.rb +0 -17
- data/lib/rom/constants.rb +0 -36
- data/lib/rom/container.rb +0 -233
- data/lib/rom/create_container.rb +0 -60
- data/lib/rom/data_proxy.rb +0 -94
- data/lib/rom/enumerable_dataset.rb +0 -68
- data/lib/rom/environment.rb +0 -70
- data/lib/rom/gateway.rb +0 -196
- data/lib/rom/global/plugin_dsl.rb +0 -47
- data/lib/rom/global.rb +0 -58
- data/lib/rom/initializer.rb +0 -26
- data/lib/rom/lint/enumerable_dataset.rb +0 -54
- data/lib/rom/lint/gateway.rb +0 -120
- data/lib/rom/lint/linter.rb +0 -78
- data/lib/rom/lint/spec.rb +0 -20
- data/lib/rom/lint/test.rb +0 -98
- data/lib/rom/mapper_registry.rb +0 -35
- data/lib/rom/memory/commands.rb +0 -56
- data/lib/rom/memory/dataset.rb +0 -97
- data/lib/rom/memory/gateway.rb +0 -64
- data/lib/rom/memory/relation.rb +0 -62
- data/lib/rom/memory/schema.rb +0 -13
- data/lib/rom/memory/storage.rb +0 -59
- data/lib/rom/memory/types.rb +0 -9
- data/lib/rom/memory.rb +0 -4
- data/lib/rom/pipeline.rb +0 -122
- data/lib/rom/plugin.rb +0 -20
- data/lib/rom/plugin_base.rb +0 -40
- data/lib/rom/plugin_registry.rb +0 -173
- data/lib/rom/plugins/command/schema.rb +0 -37
- data/lib/rom/plugins/configuration/configuration_dsl.rb +0 -21
- data/lib/rom/plugins/relation/instrumentation.rb +0 -51
- data/lib/rom/plugins/relation/key_inference.rb +0 -48
- data/lib/rom/plugins/relation/registry_reader.rb +0 -33
- data/lib/rom/registry.rb +0 -50
- data/lib/rom/relation/class_interface.rb +0 -356
- data/lib/rom/relation/composite.rb +0 -46
- data/lib/rom/relation/curried.rb +0 -109
- data/lib/rom/relation/graph.rb +0 -125
- data/lib/rom/relation/loaded.rb +0 -127
- data/lib/rom/relation/materializable.rb +0 -66
- data/lib/rom/relation/name.rb +0 -102
- data/lib/rom/relation/view_dsl.rb +0 -64
- data/lib/rom/relation.rb +0 -250
- data/lib/rom/relation_registry.rb +0 -9
- data/lib/rom/schema/attribute.rb +0 -390
- data/lib/rom/schema/dsl.rb +0 -67
- data/lib/rom/schema.rb +0 -407
- data/lib/rom/setup/auto_registration.rb +0 -74
- data/lib/rom/setup/auto_registration_strategies/base.rb +0 -16
- data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +0 -63
- data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +0 -20
- data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +0 -18
- data/lib/rom/setup/finalize/finalize_commands.rb +0 -47
- data/lib/rom/setup/finalize/finalize_mappers.rb +0 -36
- data/lib/rom/setup/finalize/finalize_relations.rb +0 -83
- data/lib/rom/setup/finalize.rb +0 -152
- data/lib/rom/setup.rb +0 -65
- data/lib/rom/support/configurable.rb +0 -85
- data/lib/rom/transaction.rb +0 -24
- data/lib/rom/types.rb +0 -49
- data/log/.gitkeep +0 -0
- data/rakelib/benchmark.rake +0 -15
- data/rakelib/mutant.rake +0 -19
- data/rakelib/rubocop.rake +0 -18
- data/rom.gemspec +0 -25
- data/spec/fixtures/app/commands/create_user.rb +0 -2
- data/spec/fixtures/app/mappers/user_list.rb +0 -2
- data/spec/fixtures/app/my_commands/create_user.rb +0 -2
- data/spec/fixtures/app/my_mappers/user_list.rb +0 -2
- data/spec/fixtures/app/my_relations/users.rb +0 -2
- data/spec/fixtures/app/relations/users.rb +0 -2
- data/spec/fixtures/custom/commands/create_user.rb +0 -6
- data/spec/fixtures/custom/mappers/user_list.rb +0 -6
- data/spec/fixtures/custom/relations/users.rb +0 -6
- data/spec/fixtures/custom_namespace/commands/create_customer.rb +0 -8
- data/spec/fixtures/custom_namespace/mappers/customer_list.rb +0 -8
- data/spec/fixtures/custom_namespace/relations/customers.rb +0 -8
- data/spec/fixtures/lib/persistence/commands/create_user.rb +0 -6
- data/spec/fixtures/lib/persistence/mappers/user_list.rb +0 -6
- data/spec/fixtures/lib/persistence/my_commands/create_user.rb +0 -6
- data/spec/fixtures/lib/persistence/my_mappers/user_list.rb +0 -6
- data/spec/fixtures/lib/persistence/my_relations/users.rb +0 -6
- data/spec/fixtures/lib/persistence/relations/users.rb +0 -6
- data/spec/fixtures/wrong/commands/create_customer.rb +0 -8
- data/spec/fixtures/wrong/mappers/customer_list.rb +0 -8
- data/spec/fixtures/wrong/relations/customers.rb +0 -8
- data/spec/integration/command_registry_spec.rb +0 -47
- data/spec/integration/commands/create_spec.rb +0 -157
- data/spec/integration/commands/delete_spec.rb +0 -67
- data/spec/integration/commands/error_handling_spec.rb +0 -25
- data/spec/integration/commands/graph_builder_spec.rb +0 -213
- data/spec/integration/commands/graph_spec.rb +0 -294
- data/spec/integration/commands/update_spec.rb +0 -86
- data/spec/integration/commands_spec.rb +0 -67
- data/spec/integration/gateways/extending_relations_spec.rb +0 -58
- data/spec/integration/gateways/setting_logger_spec.rb +0 -34
- data/spec/integration/mappers/combine_spec.rb +0 -117
- data/spec/integration/mappers/deep_embedded_spec.rb +0 -44
- data/spec/integration/mappers/definition_dsl_spec.rb +0 -206
- data/spec/integration/mappers/embedded_spec.rb +0 -62
- data/spec/integration/mappers/exclude_spec.rb +0 -27
- data/spec/integration/mappers/fold_spec.rb +0 -71
- data/spec/integration/mappers/group_spec.rb +0 -163
- data/spec/integration/mappers/overwrite_attributes_value_spec.rb +0 -51
- data/spec/integration/mappers/prefix_separator_spec.rb +0 -52
- data/spec/integration/mappers/prefix_spec.rb +0 -48
- data/spec/integration/mappers/prefixing_attributes_spec.rb +0 -37
- data/spec/integration/mappers/registering_custom_mappers_spec.rb +0 -28
- data/spec/integration/mappers/renaming_attributes_spec.rb +0 -125
- data/spec/integration/mappers/reusing_mappers_spec.rb +0 -43
- data/spec/integration/mappers/step_spec.rb +0 -119
- data/spec/integration/mappers/symbolizing_attributes_spec.rb +0 -77
- data/spec/integration/mappers/unfold_spec.rb +0 -92
- data/spec/integration/mappers/ungroup_spec.rb +0 -126
- data/spec/integration/mappers/unwrap_spec.rb +0 -93
- data/spec/integration/mappers/wrap_spec.rb +0 -155
- data/spec/integration/memory/commands/create_spec.rb +0 -23
- data/spec/integration/memory/commands/delete_spec.rb +0 -23
- data/spec/integration/memory/commands/update_spec.rb +0 -23
- data/spec/integration/multi_env_spec.rb +0 -69
- data/spec/integration/multi_repo_spec.rb +0 -46
- data/spec/integration/relations/default_dataset_spec.rb +0 -38
- data/spec/integration/relations/inheritance_spec.rb +0 -37
- data/spec/integration/relations/reading_spec.rb +0 -169
- data/spec/integration/relations/registry_dsl_spec.rb +0 -45
- data/spec/integration/setup_spec.rb +0 -193
- data/spec/shared/command_behavior.rb +0 -28
- data/spec/shared/command_graph.rb +0 -54
- data/spec/shared/container.rb +0 -9
- data/spec/shared/enumerable_dataset.rb +0 -52
- data/spec/shared/gateway_only.rb +0 -6
- data/spec/shared/materializable.rb +0 -36
- data/spec/shared/no_container.rb +0 -16
- data/spec/shared/one_behavior.rb +0 -26
- data/spec/shared/proxy.rb +0 -0
- data/spec/shared/users_and_tasks.rb +0 -10
- data/spec/spec_helper.rb +0 -59
- data/spec/support/constant_leak_finder.rb +0 -14
- data/spec/support/mutant.rb +0 -10
- data/spec/support/schema.rb +0 -14
- data/spec/support/types.rb +0 -5
- data/spec/test/memory_repository_lint_test.rb +0 -27
- data/spec/unit/rom/array_dataset_spec.rb +0 -59
- data/spec/unit/rom/association_set_spec.rb +0 -48
- data/spec/unit/rom/auto_curry_spec.rb +0 -71
- data/spec/unit/rom/commands/graph_spec.rb +0 -192
- data/spec/unit/rom/commands/lazy_spec.rb +0 -310
- data/spec/unit/rom/commands/pre_and_post_processors_spec.rb +0 -343
- data/spec/unit/rom/commands/result_spec.rb +0 -70
- data/spec/unit/rom/commands_spec.rb +0 -188
- data/spec/unit/rom/configurable_spec.rb +0 -49
- data/spec/unit/rom/configuration_spec.rb +0 -61
- data/spec/unit/rom/container_spec.rb +0 -109
- data/spec/unit/rom/create_container_spec.rb +0 -151
- data/spec/unit/rom/enumerable_dataset_spec.rb +0 -15
- data/spec/unit/rom/environment_spec.rb +0 -123
- data/spec/unit/rom/gateway_spec.rb +0 -146
- data/spec/unit/rom/mapper_registry_spec.rb +0 -25
- data/spec/unit/rom/memory/commands_spec.rb +0 -43
- data/spec/unit/rom/memory/dataset_spec.rb +0 -31
- data/spec/unit/rom/memory/gateway_spec.rb +0 -12
- data/spec/unit/rom/memory/inheritance_spec.rb +0 -32
- data/spec/unit/rom/memory/relation_spec.rb +0 -121
- data/spec/unit/rom/memory/storage_spec.rb +0 -45
- data/spec/unit/rom/plugin_spec.rb +0 -150
- data/spec/unit/rom/plugins/command/schema_spec.rb +0 -66
- data/spec/unit/rom/plugins/relation/instrumentation_spec.rb +0 -44
- data/spec/unit/rom/plugins/relation/key_inference_spec.rb +0 -85
- data/spec/unit/rom/registry_spec.rb +0 -86
- data/spec/unit/rom/relation/attribute_reader_spec.rb +0 -17
- data/spec/unit/rom/relation/call_spec.rb +0 -51
- data/spec/unit/rom/relation/composite_spec.rb +0 -106
- data/spec/unit/rom/relation/curried_spec.rb +0 -67
- data/spec/unit/rom/relation/graph_spec.rb +0 -106
- data/spec/unit/rom/relation/lazy/combine_spec.rb +0 -165
- data/spec/unit/rom/relation/lazy/graph_spec.rb +0 -165
- data/spec/unit/rom/relation/lazy_spec.rb +0 -214
- data/spec/unit/rom/relation/loaded_spec.rb +0 -53
- data/spec/unit/rom/relation/name_spec.rb +0 -58
- data/spec/unit/rom/relation/output_schema_spec.rb +0 -28
- data/spec/unit/rom/relation/schema_spec.rb +0 -259
- data/spec/unit/rom/relation/view_spec.rb +0 -158
- data/spec/unit/rom/relation_spec.rb +0 -252
- data/spec/unit/rom/schema/accessing_attributes_spec.rb +0 -52
- data/spec/unit/rom/schema/append_spec.rb +0 -17
- data/spec/unit/rom/schema/exclude_spec.rb +0 -15
- data/spec/unit/rom/schema/finalize_spec.rb +0 -59
- data/spec/unit/rom/schema/key_predicate_spec.rb +0 -15
- data/spec/unit/rom/schema/merge_spec.rb +0 -17
- data/spec/unit/rom/schema/prefix_spec.rb +0 -16
- data/spec/unit/rom/schema/project_spec.rb +0 -15
- data/spec/unit/rom/schema/rename_spec.rb +0 -22
- data/spec/unit/rom/schema/type_spec.rb +0 -49
- data/spec/unit/rom/schema/uniq_spec.rb +0 -21
- data/spec/unit/rom/schema/wrap_spec.rb +0 -18
- data/spec/unit/rom/schema_spec.rb +0 -10
- data/spec/unit/rom/setup/auto_registration_spec.rb +0 -214
@@ -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.curry(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
|
data/lib/rom/commands/graph.rb
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'rom/initializer'
|
2
|
-
require 'rom/pipeline'
|
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
|
-
extend Initializer
|
12
|
-
include Dry::Equalizer(:root, :nodes)
|
13
|
-
|
14
|
-
extend ClassInterface
|
15
|
-
|
16
|
-
include Pipeline
|
17
|
-
include Pipeline::Proxy
|
18
|
-
|
19
|
-
# @attr_reader [Command] root The root command
|
20
|
-
param :root
|
21
|
-
|
22
|
-
# @attr_reader [Array<Command>] nodes The child commands
|
23
|
-
param :nodes
|
24
|
-
|
25
|
-
alias_method :left, :root
|
26
|
-
alias_method :right, :nodes
|
27
|
-
|
28
|
-
# @attr_reader [Symbol] root's relation name
|
29
|
-
option :name, default: -> { root.name }
|
30
|
-
|
31
|
-
option :mappers, default: -> { MapperRegistry.new }
|
32
|
-
|
33
|
-
# Calls root and all nodes with the result from root
|
34
|
-
#
|
35
|
-
# Graph results are mappable through `combine` operation in mapper DSL
|
36
|
-
#
|
37
|
-
# @example
|
38
|
-
# create_user = rom.command(:users).create
|
39
|
-
# create_task = rom.command(:tasks).create
|
40
|
-
#
|
41
|
-
# command = create_user
|
42
|
-
# .with(name: 'Jane')
|
43
|
-
# .combine(create_task.with(title: 'Task'))
|
44
|
-
#
|
45
|
-
# command.call
|
46
|
-
#
|
47
|
-
# @return [Array] nested array with command results
|
48
|
-
#
|
49
|
-
# @api public
|
50
|
-
def call(*args)
|
51
|
-
left = root.call(*args)
|
52
|
-
|
53
|
-
right = nodes.map { |node|
|
54
|
-
response =
|
55
|
-
if node.lazy?
|
56
|
-
node.call(args.first, left)
|
57
|
-
else
|
58
|
-
node.call(left)
|
59
|
-
end
|
60
|
-
|
61
|
-
if node.one? && !node.graph?
|
62
|
-
[response]
|
63
|
-
else
|
64
|
-
response
|
65
|
-
end
|
66
|
-
}
|
67
|
-
|
68
|
-
if one?
|
69
|
-
[[left], right]
|
70
|
-
else
|
71
|
-
[left, right]
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# Return a new graph with updated options
|
76
|
-
#
|
77
|
-
# @api private
|
78
|
-
def with(new_options)
|
79
|
-
self.class.new(root, nodes, options.merge(new_options))
|
80
|
-
end
|
81
|
-
|
82
|
-
# @api private
|
83
|
-
def graph?
|
84
|
-
true
|
85
|
-
end
|
86
|
-
|
87
|
-
private
|
88
|
-
|
89
|
-
# @api public
|
90
|
-
def composite_class
|
91
|
-
Command::Composite
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
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
|
data/lib/rom/commands/lazy.rb
DELETED
@@ -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'
|
data/lib/rom/commands/result.rb
DELETED
@@ -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
|
data/lib/rom/commands/update.rb
DELETED
data/lib/rom/commands.rb
DELETED
data/lib/rom/configuration.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
|
-
require 'rom/environment'
|
4
|
-
require 'rom/setup'
|
5
|
-
require 'rom/configuration_dsl'
|
6
|
-
|
7
|
-
module ROM
|
8
|
-
class Configuration
|
9
|
-
extend Forwardable
|
10
|
-
include ROM::ConfigurationDSL
|
11
|
-
|
12
|
-
NoDefaultAdapterError = Class.new(StandardError)
|
13
|
-
|
14
|
-
attr_reader :environment, :setup
|
15
|
-
|
16
|
-
def_delegators :@setup, :register_relation, :register_command, :register_mapper, :register_plugin,
|
17
|
-
:relation_classes, :command_classes, :mapper_classes,
|
18
|
-
:auto_registration
|
19
|
-
|
20
|
-
def_delegators :@environment, :gateways, :gateways_map, :configure, :config
|
21
|
-
|
22
|
-
# @api public
|
23
|
-
def initialize(*args, &block)
|
24
|
-
@environment = Environment.new(*args)
|
25
|
-
@setup = Setup.new
|
26
|
-
|
27
|
-
block.call(self) unless block.nil?
|
28
|
-
end
|
29
|
-
|
30
|
-
# Apply a plugin to the configuration
|
31
|
-
#
|
32
|
-
# @param [Mixed] The plugin identifier, usually a Symbol
|
33
|
-
# @param [Hash] Plugin options
|
34
|
-
#
|
35
|
-
# @api public
|
36
|
-
def use(plugin, options = {})
|
37
|
-
if plugin.is_a?(Array)
|
38
|
-
plugin.each { |p| use(p) }
|
39
|
-
elsif plugin.is_a?(Hash)
|
40
|
-
plugin.to_a.each { |p| use(*p) }
|
41
|
-
else
|
42
|
-
ROM.plugin_registry.configuration.fetch(plugin).apply_to(self, options)
|
43
|
-
end
|
44
|
-
|
45
|
-
self
|
46
|
-
end
|
47
|
-
|
48
|
-
# Return gateway identified by name
|
49
|
-
#
|
50
|
-
# @return [Gateway]
|
51
|
-
#
|
52
|
-
# @api private
|
53
|
-
def [](name)
|
54
|
-
gateways.fetch(name)
|
55
|
-
end
|
56
|
-
|
57
|
-
# Returns gateway if method is a name of a registered gateway
|
58
|
-
#
|
59
|
-
# @return [Gateway]
|
60
|
-
#
|
61
|
-
# @api private
|
62
|
-
def method_missing(name, *)
|
63
|
-
gateways.fetch(name) { super }
|
64
|
-
end
|
65
|
-
|
66
|
-
# Hook for respond_to? used internally
|
67
|
-
#
|
68
|
-
# @api private
|
69
|
-
def respond_to?(name, include_all=false)
|
70
|
-
gateways.has_key?(name) || super
|
71
|
-
end
|
72
|
-
|
73
|
-
# @api private
|
74
|
-
def default_gateway
|
75
|
-
@default_gateway ||= gateways[:default]
|
76
|
-
end
|
77
|
-
|
78
|
-
# @api private
|
79
|
-
def adapter_for_gateway(gateway)
|
80
|
-
ROM.adapters.select do |key, value|
|
81
|
-
value.const_defined?(:Gateway) && gateway.kind_of?(value.const_get(:Gateway))
|
82
|
-
end.keys.first
|
83
|
-
end
|
84
|
-
|
85
|
-
# @api private
|
86
|
-
def default_adapter
|
87
|
-
@default_adapter ||= adapter_for_gateway(default_gateway) || ROM.adapters.keys.first
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'dry/core/inflector'
|
2
|
-
require 'dry/core/class_builder'
|
3
|
-
|
4
|
-
module ROM
|
5
|
-
module ConfigurationDSL
|
6
|
-
# Setup DSL-specific command extensions
|
7
|
-
#
|
8
|
-
# @private
|
9
|
-
class Command
|
10
|
-
# Generate a command subclass
|
11
|
-
#
|
12
|
-
# This is used by Setup#commands DSL and its `define` block
|
13
|
-
#
|
14
|
-
# @api private
|
15
|
-
def self.build_class(name, relation, options = EMPTY_HASH, &block)
|
16
|
-
type = options.fetch(:type) { name }
|
17
|
-
command_type = Dry::Core::Inflector.classify(type)
|
18
|
-
adapter = options.fetch(:adapter)
|
19
|
-
parent = ROM::Command.adapter_namespace(adapter).const_get(command_type)
|
20
|
-
class_name = generate_class_name(adapter, command_type, relation)
|
21
|
-
|
22
|
-
Dry::Core::ClassBuilder.new(name: class_name, parent: parent).call do |klass|
|
23
|
-
klass.register_as(name)
|
24
|
-
klass.relation(relation)
|
25
|
-
klass.class_eval(&block) if block
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# Create a command subclass name based on adapter, type and relation
|
30
|
-
#
|
31
|
-
# @api private
|
32
|
-
def self.generate_class_name(adapter, command_type, relation)
|
33
|
-
pieces = ['ROM']
|
34
|
-
pieces << Dry::Core::Inflector.classify(adapter)
|
35
|
-
pieces << 'Commands'
|
36
|
-
pieces << "#{command_type}[#{Dry::Core::Inflector.classify(relation)}s]"
|
37
|
-
pieces.join('::')
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
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
|