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/lint/linter.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
module ROM
|
2
|
-
module Lint
|
3
|
-
# Base class for building linters that check source code
|
4
|
-
#
|
5
|
-
# Linters are used by authors of ROM adapters to verify that their
|
6
|
-
# integration complies with the ROM api.
|
7
|
-
#
|
8
|
-
# Most of the time, authors won't need to construct linters directly
|
9
|
-
# because the provided test helpers will automatically run when required
|
10
|
-
# in tests and specs.
|
11
|
-
#
|
12
|
-
# @example
|
13
|
-
# require 'rom/lint/spec'
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# @api public
|
17
|
-
class Linter
|
18
|
-
# A failure raised by +complain+
|
19
|
-
Failure = Class.new(StandardError)
|
20
|
-
|
21
|
-
# Iterate over all lint methods
|
22
|
-
#
|
23
|
-
# @yield [String, ROM::Lint]
|
24
|
-
#
|
25
|
-
# @api public
|
26
|
-
def self.each_lint
|
27
|
-
return to_enum unless block_given?
|
28
|
-
lints.each { |lint| yield lint, self }
|
29
|
-
end
|
30
|
-
|
31
|
-
# Run a lint method
|
32
|
-
#
|
33
|
-
# @param [String] name
|
34
|
-
#
|
35
|
-
# @raise [ROM::Lint::Linter::Failure] if linting fails
|
36
|
-
#
|
37
|
-
# @api public
|
38
|
-
def lint(name)
|
39
|
-
before_lint
|
40
|
-
public_send name
|
41
|
-
after_lint
|
42
|
-
true # for assertions
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
# Return a list a lint methods
|
48
|
-
#
|
49
|
-
# @return [String]
|
50
|
-
#
|
51
|
-
# @api private
|
52
|
-
def self.lints
|
53
|
-
public_instance_methods(true).grep(/^lint_/).map(&:to_s)
|
54
|
-
end
|
55
|
-
|
56
|
-
# Raise a failure if a lint verification fails
|
57
|
-
#
|
58
|
-
# @raise [ROM::Lint::Linter::Failure]
|
59
|
-
#
|
60
|
-
# @api private
|
61
|
-
def complain(*args)
|
62
|
-
raise Failure, *args
|
63
|
-
end
|
64
|
-
|
65
|
-
# Hook method executed before each lint method run
|
66
|
-
#
|
67
|
-
# @api private
|
68
|
-
def before_lint
|
69
|
-
end
|
70
|
-
|
71
|
-
# Hook method executed after each lint method run
|
72
|
-
#
|
73
|
-
# @api private
|
74
|
-
def after_lint
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
data/lib/rom/lint/spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'rom/lint/gateway'
|
2
|
-
require 'rom/lint/enumerable_dataset'
|
3
|
-
|
4
|
-
RSpec.shared_examples "a rom gateway" do
|
5
|
-
ROM::Lint::Gateway.each_lint do |name, linter|
|
6
|
-
it name do
|
7
|
-
result = linter.new(identifier, gateway, uri).lint(name)
|
8
|
-
expect(result).to be_truthy
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
RSpec.shared_examples "a rom enumerable dataset" do
|
14
|
-
ROM::Lint::EnumerableDataset.each_lint do |name, linter|
|
15
|
-
it name do
|
16
|
-
result = linter.new(dataset, data).lint(name)
|
17
|
-
expect(result).to be_truthy
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/rom/lint/test.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
require 'rom/lint/gateway'
|
2
|
-
require 'rom/lint/enumerable_dataset'
|
3
|
-
|
4
|
-
module ROM
|
5
|
-
module Lint
|
6
|
-
# A module that helps to define test methods
|
7
|
-
module Test
|
8
|
-
# Defines a test method converting lint failures to assertions
|
9
|
-
#
|
10
|
-
# @param [String] name
|
11
|
-
#
|
12
|
-
# @api private
|
13
|
-
def define_test_method(name, &block)
|
14
|
-
define_method "test_#{name}" do
|
15
|
-
begin
|
16
|
-
instance_eval(&block)
|
17
|
-
rescue ROM::Lint::Linter::Failure => f
|
18
|
-
raise Minitest::Assertion, f.message
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# This is a simple lint-test for gateway class to ensure the
|
25
|
-
# basic interfaces are in place
|
26
|
-
#
|
27
|
-
# @example
|
28
|
-
#
|
29
|
-
# class MyGatewayTest < Minitest::Test
|
30
|
-
# include ROM::Lint::TestGateway
|
31
|
-
#
|
32
|
-
# def setup
|
33
|
-
# @gateway = MyGateway
|
34
|
-
# @uri = "super_db://something"
|
35
|
-
# end
|
36
|
-
# end
|
37
|
-
#
|
38
|
-
# @api public
|
39
|
-
module TestGateway
|
40
|
-
extend ROM::Lint::Test
|
41
|
-
|
42
|
-
# Returns the gateway identifier e.g. +:memory+
|
43
|
-
#
|
44
|
-
# @api public
|
45
|
-
attr_reader :identifier
|
46
|
-
|
47
|
-
# Returns the gateway class
|
48
|
-
#
|
49
|
-
# @api public
|
50
|
-
attr_reader :gateway
|
51
|
-
|
52
|
-
# Returns gateway's URI e.g. "super_db://something"
|
53
|
-
#
|
54
|
-
# @api public
|
55
|
-
attr_reader :uri
|
56
|
-
|
57
|
-
ROM::Lint::Gateway.each_lint do |name, linter|
|
58
|
-
define_test_method name do
|
59
|
-
assert linter.new(identifier, gateway, uri).lint(name)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# This is a simple lint-test for a gateway dataset class to ensure the
|
65
|
-
# basic behavior is correct
|
66
|
-
#
|
67
|
-
# @example
|
68
|
-
#
|
69
|
-
# class MyDatasetLintTest < Minitest::Test
|
70
|
-
# include ROM::Lint::TestEnumerableDataset
|
71
|
-
#
|
72
|
-
# def setup
|
73
|
-
# @data = [{ name: 'Jane', age: 24 }, { name: 'Joe', age: 25 }]
|
74
|
-
# @dataset = MyDataset.new(@data, [:name, :age])
|
75
|
-
# end
|
76
|
-
# end
|
77
|
-
# @api public
|
78
|
-
module TestEnumerableDataset
|
79
|
-
extend ROM::Lint::Test
|
80
|
-
|
81
|
-
# Returns the dataset instance
|
82
|
-
#
|
83
|
-
# @api public
|
84
|
-
attr_reader :dataset
|
85
|
-
|
86
|
-
# Returns the expected data
|
87
|
-
#
|
88
|
-
# @api public
|
89
|
-
attr_reader :data
|
90
|
-
|
91
|
-
ROM::Lint::EnumerableDataset.each_lint do |name, linter|
|
92
|
-
define_test_method name do
|
93
|
-
assert linter.new(dataset, data).lint(name)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
data/lib/rom/mapper_registry.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'rom/registry'
|
2
|
-
|
3
|
-
module ROM
|
4
|
-
# @private
|
5
|
-
class MapperRegistry < Registry
|
6
|
-
# @api private
|
7
|
-
def []=(name, mapper)
|
8
|
-
elements[name] = mapper
|
9
|
-
end
|
10
|
-
|
11
|
-
# @api private
|
12
|
-
def [](name)
|
13
|
-
elements.fetch(name) { raise(MapperMissingError, name) }
|
14
|
-
end
|
15
|
-
|
16
|
-
# @api private
|
17
|
-
def key?(name)
|
18
|
-
elements.key?(name)
|
19
|
-
end
|
20
|
-
|
21
|
-
# @api private
|
22
|
-
def by_path(path)
|
23
|
-
elements.fetch(paths(path).detect { |name| elements.key?(name) }) {
|
24
|
-
raise(MapperMissingError, path)
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
# @api private
|
31
|
-
def paths(path)
|
32
|
-
path.split('.').map(&:to_sym).reverse
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/lib/rom/memory/commands.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'rom/commands'
|
2
|
-
|
3
|
-
module ROM
|
4
|
-
module Memory
|
5
|
-
# Memory adapter commands namespace
|
6
|
-
#
|
7
|
-
# @api public
|
8
|
-
module Commands
|
9
|
-
# In-memory create command
|
10
|
-
#
|
11
|
-
# @api public
|
12
|
-
class Create < ROM::Commands::Create
|
13
|
-
adapter :memory
|
14
|
-
use :schema
|
15
|
-
|
16
|
-
# @see ROM::Commands::Create#execute
|
17
|
-
def execute(tuples)
|
18
|
-
Array([tuples]).flatten.map { |tuple|
|
19
|
-
attributes = input[tuple]
|
20
|
-
relation.insert(attributes.to_h)
|
21
|
-
attributes
|
22
|
-
}.to_a
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# In-memory update command
|
27
|
-
#
|
28
|
-
# @api public
|
29
|
-
class Update < ROM::Commands::Update
|
30
|
-
adapter :memory
|
31
|
-
use :schema
|
32
|
-
|
33
|
-
# @see ROM::Commands::Update#execute
|
34
|
-
def execute(params)
|
35
|
-
attributes = input[params]
|
36
|
-
relation.map { |tuple| tuple.update(attributes.to_h) }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# In-memory delete command
|
41
|
-
#
|
42
|
-
# @api public
|
43
|
-
class Delete < ROM::Commands::Delete
|
44
|
-
adapter :memory
|
45
|
-
|
46
|
-
# @see ROM::Commands::Delete#execute
|
47
|
-
def execute
|
48
|
-
relation.to_a.map do |tuple|
|
49
|
-
source.delete(tuple)
|
50
|
-
tuple
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
data/lib/rom/memory/dataset.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'rom/array_dataset'
|
2
|
-
|
3
|
-
module ROM
|
4
|
-
module Memory
|
5
|
-
# In-memory dataset
|
6
|
-
#
|
7
|
-
# @api public
|
8
|
-
class Dataset
|
9
|
-
include ArrayDataset
|
10
|
-
|
11
|
-
# Join two datasets
|
12
|
-
#
|
13
|
-
# @api public
|
14
|
-
def join(*args)
|
15
|
-
left, right = args.size > 1 ? args : [self, args.first]
|
16
|
-
|
17
|
-
join_map = left.each_with_object({}) { |tuple, h|
|
18
|
-
others = right.to_a.find_all { |t| (tuple.to_a & t.to_a).any? }
|
19
|
-
(h[tuple] ||= []).concat(others)
|
20
|
-
}
|
21
|
-
|
22
|
-
tuples = left.flat_map { |tuple|
|
23
|
-
join_map[tuple].map { |other| tuple.merge(other) }
|
24
|
-
}
|
25
|
-
|
26
|
-
self.class.new(tuples, options)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Restrict a dataset
|
30
|
-
#
|
31
|
-
# @api public
|
32
|
-
def restrict(criteria = nil)
|
33
|
-
return find_all { |tuple| yield(tuple) } unless criteria
|
34
|
-
find_all do |tuple|
|
35
|
-
criteria.all? do |k, v|
|
36
|
-
case v
|
37
|
-
when Array then v.include?(tuple[k])
|
38
|
-
when Regexp then tuple[k].match(v)
|
39
|
-
else tuple[k].eql?(v)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Project a dataset
|
46
|
-
#
|
47
|
-
# @api public
|
48
|
-
def project(*names)
|
49
|
-
map { |tuple| tuple.reject { |key| !names.include?(key) } }
|
50
|
-
end
|
51
|
-
|
52
|
-
# Sort a dataset
|
53
|
-
#
|
54
|
-
# @param [Array<Symbol>] names
|
55
|
-
# Names of fields to order tuples by
|
56
|
-
#
|
57
|
-
# @option [Boolean] :nils_first (false)
|
58
|
-
# Whether `nil` values should be placed before others
|
59
|
-
#
|
60
|
-
# @api public
|
61
|
-
def order(*fields)
|
62
|
-
nils_first = fields.pop[:nils_first] if fields.last.is_a?(Hash)
|
63
|
-
|
64
|
-
sort do |a, b|
|
65
|
-
fields # finds the first difference between selected fields of tuples
|
66
|
-
.map { |n| __compare__ a[n], b[n], nils_first }
|
67
|
-
.detect(-> { 0 }) { |r| r != 0 }
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# Insert tuple into a dataset
|
72
|
-
#
|
73
|
-
# @api public
|
74
|
-
def insert(tuple)
|
75
|
-
data << tuple
|
76
|
-
self
|
77
|
-
end
|
78
|
-
alias_method :<<, :insert
|
79
|
-
|
80
|
-
# Delete tuples from a dataset
|
81
|
-
#
|
82
|
-
# @api public
|
83
|
-
def delete(tuple)
|
84
|
-
data.delete(tuple)
|
85
|
-
self
|
86
|
-
end
|
87
|
-
|
88
|
-
private
|
89
|
-
|
90
|
-
# Compares two values, that are either comparable, or can be nils
|
91
|
-
def __compare__(a, b, nils_first)
|
92
|
-
return a <=> b unless a.nil? ^ b.nil?
|
93
|
-
(nils_first ^ b.nil?) ? -1 : 1
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
data/lib/rom/memory/gateway.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'rom/gateway'
|
2
|
-
require 'rom/memory/storage'
|
3
|
-
require 'rom/memory/commands'
|
4
|
-
|
5
|
-
module ROM
|
6
|
-
module Memory
|
7
|
-
# In-memory gateway interface
|
8
|
-
#
|
9
|
-
# @example
|
10
|
-
# gateway = ROM::Memory::Gateway.new
|
11
|
-
# gateway.dataset(:users)
|
12
|
-
# gateway[:users].insert(name: 'Jane')
|
13
|
-
#
|
14
|
-
# @api public
|
15
|
-
class Gateway < ROM::Gateway
|
16
|
-
adapter :memory
|
17
|
-
|
18
|
-
# @return [Object] default logger
|
19
|
-
#
|
20
|
-
# @api public
|
21
|
-
attr_reader :logger
|
22
|
-
|
23
|
-
# @api private
|
24
|
-
def initialize
|
25
|
-
@connection = Storage.new
|
26
|
-
end
|
27
|
-
|
28
|
-
# Set default logger for the gateway
|
29
|
-
#
|
30
|
-
# @param [Object] logger object
|
31
|
-
#
|
32
|
-
# @api public
|
33
|
-
def use_logger(logger)
|
34
|
-
@logger = logger
|
35
|
-
end
|
36
|
-
|
37
|
-
# Register a dataset in the gateway
|
38
|
-
#
|
39
|
-
# If dataset already exists it will be returned
|
40
|
-
#
|
41
|
-
# @return [Dataset]
|
42
|
-
#
|
43
|
-
# @api public
|
44
|
-
def dataset(name)
|
45
|
-
self[name] || connection.create_dataset(name)
|
46
|
-
end
|
47
|
-
|
48
|
-
# @see ROM::Gateway#dataset?
|
49
|
-
def dataset?(name)
|
50
|
-
connection.key?(name)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Return dataset with the given name
|
54
|
-
#
|
55
|
-
# @param (see ROM::Gateway#[])
|
56
|
-
# @return [Memory::Dataset]
|
57
|
-
#
|
58
|
-
# @api public
|
59
|
-
def [](name)
|
60
|
-
connection[name]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
data/lib/rom/memory/relation.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'rom/memory/types'
|
2
|
-
require 'rom/memory/schema'
|
3
|
-
|
4
|
-
module ROM
|
5
|
-
module Memory
|
6
|
-
# Relation subclass for memory adapter
|
7
|
-
#
|
8
|
-
# @example
|
9
|
-
# class Users < ROM::Relation[:memory]
|
10
|
-
# end
|
11
|
-
#
|
12
|
-
# @api public
|
13
|
-
class Relation < ROM::Relation
|
14
|
-
include Enumerable
|
15
|
-
include Memory
|
16
|
-
|
17
|
-
adapter :memory
|
18
|
-
schema_class Memory::Schema
|
19
|
-
|
20
|
-
forward :take, :join, :restrict, :order
|
21
|
-
|
22
|
-
# Project a relation with provided attribute names
|
23
|
-
#
|
24
|
-
# @param [*Array] names A list with attribute names
|
25
|
-
#
|
26
|
-
# @return [Memory::Relation]
|
27
|
-
#
|
28
|
-
# @api public
|
29
|
-
def project(*names)
|
30
|
-
schema.project(*names).(self)
|
31
|
-
end
|
32
|
-
|
33
|
-
# Insert tuples into the relation
|
34
|
-
#
|
35
|
-
# @example
|
36
|
-
# users.insert(name: 'Jane')
|
37
|
-
#
|
38
|
-
# @return [Relation]
|
39
|
-
#
|
40
|
-
# @api public
|
41
|
-
def insert(*args)
|
42
|
-
dataset.insert(*args)
|
43
|
-
self
|
44
|
-
end
|
45
|
-
alias_method :<<, :insert
|
46
|
-
|
47
|
-
# Delete tuples from the relation
|
48
|
-
#
|
49
|
-
# @example
|
50
|
-
# users.insert(name: 'Jane')
|
51
|
-
# users.delete(name: 'Jane')
|
52
|
-
#
|
53
|
-
# @return [Relation]
|
54
|
-
#
|
55
|
-
# @api public
|
56
|
-
def delete(*args)
|
57
|
-
dataset.delete(*args)
|
58
|
-
self
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
data/lib/rom/memory/schema.rb
DELETED
data/lib/rom/memory/storage.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'concurrent/hash'
|
2
|
-
require 'concurrent/array'
|
3
|
-
|
4
|
-
require 'rom/memory/dataset'
|
5
|
-
|
6
|
-
module ROM
|
7
|
-
module Memory
|
8
|
-
# In-memory thread-safe data storage
|
9
|
-
#
|
10
|
-
# @private
|
11
|
-
class Storage
|
12
|
-
# Dataset registry
|
13
|
-
#
|
14
|
-
# @return [ThreadSafe::Hash]
|
15
|
-
#
|
16
|
-
# @api private
|
17
|
-
attr_reader :data
|
18
|
-
|
19
|
-
# @api private
|
20
|
-
def initialize
|
21
|
-
@data = Concurrent::Hash.new
|
22
|
-
end
|
23
|
-
|
24
|
-
# @return [Dataset]
|
25
|
-
#
|
26
|
-
# @api private
|
27
|
-
def [](name)
|
28
|
-
data[name]
|
29
|
-
end
|
30
|
-
|
31
|
-
# Register a new dataset
|
32
|
-
#
|
33
|
-
# @return [Dataset]
|
34
|
-
#
|
35
|
-
# @api private
|
36
|
-
def create_dataset(name)
|
37
|
-
data[name] = Dataset.new(Concurrent::Array.new)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Check if there's dataset under specified key
|
41
|
-
#
|
42
|
-
# @return [Boolean]
|
43
|
-
#
|
44
|
-
# @api private
|
45
|
-
def key?(name)
|
46
|
-
data.key?(name)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Return registered datasets count
|
50
|
-
#
|
51
|
-
# @return [Integer]
|
52
|
-
#
|
53
|
-
# @api private
|
54
|
-
def size
|
55
|
-
data.size
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
data/lib/rom/memory/types.rb
DELETED
data/lib/rom/memory.rb
DELETED