rom 3.3.3 → 4.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- 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/Rakefile
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require "rspec/core/rake_task"
|
3
|
-
require "rake/testtask"
|
4
|
-
|
5
|
-
RSpec::Core::RakeTask.new(:spec)
|
6
|
-
task default: [:ci]
|
7
|
-
|
8
|
-
desc 'Run specs in isolation'
|
9
|
-
task :"spec:isolation" do
|
10
|
-
FileList["spec/**/*_spec.rb"].each do |spec|
|
11
|
-
sh "COVERAGE=false bundle exec rspec #{spec}"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
if RUBY_ENGINE != 'ruby'
|
16
|
-
desc "Run CI tasks"
|
17
|
-
task ci: [:spec, :lint]
|
18
|
-
else
|
19
|
-
desc "Run CI tasks"
|
20
|
-
task ci: [:spec, :lint, :"spec:isolation"]
|
21
|
-
end
|
22
|
-
|
23
|
-
Rake::TestTask.new(:lint) do |test|
|
24
|
-
test.description = "Run adapter lint tests against memory adapter"
|
25
|
-
test.test_files = FileList.new('spec/test/*_test.rb')
|
26
|
-
test.libs << 'test'
|
27
|
-
test.verbose = true
|
28
|
-
end
|
data/lib/rom/array_dataset.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'rom/initializer'
|
2
|
-
require 'rom/enumerable_dataset'
|
3
|
-
|
4
|
-
module ROM
|
5
|
-
# A helper module that adds data-proxy behavior to an array-like object
|
6
|
-
#
|
7
|
-
# @see EnumerableDataset
|
8
|
-
#
|
9
|
-
# @api public
|
10
|
-
module ArrayDataset
|
11
|
-
extend DataProxy::ClassMethods
|
12
|
-
include EnumerableDataset
|
13
|
-
|
14
|
-
# Extends the class with data-proxy behavior
|
15
|
-
#
|
16
|
-
# @api private
|
17
|
-
def self.included(klass)
|
18
|
-
klass.class_eval do
|
19
|
-
extend Initializer
|
20
|
-
include DataProxy
|
21
|
-
|
22
|
-
param :data
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
forward(
|
27
|
-
:*, :+, :-, :compact, :compact!, :flatten, :flatten!, :length, :pop,
|
28
|
-
:reverse, :reverse!, :sample, :size, :shift, :shuffle, :shuffle!,
|
29
|
-
:slice, :slice!, :sort!, :uniq, :uniq!, :unshift, :values_at
|
30
|
-
)
|
31
|
-
|
32
|
-
[
|
33
|
-
:map!, :combination, :cycle, :delete_if, :keep_if, :permutation, :reject!,
|
34
|
-
:select!, :sort_by!
|
35
|
-
].each do |method|
|
36
|
-
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
37
|
-
def #{method}(*args, &block)
|
38
|
-
return to_enum unless block
|
39
|
-
self.class.new(data.send(:#{method}, *args, &block), options)
|
40
|
-
end
|
41
|
-
RUBY
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/lib/rom/association_set.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'dry/core/deprecations'
|
2
|
-
require 'dry/core/inflector'
|
3
|
-
|
4
|
-
require 'rom/registry'
|
5
|
-
|
6
|
-
module ROM
|
7
|
-
class AssociationSet < ROM::Registry
|
8
|
-
# @api private
|
9
|
-
def try(name, &block)
|
10
|
-
key = name.to_sym
|
11
|
-
|
12
|
-
if key?(key) || key?(singularize(key))
|
13
|
-
yield(self[key])
|
14
|
-
else
|
15
|
-
msg = <<-STR
|
16
|
-
Key inference will be removed in rom 4.0. You need to define :#{key} association.
|
17
|
-
=> Called at:
|
18
|
-
#{caller.join("\n")}
|
19
|
-
STR
|
20
|
-
|
21
|
-
Dry::Core::Deprecations.warn(msg)
|
22
|
-
|
23
|
-
false
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# @api private
|
28
|
-
def [](name)
|
29
|
-
key = name.to_sym
|
30
|
-
|
31
|
-
if key?(key)
|
32
|
-
super
|
33
|
-
else
|
34
|
-
sk = singularize(key)
|
35
|
-
|
36
|
-
if key?(sk)
|
37
|
-
super(sk)
|
38
|
-
else
|
39
|
-
super
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# @api private
|
45
|
-
def singularize(key)
|
46
|
-
Dry::Core::Inflector.singularize(key).to_sym
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/lib/rom/auto_curry.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
module ROM
|
2
|
-
module AutoCurry
|
3
|
-
def self.extended(klass)
|
4
|
-
klass.define_singleton_method(:method_added) do |name|
|
5
|
-
return if auto_curry_busy?
|
6
|
-
auto_curry_guard { auto_curry(name) }
|
7
|
-
super(name)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def auto_curry_guard
|
12
|
-
@__auto_curry_busy__ = true
|
13
|
-
yield
|
14
|
-
ensure
|
15
|
-
@__auto_curry_busy__ = false
|
16
|
-
end
|
17
|
-
|
18
|
-
def auto_curry_busy?
|
19
|
-
@__auto_curry_busy__ ||= false
|
20
|
-
end
|
21
|
-
|
22
|
-
def auto_curried_methods
|
23
|
-
@__auto_curried_methods__ ||= []
|
24
|
-
end
|
25
|
-
|
26
|
-
def auto_curry(name, &block)
|
27
|
-
arity = instance_method(name).arity
|
28
|
-
|
29
|
-
return unless public_instance_methods.include?(name) && arity != 0
|
30
|
-
|
31
|
-
mod = Module.new
|
32
|
-
|
33
|
-
mod.module_eval do
|
34
|
-
define_method(name) do |*args, &mblock|
|
35
|
-
response =
|
36
|
-
if arity < 0 || arity == args.size
|
37
|
-
super(*args, &mblock)
|
38
|
-
else
|
39
|
-
self.class.curried.new(self, name: name, curry_args: args, arity: arity)
|
40
|
-
end
|
41
|
-
|
42
|
-
if block
|
43
|
-
response.instance_exec(&block)
|
44
|
-
else
|
45
|
-
response
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
auto_curried_methods << name
|
51
|
-
|
52
|
-
prepend(mod)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
data/lib/rom/command.rb
DELETED
@@ -1,494 +0,0 @@
|
|
1
|
-
require 'dry/core/deprecations'
|
2
|
-
require 'dry/core/class_attributes'
|
3
|
-
|
4
|
-
require 'rom/types'
|
5
|
-
require 'rom/initializer'
|
6
|
-
require 'rom/pipeline'
|
7
|
-
|
8
|
-
require 'rom/commands/class_interface'
|
9
|
-
require 'rom/commands/composite'
|
10
|
-
require 'rom/commands/graph'
|
11
|
-
require 'rom/commands/lazy'
|
12
|
-
|
13
|
-
module ROM
|
14
|
-
# Abstract command class
|
15
|
-
#
|
16
|
-
# Provides a constructor accepting relation with options and basic behavior
|
17
|
-
# for calling, currying and composing commands.
|
18
|
-
#
|
19
|
-
# Typically command subclasses should inherit from specialized
|
20
|
-
# Create/Update/Delete, not this one.
|
21
|
-
#
|
22
|
-
# @abstract
|
23
|
-
#
|
24
|
-
# @api public
|
25
|
-
class Command
|
26
|
-
extend Initializer
|
27
|
-
include Dry::Equalizer(:relation, :options)
|
28
|
-
include Commands
|
29
|
-
include Pipeline::Operator
|
30
|
-
|
31
|
-
extend Dry::Core::ClassAttributes
|
32
|
-
extend Dry::Core::Deprecations[:rom]
|
33
|
-
extend ClassInterface
|
34
|
-
|
35
|
-
# @!method self.adapter
|
36
|
-
# Get or set adapter identifier
|
37
|
-
#
|
38
|
-
# @overload adapter
|
39
|
-
# Get adapter identifier
|
40
|
-
#
|
41
|
-
# @example
|
42
|
-
# ROM::Memory::Commands::Create.adapter
|
43
|
-
# # => :memory
|
44
|
-
#
|
45
|
-
# @return [Symbol]
|
46
|
-
#
|
47
|
-
# @overload adapter(identifier)
|
48
|
-
# Set adapter identifier. This must always match actual adapter identifier
|
49
|
-
# that was used to register an adapter.
|
50
|
-
#
|
51
|
-
# @example
|
52
|
-
# module MyAdapter
|
53
|
-
# class CreateCommand < ROM::Commands::Memory::Create
|
54
|
-
# adapter :my_adapter
|
55
|
-
# end
|
56
|
-
# end
|
57
|
-
#
|
58
|
-
# @api public
|
59
|
-
defines :adapter
|
60
|
-
|
61
|
-
# @!method self.relation
|
62
|
-
# Get or set relation identifier
|
63
|
-
#
|
64
|
-
# @overload relation
|
65
|
-
# Get relation identifier
|
66
|
-
#
|
67
|
-
# @example
|
68
|
-
# class CreateUser < ROM::Commands::Create[:memory]
|
69
|
-
# relation :users
|
70
|
-
# end
|
71
|
-
#
|
72
|
-
# CreateUser.relation
|
73
|
-
# # => :users
|
74
|
-
#
|
75
|
-
# @return [Symbol]
|
76
|
-
#
|
77
|
-
# @overload relation(identifier)
|
78
|
-
# Set relation identifier.
|
79
|
-
#
|
80
|
-
# @example
|
81
|
-
# class CreateUser < ROM::Commands::Create[:memory]
|
82
|
-
# relation :users
|
83
|
-
# end
|
84
|
-
#
|
85
|
-
# @api public
|
86
|
-
defines :relation
|
87
|
-
|
88
|
-
# @!method self.relation
|
89
|
-
# Get or set result type
|
90
|
-
#
|
91
|
-
# @overload result
|
92
|
-
# Get result type
|
93
|
-
#
|
94
|
-
# @example
|
95
|
-
# class CreateUser < ROM::Commands::Create[:memory]
|
96
|
-
# result :one
|
97
|
-
# end
|
98
|
-
#
|
99
|
-
# CreateUser.result
|
100
|
-
# # => :one
|
101
|
-
#
|
102
|
-
# @return [Symbol]
|
103
|
-
#
|
104
|
-
# @overload relation(identifier)
|
105
|
-
# Set result type
|
106
|
-
#
|
107
|
-
# @example
|
108
|
-
# class CreateUser < ROM::Commands::Create[:memory]
|
109
|
-
# result :one
|
110
|
-
# end
|
111
|
-
#
|
112
|
-
# @api public
|
113
|
-
defines :result
|
114
|
-
|
115
|
-
# @!method self.relation
|
116
|
-
# Get or set input processing function. This is typically set during setup
|
117
|
-
# to relation's input_schema
|
118
|
-
#
|
119
|
-
# @overload input
|
120
|
-
# Get input processing function
|
121
|
-
#
|
122
|
-
# @example
|
123
|
-
# class CreateUser < ROM::Commands::Create[:memory]
|
124
|
-
# input -> tuple { .. }
|
125
|
-
# end
|
126
|
-
#
|
127
|
-
# CreateUser.input
|
128
|
-
# # Your custom function
|
129
|
-
#
|
130
|
-
# @return [Proc,#call]
|
131
|
-
#
|
132
|
-
# @overload input(identifier)
|
133
|
-
# Set input processing function
|
134
|
-
#
|
135
|
-
# @example
|
136
|
-
# class CreateUser < ROM::Commands::Create[:memory]
|
137
|
-
# input -> tuple { .. }
|
138
|
-
# end
|
139
|
-
#
|
140
|
-
# @api public
|
141
|
-
defines :input
|
142
|
-
|
143
|
-
# @!method self.register_as
|
144
|
-
# Get or set identifier that should be used to register a command in a container
|
145
|
-
#
|
146
|
-
# @overload register_as
|
147
|
-
# Get registration identifier
|
148
|
-
#
|
149
|
-
# @example
|
150
|
-
# class CreateUser < ROM::Commands::Create[:memory]
|
151
|
-
# register_as :create_user
|
152
|
-
# end
|
153
|
-
#
|
154
|
-
# CreateUser.register_as
|
155
|
-
# # => :create_user
|
156
|
-
#
|
157
|
-
# @return [Symbol]
|
158
|
-
#
|
159
|
-
# @overload register_as(identifier)
|
160
|
-
# Set registration identifier
|
161
|
-
#
|
162
|
-
# @example
|
163
|
-
# class CreateUser < ROM::Commands::Create[:memory]
|
164
|
-
# register_as :create_user
|
165
|
-
# end
|
166
|
-
#
|
167
|
-
# @api public
|
168
|
-
defines :register_as
|
169
|
-
|
170
|
-
# @!method self.restrictable
|
171
|
-
# @overload restrictable
|
172
|
-
# Check if a command class is restrictable
|
173
|
-
#
|
174
|
-
# @example
|
175
|
-
# class UpdateUser < ROM::Commands::Update[:memory]
|
176
|
-
# restrictable true
|
177
|
-
# end
|
178
|
-
#
|
179
|
-
# CreateUser.restrictable
|
180
|
-
# # => true
|
181
|
-
#
|
182
|
-
# @return [FalseClass, TrueClass]
|
183
|
-
#
|
184
|
-
# @overload restrictable(value)
|
185
|
-
# Set if a command is restrictable
|
186
|
-
#
|
187
|
-
# @example
|
188
|
-
# class UpdateUser < ROM::Commands::Update[:memory]
|
189
|
-
# restrictable true
|
190
|
-
# end
|
191
|
-
#
|
192
|
-
# @api public
|
193
|
-
defines :restrictable
|
194
|
-
|
195
|
-
# @!attribute [r] relation
|
196
|
-
# @return [Relation] Command's relation
|
197
|
-
param :relation
|
198
|
-
|
199
|
-
CommandType = Types::Strict::Symbol.enum(:create, :update, :delete)
|
200
|
-
Result = Types::Strict::Symbol.enum(:one, :many)
|
201
|
-
|
202
|
-
# @!attribute [r] type
|
203
|
-
# @return [Symbol] The command type, one of :create, :update or :delete
|
204
|
-
option :type, type: CommandType, optional: true
|
205
|
-
|
206
|
-
# @!attribute [r] source
|
207
|
-
# @return [Relation] The source relation
|
208
|
-
option :source, default: -> { relation }
|
209
|
-
|
210
|
-
# @!attribute [r] result
|
211
|
-
# @return [Symbol] Result type, either :one or :many
|
212
|
-
option :result, type: Result
|
213
|
-
|
214
|
-
# @!attribute [r] input
|
215
|
-
# @return [Proc, #call] Tuple processing function, typically uses Relation#input_schema
|
216
|
-
option :input
|
217
|
-
|
218
|
-
# @!attribute [r] curry_args
|
219
|
-
# @return [Array] Curried args
|
220
|
-
option :curry_args, default: -> { EMPTY_ARRAY }
|
221
|
-
|
222
|
-
# @!attribute [r] before
|
223
|
-
# @return [Array<Hash>] An array with before hooks configuration
|
224
|
-
option :before, Types::Coercible::Array, reader: false, default: -> { self.class.before }
|
225
|
-
|
226
|
-
# @!attribute [r] after
|
227
|
-
# @return [Array<Hash>] An array with after hooks configuration
|
228
|
-
option :after, Types::Coercible::Array, reader: false, default: -> { self.class.after }
|
229
|
-
|
230
|
-
input Hash
|
231
|
-
result :many
|
232
|
-
|
233
|
-
# Return name of this command's relation
|
234
|
-
#
|
235
|
-
# @return [ROM::Relation::Name]
|
236
|
-
#
|
237
|
-
# @api public
|
238
|
-
def name
|
239
|
-
relation.name
|
240
|
-
end
|
241
|
-
|
242
|
-
# Return gateway of this command's relation
|
243
|
-
#
|
244
|
-
# @return [Symbol]
|
245
|
-
#
|
246
|
-
# @api public
|
247
|
-
def gateway
|
248
|
-
relation.gateway
|
249
|
-
end
|
250
|
-
|
251
|
-
# Execute the command
|
252
|
-
#
|
253
|
-
# @abstract
|
254
|
-
#
|
255
|
-
# @return [Array] an array with inserted tuples
|
256
|
-
#
|
257
|
-
# @api private
|
258
|
-
def execute(*)
|
259
|
-
raise(
|
260
|
-
NotImplementedError,
|
261
|
-
"#{self.class}##{__method__} must be implemented"
|
262
|
-
)
|
263
|
-
end
|
264
|
-
|
265
|
-
# Call the command and return one or many tuples
|
266
|
-
#
|
267
|
-
# This method will apply before/after hooks automatically
|
268
|
-
#
|
269
|
-
# @api public
|
270
|
-
def call(*args, &block)
|
271
|
-
tuples =
|
272
|
-
if hooks?
|
273
|
-
prepared =
|
274
|
-
if curried?
|
275
|
-
apply_hooks(before_hooks, *(curry_args + args))
|
276
|
-
else
|
277
|
-
apply_hooks(before_hooks, *args)
|
278
|
-
end
|
279
|
-
|
280
|
-
result = prepared ? execute(prepared, &block) : execute(&block)
|
281
|
-
|
282
|
-
if curried?
|
283
|
-
if args.size > 0
|
284
|
-
apply_hooks(after_hooks, result, *args)
|
285
|
-
elsif curry_args.size > 1
|
286
|
-
apply_hooks(after_hooks, result, curry_args[1])
|
287
|
-
else
|
288
|
-
apply_hooks(after_hooks, result)
|
289
|
-
end
|
290
|
-
else
|
291
|
-
apply_hooks(after_hooks, result, *args[1..args.size-1])
|
292
|
-
end
|
293
|
-
else
|
294
|
-
execute(*(curry_args + args), &block)
|
295
|
-
end
|
296
|
-
|
297
|
-
if one?
|
298
|
-
tuples.first
|
299
|
-
else
|
300
|
-
tuples
|
301
|
-
end
|
302
|
-
end
|
303
|
-
alias_method :[], :call
|
304
|
-
|
305
|
-
# Curry this command with provided args
|
306
|
-
#
|
307
|
-
# Curried command can be called without args. If argument is a graph input processor,
|
308
|
-
# lazy command will be returned, which is used for handling nested input hashes.
|
309
|
-
#
|
310
|
-
# @return [Command, Lazy]
|
311
|
-
#
|
312
|
-
# @api public
|
313
|
-
def curry(*args)
|
314
|
-
if curry_args.empty? && args.first.is_a?(Graph::InputEvaluator)
|
315
|
-
Lazy[self].new(self, *args)
|
316
|
-
else
|
317
|
-
self.class.build(relation, **options, curry_args: args)
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
# @api public
|
322
|
-
def with(*args)
|
323
|
-
self.class.warn "Command#with will change its behavior in rom 4.0. Use Command#curry instead.\n\n#{caller[0..5].join("\n")}"
|
324
|
-
curry(*args)
|
325
|
-
end
|
326
|
-
|
327
|
-
# Compose this command with other commands
|
328
|
-
#
|
329
|
-
# Composed commands can handle nested input
|
330
|
-
#
|
331
|
-
# @return [Command::Graph]
|
332
|
-
#
|
333
|
-
# @api public
|
334
|
-
def combine(*others)
|
335
|
-
Graph.new(self, others)
|
336
|
-
end
|
337
|
-
|
338
|
-
# Check if this command is curried
|
339
|
-
#
|
340
|
-
# @return [TrueClass, FalseClass]
|
341
|
-
#
|
342
|
-
# @api public
|
343
|
-
def curried?
|
344
|
-
curry_args.size > 0
|
345
|
-
end
|
346
|
-
|
347
|
-
# Return a new command with new options
|
348
|
-
#
|
349
|
-
# @param [Hash] new_opts A hash with new options
|
350
|
-
#
|
351
|
-
# @return [Command]
|
352
|
-
#
|
353
|
-
# @api public
|
354
|
-
def with_opts(new_opts)
|
355
|
-
self.class.new(relation, options.merge(new_opts))
|
356
|
-
end
|
357
|
-
|
358
|
-
# Return a new command with appended before hooks
|
359
|
-
#
|
360
|
-
# @param [Array<Hash>] hooks A list of before hooks configurations
|
361
|
-
#
|
362
|
-
# @return [Command]
|
363
|
-
#
|
364
|
-
# @api public
|
365
|
-
def before(*hooks)
|
366
|
-
self.class.new(relation, **options, before: before_hooks + hooks)
|
367
|
-
end
|
368
|
-
|
369
|
-
# Return a new command with appended after hooks
|
370
|
-
#
|
371
|
-
# @param [Array<Hash>] hooks A list of after hooks configurations
|
372
|
-
#
|
373
|
-
# @return [Command]
|
374
|
-
#
|
375
|
-
# @api public
|
376
|
-
def after(*hooks)
|
377
|
-
self.class.new(relation, **options, after: after_hooks + hooks)
|
378
|
-
end
|
379
|
-
|
380
|
-
# List of before hooks
|
381
|
-
#
|
382
|
-
# @return [Array]
|
383
|
-
#
|
384
|
-
# @api public
|
385
|
-
def before_hooks
|
386
|
-
options[:before]
|
387
|
-
end
|
388
|
-
|
389
|
-
# List of after hooks
|
390
|
-
#
|
391
|
-
# @return [Array]
|
392
|
-
#
|
393
|
-
# @api public
|
394
|
-
def after_hooks
|
395
|
-
options[:after]
|
396
|
-
end
|
397
|
-
|
398
|
-
# Return a new command with other source relation
|
399
|
-
#
|
400
|
-
# This can be used to restrict command with a specific relation
|
401
|
-
#
|
402
|
-
# @return [Command]
|
403
|
-
#
|
404
|
-
# @api public
|
405
|
-
def new(new_relation)
|
406
|
-
self.class.build(new_relation, **options, source: relation)
|
407
|
-
end
|
408
|
-
|
409
|
-
# Check if this command has any hooks
|
410
|
-
#
|
411
|
-
# @api private
|
412
|
-
def hooks?
|
413
|
-
before_hooks.size > 0 || after_hooks.size > 0
|
414
|
-
end
|
415
|
-
|
416
|
-
# Check if this command is lazy
|
417
|
-
#
|
418
|
-
# @return [false]
|
419
|
-
#
|
420
|
-
# @api private
|
421
|
-
def lazy?
|
422
|
-
false
|
423
|
-
end
|
424
|
-
|
425
|
-
# Check if this command is a graph
|
426
|
-
#
|
427
|
-
# @return [false]
|
428
|
-
#
|
429
|
-
# @api private
|
430
|
-
def graph?
|
431
|
-
false
|
432
|
-
end
|
433
|
-
|
434
|
-
# Check if this command returns a single tuple
|
435
|
-
#
|
436
|
-
# @return [TrueClass,FalseClass]
|
437
|
-
#
|
438
|
-
# @api private
|
439
|
-
def one?
|
440
|
-
result.equal?(:one)
|
441
|
-
end
|
442
|
-
|
443
|
-
# Check if this command returns many tuples
|
444
|
-
#
|
445
|
-
# @return [TrueClass,FalseClass]
|
446
|
-
#
|
447
|
-
# @api private
|
448
|
-
def many?
|
449
|
-
result.equal?(:many)
|
450
|
-
end
|
451
|
-
|
452
|
-
private
|
453
|
-
|
454
|
-
# Hook called by Pipeline to get composite class for commands
|
455
|
-
#
|
456
|
-
# @return [Class]
|
457
|
-
#
|
458
|
-
# @api private
|
459
|
-
def composite_class
|
460
|
-
Command::Composite
|
461
|
-
end
|
462
|
-
|
463
|
-
# Apply provided hooks
|
464
|
-
#
|
465
|
-
# Used by #call
|
466
|
-
#
|
467
|
-
# @return [Array<Hash>]
|
468
|
-
#
|
469
|
-
# @api private
|
470
|
-
def apply_hooks(hooks, tuples, *args)
|
471
|
-
hooks.reduce(tuples) do |a, e|
|
472
|
-
if e.is_a?(Hash)
|
473
|
-
hook_meth, hook_args = e.to_a.flatten(1)
|
474
|
-
__send__(hook_meth, a, *args, **hook_args)
|
475
|
-
else
|
476
|
-
__send__(e, a, *args)
|
477
|
-
end
|
478
|
-
end
|
479
|
-
end
|
480
|
-
|
481
|
-
# Pipes a dataset through command's relation
|
482
|
-
#
|
483
|
-
# @return [Array]
|
484
|
-
#
|
485
|
-
# @api private
|
486
|
-
def wrap_dataset(dataset)
|
487
|
-
if relation.is_a?(Relation::Composite)
|
488
|
-
relation.new(dataset).to_a
|
489
|
-
else
|
490
|
-
dataset
|
491
|
-
end
|
492
|
-
end
|
493
|
-
end
|
494
|
-
end
|