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
data/lib/rom/command_registry.rb
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
require 'dry/core/deprecations'
|
2
|
-
|
3
|
-
require 'rom/types'
|
4
|
-
require 'rom/commands/result'
|
5
|
-
|
6
|
-
module ROM
|
7
|
-
# Specialized registry class for commands
|
8
|
-
#
|
9
|
-
# @api public
|
10
|
-
class CommandRegistry
|
11
|
-
extend Initializer
|
12
|
-
extend Dry::Core::Deprecations[:rom]
|
13
|
-
|
14
|
-
include Commands
|
15
|
-
|
16
|
-
CommandNotFoundError = Class.new(KeyError)
|
17
|
-
RegistryType = Types.Definition(Registry) | Types.Constructor(Registry) { |r| Registry.new(r, self.class.name) }
|
18
|
-
|
19
|
-
# Name of the relation from which commands are under
|
20
|
-
#
|
21
|
-
# @return [String]
|
22
|
-
#
|
23
|
-
# @api private
|
24
|
-
param :relation_name
|
25
|
-
|
26
|
-
# Internal command registry
|
27
|
-
#
|
28
|
-
# @return [Registry]
|
29
|
-
#
|
30
|
-
# @api private
|
31
|
-
param :registry, type: RegistryType
|
32
|
-
|
33
|
-
option :mappers, optional: true
|
34
|
-
option :mapper, optional: true
|
35
|
-
|
36
|
-
# Try to execute a command in a block
|
37
|
-
#
|
38
|
-
# @yield [command] Passes command to the block
|
39
|
-
#
|
40
|
-
# @example
|
41
|
-
#
|
42
|
-
# rom.command(:users).try { create(name: 'Jane') }
|
43
|
-
# rom.command(:users).try { update(:by_id, 1).call(name: 'Jane Doe') }
|
44
|
-
# rom.command(:users).try { delete(:by_id, 1) }
|
45
|
-
#
|
46
|
-
# @return [Commands::Result]
|
47
|
-
#
|
48
|
-
# @api public
|
49
|
-
def try(&block)
|
50
|
-
self.class.warn "CommandRegistry#try will be removed in rom 4.0"
|
51
|
-
|
52
|
-
response = block.call
|
53
|
-
|
54
|
-
if response.is_a?(Command) || response.is_a?(Composite)
|
55
|
-
try { response.call }
|
56
|
-
else
|
57
|
-
Result::Success.new(response)
|
58
|
-
end
|
59
|
-
rescue CommandError => e
|
60
|
-
Result::Failure.new(e)
|
61
|
-
end
|
62
|
-
|
63
|
-
# Return a command from the registry
|
64
|
-
#
|
65
|
-
# If mapper is set command will be turned into a composite command with
|
66
|
-
# auto-mapping
|
67
|
-
#
|
68
|
-
# @example
|
69
|
-
# create_user = rom.command(:users)[:create]
|
70
|
-
# create_user[name: 'Jane']
|
71
|
-
#
|
72
|
-
# # with mapping, assuming :entity mapper is registered for :users relation
|
73
|
-
# create_user = rom.command(:users).as(:entity)[:create]
|
74
|
-
# create_user[name: 'Jane'] # => result is send through :entity mapper
|
75
|
-
#
|
76
|
-
# @param [Symbol] name The name of a registered command
|
77
|
-
#
|
78
|
-
# @return [Command,Command::Composite]
|
79
|
-
#
|
80
|
-
# @api public
|
81
|
-
def [](name)
|
82
|
-
command = fetch_command(name)
|
83
|
-
mapper = options[:mapper]
|
84
|
-
|
85
|
-
if mapper
|
86
|
-
command.curry >> mapper
|
87
|
-
else
|
88
|
-
command
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# Specify a mapper that should be used for commands from this registry
|
93
|
-
#
|
94
|
-
# @example
|
95
|
-
# entity_commands = rom.command(:users).as(:entity)
|
96
|
-
#
|
97
|
-
#
|
98
|
-
# @param [Symbol] mapper_name The name of a registered mapper
|
99
|
-
#
|
100
|
-
# @return [CommandRegistry]
|
101
|
-
#
|
102
|
-
# @api public
|
103
|
-
def as(mapper_name)
|
104
|
-
with(mapper: mappers[mapper_name])
|
105
|
-
end
|
106
|
-
|
107
|
-
# Return new instance of this registry with updated options
|
108
|
-
#
|
109
|
-
# @return [CommandRegistry]
|
110
|
-
#
|
111
|
-
# @api private
|
112
|
-
def with(new_options)
|
113
|
-
self.class.new(relation_name, registry, options.merge(new_options))
|
114
|
-
end
|
115
|
-
|
116
|
-
private
|
117
|
-
|
118
|
-
# Fetch a command from the registry and raise a specialized error
|
119
|
-
# in case the command is not found
|
120
|
-
#
|
121
|
-
# @api private
|
122
|
-
def fetch_command(name)
|
123
|
-
registry.fetch(name) do
|
124
|
-
raise CommandNotFoundError.new(
|
125
|
-
"There is no :#{name} command for :#{relation_name} relation"
|
126
|
-
)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
# Allow checking if a certain command is available using dot-notation
|
131
|
-
#
|
132
|
-
# @api private
|
133
|
-
def respond_to_missing?(name, include_private = false)
|
134
|
-
registry.key?(name) || super
|
135
|
-
end
|
136
|
-
|
137
|
-
# Allow retrieving commands using dot-notation
|
138
|
-
#
|
139
|
-
# @api private
|
140
|
-
def method_missing(name, *)
|
141
|
-
if registry.key?(name)
|
142
|
-
self[name]
|
143
|
-
else
|
144
|
-
super
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
@@ -1,270 +0,0 @@
|
|
1
|
-
require 'dry/core/class_builder'
|
2
|
-
require 'dry/core/inflector'
|
3
|
-
|
4
|
-
module ROM
|
5
|
-
# Base command class with factory class-level interface and setup-related logic
|
6
|
-
#
|
7
|
-
# @private
|
8
|
-
class Command
|
9
|
-
module ClassInterface
|
10
|
-
# This hook sets up default class state
|
11
|
-
#
|
12
|
-
# @api private
|
13
|
-
def inherited(klass)
|
14
|
-
super
|
15
|
-
klass.instance_variable_set(:'@before', before.dup)
|
16
|
-
klass.instance_variable_set(:'@after', after.dup)
|
17
|
-
end
|
18
|
-
|
19
|
-
# Sets up the base class
|
20
|
-
#
|
21
|
-
# @api private
|
22
|
-
def self.extended(klass)
|
23
|
-
super
|
24
|
-
klass.set_hooks(:before, [])
|
25
|
-
klass.set_hooks(:after, [])
|
26
|
-
end
|
27
|
-
|
28
|
-
# Return adapter specific sub-class based on the adapter identifier
|
29
|
-
#
|
30
|
-
# This is a syntax sugar to make things consistent
|
31
|
-
#
|
32
|
-
# @example
|
33
|
-
# ROM::Commands::Create[:memory]
|
34
|
-
# # => ROM::Memory::Commands::Create
|
35
|
-
#
|
36
|
-
# @param [Symbol] adapter identifier
|
37
|
-
#
|
38
|
-
# @return [Class]
|
39
|
-
#
|
40
|
-
# @api public
|
41
|
-
def [](adapter)
|
42
|
-
adapter_namespace(adapter).const_get(Dry::Core::Inflector.demodulize(name))
|
43
|
-
end
|
44
|
-
|
45
|
-
# Return namespaces that contains command subclasses of a specific adapter
|
46
|
-
#
|
47
|
-
# @param [Symbol] adapter identifier
|
48
|
-
#
|
49
|
-
# @return [Module]
|
50
|
-
#
|
51
|
-
# @api private
|
52
|
-
def adapter_namespace(adapter)
|
53
|
-
ROM.adapters.fetch(adapter).const_get(:Commands)
|
54
|
-
rescue KeyError
|
55
|
-
raise AdapterNotPresentError.new(adapter, :relation)
|
56
|
-
end
|
57
|
-
|
58
|
-
# Build a command class for a specific relation with options
|
59
|
-
#
|
60
|
-
# @example
|
61
|
-
# class CreateUser < ROM::Commands::Create[:memory]
|
62
|
-
# end
|
63
|
-
#
|
64
|
-
# command = CreateUser.build(rom.relations[:users])
|
65
|
-
#
|
66
|
-
# @param [Relation] relation
|
67
|
-
# @param [Hash] options
|
68
|
-
#
|
69
|
-
# @return [Command]
|
70
|
-
#
|
71
|
-
# @api public
|
72
|
-
def build(relation, options = EMPTY_HASH)
|
73
|
-
new(relation, self.options.merge(options))
|
74
|
-
end
|
75
|
-
|
76
|
-
# Create a command class with a specific type
|
77
|
-
#
|
78
|
-
# @param [Symbol] command name
|
79
|
-
# @param [Class] parent class
|
80
|
-
#
|
81
|
-
# @yield [Class] create class
|
82
|
-
#
|
83
|
-
# @return [Class, Object] return result of the block if it was provided
|
84
|
-
#
|
85
|
-
# @api public
|
86
|
-
def create_class(name, type, &block)
|
87
|
-
klass = Dry::Core::ClassBuilder
|
88
|
-
.new(name: "#{Dry::Core::Inflector.classify(type)}[:#{name}]", parent: type)
|
89
|
-
.call
|
90
|
-
|
91
|
-
if block
|
92
|
-
yield(klass)
|
93
|
-
else
|
94
|
-
klass
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# Use a configured plugin in this relation
|
99
|
-
#
|
100
|
-
# @example
|
101
|
-
# class CreateUser < ROM::Commands::Create[:memory]
|
102
|
-
# use :pagintion
|
103
|
-
#
|
104
|
-
# per_page 30
|
105
|
-
# end
|
106
|
-
#
|
107
|
-
# @param [Symbol] plugin
|
108
|
-
# @param [Hash] options
|
109
|
-
# @option options [Symbol] :adapter (:default) first adapter to check for plugin
|
110
|
-
#
|
111
|
-
# @api public
|
112
|
-
def use(plugin, _options = EMPTY_HASH)
|
113
|
-
ROM.plugin_registry.commands.fetch(plugin, adapter).apply_to(self)
|
114
|
-
end
|
115
|
-
|
116
|
-
# Extend a command class with relation view methods
|
117
|
-
#
|
118
|
-
# @param [Relation]
|
119
|
-
#
|
120
|
-
# @return [Class]
|
121
|
-
#
|
122
|
-
# @api public
|
123
|
-
def extend_for_relation(relation)
|
124
|
-
include(relation_methods_mod(relation.class))
|
125
|
-
end
|
126
|
-
|
127
|
-
# Set before-execute hooks
|
128
|
-
#
|
129
|
-
# @overload before(hook)
|
130
|
-
# Set an before hook as a method name
|
131
|
-
#
|
132
|
-
# @example
|
133
|
-
# class CreateUser < ROM::Commands::Create[:sql]
|
134
|
-
# relation :users
|
135
|
-
# register_as :create
|
136
|
-
#
|
137
|
-
# before :my_hook
|
138
|
-
#
|
139
|
-
# def my_hook(tuple, *)
|
140
|
-
# puts "hook called#
|
141
|
-
# end
|
142
|
-
# end
|
143
|
-
#
|
144
|
-
# @overload before(hook_opts)
|
145
|
-
# Set an before hook as a method name with arguments
|
146
|
-
#
|
147
|
-
# @example
|
148
|
-
# class CreateUser < ROM::Commands::Create[:sql]
|
149
|
-
# relation :users
|
150
|
-
# register_as :create
|
151
|
-
#
|
152
|
-
# before my_hook: { arg1: 1, arg1: 2 }
|
153
|
-
#
|
154
|
-
# def my_hook(tuple, arg1:, arg2:)
|
155
|
-
# puts "hook called with args: #{arg1} and #{arg2}"
|
156
|
-
# end
|
157
|
-
# end
|
158
|
-
#
|
159
|
-
# @param [Hash<Symbol=>Hash>] hook Options with method name and pre-set args
|
160
|
-
#
|
161
|
-
# @return [Array<Hash, Symbol>] A list of all configured before hooks
|
162
|
-
#
|
163
|
-
# @api public
|
164
|
-
def before(*hooks)
|
165
|
-
if hooks.size > 0
|
166
|
-
set_hooks(:before, hooks)
|
167
|
-
else
|
168
|
-
@before
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
# Set after-execute hooks
|
173
|
-
#
|
174
|
-
# @overload after(hook)
|
175
|
-
# Set an after hook as a method name
|
176
|
-
#
|
177
|
-
# @example
|
178
|
-
# class CreateUser < ROM::Commands::Create[:sql]
|
179
|
-
# relation :users
|
180
|
-
# register_as :create
|
181
|
-
#
|
182
|
-
# after :my_hook
|
183
|
-
#
|
184
|
-
# def my_hook(tuple, *)
|
185
|
-
# puts "hook called#
|
186
|
-
# end
|
187
|
-
# end
|
188
|
-
#
|
189
|
-
# @overload after(hook_opts)
|
190
|
-
# Set an after hook as a method name with arguments
|
191
|
-
#
|
192
|
-
# @example
|
193
|
-
# class CreateUser < ROM::Commands::Create[:sql]
|
194
|
-
# relation :users
|
195
|
-
# register_as :create
|
196
|
-
#
|
197
|
-
# after my_hook: { arg1: 1, arg1: 2 }
|
198
|
-
#
|
199
|
-
# def my_hook(tuple, arg1:, arg2:)
|
200
|
-
# puts "hook called with args: #{arg1} and #{arg2}"
|
201
|
-
# end
|
202
|
-
# end
|
203
|
-
#
|
204
|
-
# @param [Hash<Symbol=>Hash>] hook Options with method name and pre-set args
|
205
|
-
#
|
206
|
-
# @return [Array<Hash, Symbol>] A list of all configured after hooks
|
207
|
-
#
|
208
|
-
# @api public
|
209
|
-
def after(*hooks)
|
210
|
-
if hooks.size > 0
|
211
|
-
set_hooks(:after, hooks)
|
212
|
-
else
|
213
|
-
@after
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
# Set new or more hooks
|
218
|
-
#
|
219
|
-
# @api private
|
220
|
-
def set_hooks(type, hooks)
|
221
|
-
ivar = :"@#{type}"
|
222
|
-
|
223
|
-
if instance_variable_defined?(ivar)
|
224
|
-
instance_variable_get(ivar).concat(hooks)
|
225
|
-
else
|
226
|
-
instance_variable_set(ivar, hooks)
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
# Return default name of the command class based on its name
|
231
|
-
#
|
232
|
-
# During setup phase this is used by defalut as `register_as` option
|
233
|
-
#
|
234
|
-
# @return [Symbol]
|
235
|
-
#
|
236
|
-
# @api private
|
237
|
-
def default_name
|
238
|
-
Dry::Core::Inflector.underscore(Dry::Core::Inflector.demodulize(name)).to_sym
|
239
|
-
end
|
240
|
-
|
241
|
-
# Return default options based on class macros
|
242
|
-
#
|
243
|
-
# @return [Hash]
|
244
|
-
#
|
245
|
-
# @api private
|
246
|
-
def options
|
247
|
-
{ input: input, result: result, before: before, after: after }
|
248
|
-
end
|
249
|
-
|
250
|
-
# @api private
|
251
|
-
def relation_methods_mod(relation_class)
|
252
|
-
Module.new do
|
253
|
-
relation_class.view_methods.each do |meth|
|
254
|
-
module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
255
|
-
def #{meth}(*args)
|
256
|
-
response = relation.public_send(:#{meth}, *args)
|
257
|
-
|
258
|
-
if response.is_a?(relation.class)
|
259
|
-
new(response)
|
260
|
-
else
|
261
|
-
response
|
262
|
-
end
|
263
|
-
end
|
264
|
-
RUBY
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'rom/pipeline'
|
2
|
-
|
3
|
-
module ROM
|
4
|
-
module Commands
|
5
|
-
# Composite command that consists of left and right commands
|
6
|
-
#
|
7
|
-
# @api public
|
8
|
-
class Composite < Pipeline::Composite
|
9
|
-
# Calls the composite command
|
10
|
-
#
|
11
|
-
# Right command is called with a result from the left one
|
12
|
-
#
|
13
|
-
# @return [Object]
|
14
|
-
#
|
15
|
-
# @api public
|
16
|
-
def call(*args)
|
17
|
-
response = left.call(*args)
|
18
|
-
|
19
|
-
if response.nil? || (many? && response.size == 0)
|
20
|
-
return one? ? nil : EMPTY_ARRAY
|
21
|
-
end
|
22
|
-
|
23
|
-
if one? && !graph?
|
24
|
-
if right.is_a?(Command) || right.is_a?(Commands::Composite)
|
25
|
-
right.call([response].first)
|
26
|
-
else
|
27
|
-
right.call([response]).first
|
28
|
-
end
|
29
|
-
elsif one? && graph?
|
30
|
-
right.call(response).first
|
31
|
-
else
|
32
|
-
right.call(response)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
alias_method :[], :call
|
36
|
-
|
37
|
-
# @api private
|
38
|
-
def graph?
|
39
|
-
left.is_a?(Graph)
|
40
|
-
end
|
41
|
-
|
42
|
-
# @api private
|
43
|
-
def result
|
44
|
-
left.result
|
45
|
-
end
|
46
|
-
|
47
|
-
# @api private
|
48
|
-
def decorate?(response)
|
49
|
-
super || response.is_a?(Graph)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
data/lib/rom/commands/create.rb
DELETED
data/lib/rom/commands/delete.rb
DELETED
@@ -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
|