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,36 +0,0 @@
|
|
1
|
-
require 'dry/core/class_builder'
|
2
|
-
|
3
|
-
module ROM
|
4
|
-
module ConfigurationDSL
|
5
|
-
# Setup DSL-specific mapper extensions
|
6
|
-
#
|
7
|
-
# @private
|
8
|
-
class Mapper
|
9
|
-
# Generate a mapper subclass
|
10
|
-
#
|
11
|
-
# This is used by Setup#mappers DSL
|
12
|
-
#
|
13
|
-
# @api private
|
14
|
-
def self.build_class(name, mapper_registry, options = EMPTY_HASH, &block)
|
15
|
-
class_name = "ROM::Mapper[#{name}]"
|
16
|
-
|
17
|
-
parent = options[:parent]
|
18
|
-
inherit_header = options.fetch(:inherit_header) { ROM::Mapper.inherit_header }
|
19
|
-
|
20
|
-
parent_class =
|
21
|
-
if parent
|
22
|
-
mapper_registry.detect { |klass| klass.relation == parent }
|
23
|
-
else
|
24
|
-
ROM::Mapper
|
25
|
-
end
|
26
|
-
|
27
|
-
Dry::Core::ClassBuilder.new(name: class_name, parent: parent_class).call do |klass|
|
28
|
-
klass.relation(name)
|
29
|
-
klass.inherit_header(inherit_header)
|
30
|
-
|
31
|
-
klass.class_eval(&block) if block
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'rom/configuration_dsl/mapper'
|
2
|
-
|
3
|
-
module ROM
|
4
|
-
module ConfigurationDSL
|
5
|
-
# Mapper definition DSL used by Setup DSL
|
6
|
-
#
|
7
|
-
# @private
|
8
|
-
class MapperDSL
|
9
|
-
attr_reader :registry, :mapper_classes, :mapper_classes
|
10
|
-
|
11
|
-
# @api private
|
12
|
-
def initialize(registry, mapper_classes, block)
|
13
|
-
@registry = registry
|
14
|
-
@mapper_classes = mapper_classes
|
15
|
-
@defined_mappers = []
|
16
|
-
|
17
|
-
instance_exec(&block)
|
18
|
-
|
19
|
-
@mapper_classes = @defined_mappers
|
20
|
-
end
|
21
|
-
|
22
|
-
# Define a mapper class
|
23
|
-
#
|
24
|
-
# @param [Symbol] name of the mapper
|
25
|
-
# @param [Hash] options
|
26
|
-
#
|
27
|
-
# @return [Class]
|
28
|
-
#
|
29
|
-
# @api public
|
30
|
-
def define(name, options = EMPTY_HASH, &block)
|
31
|
-
@defined_mappers << Mapper.build_class(name, (@mapper_classes + @defined_mappers), options, &block)
|
32
|
-
self
|
33
|
-
end
|
34
|
-
|
35
|
-
# TODO
|
36
|
-
#
|
37
|
-
# @api public
|
38
|
-
def register(relation, mappers)
|
39
|
-
registry.register_mapper(relation => mappers)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'dry/core/class_builder'
|
2
|
-
require 'dry/core/inflector'
|
3
|
-
|
4
|
-
module ROM
|
5
|
-
module ConfigurationDSL
|
6
|
-
# Setup DSL-specific relation extensions
|
7
|
-
#
|
8
|
-
# @private
|
9
|
-
class Relation
|
10
|
-
# Generate a relation subclass
|
11
|
-
#
|
12
|
-
# This is used by Setup#relation DSL
|
13
|
-
#
|
14
|
-
# @api private
|
15
|
-
def self.build_class(name, options = EMPTY_HASH)
|
16
|
-
class_name = "ROM::Relation[#{Dry::Core::Inflector.camelize(name)}]"
|
17
|
-
adapter = options.fetch(:adapter)
|
18
|
-
|
19
|
-
Dry::Core::ClassBuilder.new(name: class_name, parent: ROM::Relation[adapter]).call do |klass|
|
20
|
-
klass.gateway(options.fetch(:gateway, :default))
|
21
|
-
klass.dataset(name, deprecation: false)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'rom/configuration_dsl/relation'
|
2
|
-
require 'rom/configuration_dsl/mapper_dsl'
|
3
|
-
require 'rom/configuration_dsl/command_dsl'
|
4
|
-
|
5
|
-
module ROM
|
6
|
-
# This extends Configuration class with the DSL methods
|
7
|
-
#
|
8
|
-
# @api public
|
9
|
-
module ConfigurationDSL
|
10
|
-
# Relation definition DSL
|
11
|
-
#
|
12
|
-
# @example
|
13
|
-
#
|
14
|
-
# setup.relation(:users) do
|
15
|
-
# def names
|
16
|
-
# project(:name)
|
17
|
-
# end
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# @api public
|
21
|
-
def relation(name, options = EMPTY_HASH, &block)
|
22
|
-
klass_opts = { adapter: default_adapter }.merge(options)
|
23
|
-
klass = Relation.build_class(name, klass_opts)
|
24
|
-
klass.register_as(name, deprecation: false)
|
25
|
-
klass.class_eval(&block) if block
|
26
|
-
register_relation(klass)
|
27
|
-
klass
|
28
|
-
end
|
29
|
-
|
30
|
-
# Mapper definition DSL
|
31
|
-
#
|
32
|
-
# @example
|
33
|
-
#
|
34
|
-
# setup.mappers do
|
35
|
-
# define(:users) do
|
36
|
-
# model name: 'User'
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# define(:names, parent: :users) do
|
40
|
-
# exclude :id
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
#
|
44
|
-
# @api public
|
45
|
-
def mappers(&block)
|
46
|
-
register_mapper(*MapperDSL.new(self, mapper_classes, block).mapper_classes)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Command definition DSL
|
50
|
-
#
|
51
|
-
# @example
|
52
|
-
#
|
53
|
-
# setup.commands(:users) do
|
54
|
-
# define(:create) do
|
55
|
-
# input NewUserParams
|
56
|
-
# result :one
|
57
|
-
# end
|
58
|
-
#
|
59
|
-
# define(:update) do
|
60
|
-
# input UserParams
|
61
|
-
# result :many
|
62
|
-
# end
|
63
|
-
#
|
64
|
-
# define(:delete) do
|
65
|
-
# result :many
|
66
|
-
# end
|
67
|
-
# end
|
68
|
-
#
|
69
|
-
# @api public
|
70
|
-
def commands(name, &block)
|
71
|
-
register_command(*CommandDSL.new(name, default_adapter, &block).command_classes)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Configures a plugin for a specific adapter to be enabled for all relations
|
75
|
-
#
|
76
|
-
# @example
|
77
|
-
# config = ROM::Configuration.new(:sql, 'sqlite::memory')
|
78
|
-
#
|
79
|
-
# config.plugin(:sql, relations: :instrumentation) do |p|
|
80
|
-
# p.notifications = MyNotificationsBackend
|
81
|
-
# end
|
82
|
-
#
|
83
|
-
# config.plugin(:sql, relations: :pagination)
|
84
|
-
#
|
85
|
-
# @param [Symbol] adapter The adapter identifier
|
86
|
-
# @param [Hash<Symbol=>Symbol>] spec Component identifier => plugin identifier
|
87
|
-
#
|
88
|
-
# @return [Plugin]
|
89
|
-
#
|
90
|
-
# @api public
|
91
|
-
def plugin(adapter, spec, &block)
|
92
|
-
type, name = spec.flatten(1)
|
93
|
-
plugin = plugin_registry.send(type).adapter(adapter).fetch(name) { plugin_registry.send(type).fetch(name) }
|
94
|
-
|
95
|
-
if block
|
96
|
-
register_plugin(plugin.configure(&block))
|
97
|
-
else
|
98
|
-
register_plugin(plugin)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
# @api private
|
103
|
-
def plugin_registry
|
104
|
-
ROM.plugin_registry
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'rom/plugin_base'
|
2
|
-
|
3
|
-
module ROM
|
4
|
-
# ConfigurationPlugin is a simple object used to store configuration plugin configurations
|
5
|
-
#
|
6
|
-
# @private
|
7
|
-
class ConfigurationPlugin < PluginBase
|
8
|
-
# Apply this plugin to the provided configuration
|
9
|
-
#
|
10
|
-
# @param [ROM::Configuration] configuration
|
11
|
-
#
|
12
|
-
# @api private
|
13
|
-
def apply_to(configuration, options = {})
|
14
|
-
mod.apply(configuration, options)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/rom/constants.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# Constants and errors common in the whole library
|
2
|
-
module ROM
|
3
|
-
AdapterLoadError = Class.new(StandardError)
|
4
|
-
|
5
|
-
class AdapterNotPresentError < StandardError
|
6
|
-
def initialize(adapter, component)
|
7
|
-
super(
|
8
|
-
"Failed to find #{component} class for #{adapter} adapter. " \
|
9
|
-
"Make sure ROM setup was started and the adapter identifier is correct."
|
10
|
-
)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
EnvAlreadyFinalizedError = Class.new(StandardError)
|
15
|
-
RelationAlreadyDefinedError = Class.new(StandardError)
|
16
|
-
NoRelationError = Class.new(StandardError)
|
17
|
-
CommandError = Class.new(StandardError)
|
18
|
-
KeyMissing = Class.new(ROM::CommandError)
|
19
|
-
TupleCountMismatchError = Class.new(CommandError)
|
20
|
-
MapperMissingError = Class.new(StandardError)
|
21
|
-
UnknownPluginError = Class.new(StandardError)
|
22
|
-
UnsupportedRelationError = Class.new(StandardError)
|
23
|
-
MissingAdapterIdentifierError = Class.new(StandardError)
|
24
|
-
|
25
|
-
MissingSchemaClassError = Class.new(StandardError) do
|
26
|
-
def initialize(klass)
|
27
|
-
super("#{klass.inspect} relation is missing schema_class")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
DuplicateConfigurationError = Class.new(StandardError)
|
32
|
-
DuplicateContainerError = Class.new(StandardError)
|
33
|
-
|
34
|
-
InvalidOptionValueError = Class.new(StandardError)
|
35
|
-
InvalidOptionKeyError = Class.new(StandardError)
|
36
|
-
end
|
data/lib/rom/container.rb
DELETED
@@ -1,233 +0,0 @@
|
|
1
|
-
require 'dry/core/deprecations'
|
2
|
-
|
3
|
-
require 'rom/relation/loaded'
|
4
|
-
require 'rom/commands/graph'
|
5
|
-
require 'rom/commands/graph/builder'
|
6
|
-
|
7
|
-
module ROM
|
8
|
-
# ROM container is an isolated environment with no global state where all
|
9
|
-
# components are registered. Container objects provide access to your
|
10
|
-
# relations, commands and mappers. ROM containers are usually configured and
|
11
|
-
# handled via framework integrations, although it is easy to use them
|
12
|
-
# standalone.
|
13
|
-
#
|
14
|
-
# There are 3 types of container setup:
|
15
|
-
#
|
16
|
-
# * Setup DSL - a simple block-based configuration which allows configuring
|
17
|
-
# all components and gives you back a container instance. This type is suitable
|
18
|
-
# for small scripts, or in some cases rake tasks
|
19
|
-
# * Explicit setup - this type requires creating a configuration object,
|
20
|
-
# registering component classes (ie relation classes) and passing the config
|
21
|
-
# to container builder function. This type is suitable when your environment
|
22
|
-
# is not typical and you need full control over component registration
|
23
|
-
# * Explicit setup with auto-registration - same as explicit setup but allows
|
24
|
-
# you to configure auto-registration mechanism which will register component
|
25
|
-
# classes for you, based on dir/file naming conventions. This is the most
|
26
|
-
# common type of setup that's used by framework integrations
|
27
|
-
#
|
28
|
-
# @example in-line setup
|
29
|
-
# rom = ROM.container(:sql, 'sqlite::memory') do |config|
|
30
|
-
# config.default.create_table :users do
|
31
|
-
# primary_key :id
|
32
|
-
# column :name, String, null: false
|
33
|
-
# end
|
34
|
-
#
|
35
|
-
# config.relation(:users) do
|
36
|
-
# schema(infer: true)
|
37
|
-
#
|
38
|
-
# def by_name(name)
|
39
|
-
# where(name: name)
|
40
|
-
# end
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
#
|
44
|
-
# rom.relations[:users].insert(name: "Jane")
|
45
|
-
#
|
46
|
-
# rom.relations[:users].by_name("Jane").to_a
|
47
|
-
# # [{:id=>1, :name=>"Jane"}]
|
48
|
-
#
|
49
|
-
# @example multi-step setup with explicit component classes
|
50
|
-
# config = ROM::Configuration.new(:sql, 'sqlite::memory')
|
51
|
-
#
|
52
|
-
# config.default.create_table :users do
|
53
|
-
# primary_key :id
|
54
|
-
# column :name, String, null: false
|
55
|
-
# end
|
56
|
-
#
|
57
|
-
# class Users < ROM::Relation[:sql]
|
58
|
-
# schema(:users, infer: true)
|
59
|
-
#
|
60
|
-
# def by_name(name)
|
61
|
-
# where(name: name)
|
62
|
-
# end
|
63
|
-
# end
|
64
|
-
#
|
65
|
-
# config.register_relation(Users)
|
66
|
-
#
|
67
|
-
# rom = ROM.container(config)
|
68
|
-
#
|
69
|
-
# rom.relations[:users].insert(name: "Jane")
|
70
|
-
#
|
71
|
-
# rom.relations[:users].by_name("Jane").to_a
|
72
|
-
# # [{:id=>1, :name=>"Jane"}]
|
73
|
-
#
|
74
|
-
#
|
75
|
-
# @example multi-step setup with auto-registration
|
76
|
-
# config = ROM::Configuration.new(:sql, 'sqlite::memory')
|
77
|
-
# config.auto_registration('./persistence', namespace: false)
|
78
|
-
#
|
79
|
-
# config.default.create_table :users do
|
80
|
-
# primary_key :id
|
81
|
-
# column :name, String, null: false
|
82
|
-
# end
|
83
|
-
#
|
84
|
-
# # ./persistence/relations/users.rb
|
85
|
-
# class Users < ROM::Relation[:sql]
|
86
|
-
# schema(infer: true)
|
87
|
-
#
|
88
|
-
# def by_name(name)
|
89
|
-
# where(name: name)
|
90
|
-
# end
|
91
|
-
# end
|
92
|
-
#
|
93
|
-
# rom = ROM.container(config)
|
94
|
-
#
|
95
|
-
# rom.relations[:users].insert(name: "Jane")
|
96
|
-
#
|
97
|
-
# rom.relations[:users].by_name("Jane").to_a
|
98
|
-
# # [{:id=>1, :name=>"Jane"}]
|
99
|
-
#
|
100
|
-
# @api public
|
101
|
-
class Container
|
102
|
-
extend Dry::Core::Deprecations[:rom]
|
103
|
-
|
104
|
-
include Dry::Equalizer(:gateways, :relations, :mappers, :commands)
|
105
|
-
|
106
|
-
# @!attribute [r] gateways
|
107
|
-
# @return [Hash] A hash with configured gateways
|
108
|
-
attr_reader :gateways
|
109
|
-
|
110
|
-
# @!attribute [r] relations
|
111
|
-
# @return [RelationRegistry] The relation registry
|
112
|
-
attr_reader :relations
|
113
|
-
|
114
|
-
# @!attribute [r] gateways
|
115
|
-
# @return [CommandRegistry] The command registry
|
116
|
-
attr_reader :commands
|
117
|
-
|
118
|
-
# @!attribute [r] mappers
|
119
|
-
# @return [Hash] A hash with configured custom mappers
|
120
|
-
attr_reader :mappers
|
121
|
-
|
122
|
-
# @api private
|
123
|
-
def initialize(gateways, relations, mappers, commands)
|
124
|
-
@gateways = gateways
|
125
|
-
@relations = relations
|
126
|
-
@mappers = mappers
|
127
|
-
@commands = commands
|
128
|
-
end
|
129
|
-
|
130
|
-
# Get relation instance identified by its name
|
131
|
-
#
|
132
|
-
# This method will use a custom mapper if it was configured. ie if you have
|
133
|
-
# a relation called `:users` and a mapper configured for `:users` relation,
|
134
|
-
# then by default this mapper will be used.
|
135
|
-
#
|
136
|
-
# @example
|
137
|
-
# rom.relation(:users)
|
138
|
-
# rom.relation(:users).by_name('Jane')
|
139
|
-
#
|
140
|
-
# # block syntax allows accessing lower-level query DSLs (usage is discouraged though)
|
141
|
-
# rom.relation { |r| r.restrict(name: 'Jane') }
|
142
|
-
#
|
143
|
-
# # with mapping
|
144
|
-
# rom.relation(:users).map_with(:presenter)
|
145
|
-
#
|
146
|
-
# # using multiple mappers
|
147
|
-
# rom.relation(:users).page(1).map_with(:presenter, :json_serializer)
|
148
|
-
#
|
149
|
-
# @param [Symbol] name of the relation to load
|
150
|
-
#
|
151
|
-
# @yield [Relation]
|
152
|
-
#
|
153
|
-
# @return [Relation]
|
154
|
-
#
|
155
|
-
# @api public
|
156
|
-
def relation(name, &block)
|
157
|
-
Dry::Core::Deprecations.warn("#{self.class}#relation is deprecated and will be removed in 4.0\n\n#{caller[0..5].join("\n")}")
|
158
|
-
|
159
|
-
relation =
|
160
|
-
if block
|
161
|
-
yield(relations[name])
|
162
|
-
else
|
163
|
-
relations[name]
|
164
|
-
end
|
165
|
-
|
166
|
-
if mappers.key?(name)
|
167
|
-
relation.with(mappers: mappers[name])
|
168
|
-
else
|
169
|
-
relation
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
# Returns commands registry for the given relation
|
174
|
-
#
|
175
|
-
# @example
|
176
|
-
# # plain command without mapping
|
177
|
-
# rom.command(:users).create
|
178
|
-
#
|
179
|
-
# # allows auto-mapping using registered mappers
|
180
|
-
# rom.command(:users).as(:entity)
|
181
|
-
#
|
182
|
-
# # allows building up a command graph for nested input
|
183
|
-
# command = rom.command([:users, [:create, [:tasks, [:create]]]])
|
184
|
-
#
|
185
|
-
# command.call(users: [{ name: 'Jane', tasks: [{ title: 'One' }] }])
|
186
|
-
#
|
187
|
-
# @param [Array,Symbol] options Either graph options or registered command name
|
188
|
-
#
|
189
|
-
# @return [Command, Command::Graph]
|
190
|
-
#
|
191
|
-
# @api public
|
192
|
-
def command(options = nil)
|
193
|
-
Dry::Core::Deprecations.warn("#{self.class}#command is deprecated and will be removed in 4.0\n\n#{caller[0..5].join("\n")}")
|
194
|
-
|
195
|
-
case options
|
196
|
-
when Symbol
|
197
|
-
name = options
|
198
|
-
if mappers.key?(name)
|
199
|
-
commands[name].with(mappers: mappers[name])
|
200
|
-
else
|
201
|
-
commands[name]
|
202
|
-
end
|
203
|
-
when Array
|
204
|
-
graph = Commands::Graph.build(commands, options)
|
205
|
-
name = graph.name
|
206
|
-
|
207
|
-
if mappers.key?(name)
|
208
|
-
graph.with(mappers: mappers[name])
|
209
|
-
else
|
210
|
-
graph
|
211
|
-
end
|
212
|
-
when nil
|
213
|
-
Commands::Graph::Builder.new(self)
|
214
|
-
else
|
215
|
-
raise ArgumentError, "#{self.class}#command accepts a symbol or an array"
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
# Disconnect all gateways
|
220
|
-
#
|
221
|
-
# @example
|
222
|
-
# rom = ROM.container(:sql, 'sqlite://my_db.sqlite')
|
223
|
-
# rom.relations[:users].insert(name: "Jane")
|
224
|
-
# rom.disconnect
|
225
|
-
#
|
226
|
-
# @return [Hash<Symbol=>Gateway>] a hash with disconnected gateways
|
227
|
-
#
|
228
|
-
# @api public
|
229
|
-
def disconnect
|
230
|
-
gateways.each_value(&:disconnect)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
data/lib/rom/create_container.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'rom/configuration'
|
2
|
-
require 'rom/environment'
|
3
|
-
require 'rom/setup'
|
4
|
-
require 'rom/setup/finalize'
|
5
|
-
|
6
|
-
module ROM
|
7
|
-
class CreateContainer
|
8
|
-
attr_reader :container
|
9
|
-
|
10
|
-
def initialize(environment, setup)
|
11
|
-
@container = finalize(environment, setup)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def finalize(environment, setup)
|
17
|
-
environment.configure do |config|
|
18
|
-
environment.gateways.each_key do |key|
|
19
|
-
gateway_config = config.gateways[key]
|
20
|
-
gateway_config.infer_relations = true unless gateway_config.key?(:infer_relations)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
finalize = Finalize.new(
|
25
|
-
gateways: environment.gateways,
|
26
|
-
gateway_map: environment.gateways_map,
|
27
|
-
relation_classes: setup.relation_classes,
|
28
|
-
command_classes: setup.command_classes,
|
29
|
-
mappers: setup.mapper_classes,
|
30
|
-
plugins: setup.plugins,
|
31
|
-
config: environment.config.dup.freeze
|
32
|
-
)
|
33
|
-
|
34
|
-
finalize.run!
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class InlineCreateContainer < CreateContainer
|
39
|
-
def initialize(*args, &block)
|
40
|
-
case args.first
|
41
|
-
when Configuration
|
42
|
-
environment = args.first.environment
|
43
|
-
setup = args.first.setup
|
44
|
-
when Environment
|
45
|
-
environment = args.first
|
46
|
-
setup = args[1]
|
47
|
-
else
|
48
|
-
configuration = Configuration.new(*args, &block)
|
49
|
-
environment = configuration.environment
|
50
|
-
setup = configuration.setup
|
51
|
-
end
|
52
|
-
|
53
|
-
super(environment, setup)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.container(*args, &block)
|
58
|
-
InlineCreateContainer.new(*args, &block).container
|
59
|
-
end
|
60
|
-
end
|
data/lib/rom/data_proxy.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
module ROM
|
2
|
-
# Helper module for dataset classes
|
3
|
-
#
|
4
|
-
# It provides a constructor accepting data, header and an optional row_proc.
|
5
|
-
# This module is used internally by EnumerableDataset and ArrayDataset.
|
6
|
-
#
|
7
|
-
# @private
|
8
|
-
module DataProxy
|
9
|
-
NON_FORWARDABLE = [
|
10
|
-
:each, :to_a, :to_ary, :kind_of?, :instance_of?, :is_a?
|
11
|
-
].freeze
|
12
|
-
|
13
|
-
# Wrapped data array
|
14
|
-
#
|
15
|
-
# @return [Object] Data object for the iterator
|
16
|
-
#
|
17
|
-
# @api private
|
18
|
-
attr_reader :data
|
19
|
-
|
20
|
-
# @return [Proc] tuple processing proc
|
21
|
-
#
|
22
|
-
# @api private
|
23
|
-
attr_reader :row_proc
|
24
|
-
|
25
|
-
# Extends the class with `forward` DSL and Equalizer using `data` attribute
|
26
|
-
#
|
27
|
-
# @see ClassMethods#forward
|
28
|
-
#
|
29
|
-
# @api private
|
30
|
-
def self.included(klass)
|
31
|
-
klass.class_eval do
|
32
|
-
extend ClassMethods
|
33
|
-
|
34
|
-
include Dry::Equalizer(:data)
|
35
|
-
|
36
|
-
option :row_proc, default: -> { self.class.row_proc }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# Iterate over data using row_proc
|
41
|
-
#
|
42
|
-
# @return [Enumerator] if block is not given
|
43
|
-
#
|
44
|
-
# @api private
|
45
|
-
def each
|
46
|
-
return to_enum unless block_given?
|
47
|
-
data.each { |tuple| yield(row_proc[tuple]) }
|
48
|
-
end
|
49
|
-
|
50
|
-
module ClassMethods
|
51
|
-
# Default no-op tuple proc
|
52
|
-
#
|
53
|
-
# @return [Proc]
|
54
|
-
#
|
55
|
-
# @api private
|
56
|
-
def row_proc
|
57
|
-
-> tuple { tuple }
|
58
|
-
end
|
59
|
-
|
60
|
-
# Forward provided methods to the underlaying data object
|
61
|
-
#
|
62
|
-
# @example
|
63
|
-
#
|
64
|
-
# class MyDataset
|
65
|
-
# include DataProxy
|
66
|
-
#
|
67
|
-
# forward(:find_all, :map)
|
68
|
-
# end
|
69
|
-
#
|
70
|
-
# @return [undefined]
|
71
|
-
#
|
72
|
-
# @api public
|
73
|
-
def forward(*methods)
|
74
|
-
# FIXME: we should probably raise if one of the non-forwardable methods
|
75
|
-
# was provided
|
76
|
-
(methods - NON_FORWARDABLE).each do |method_name|
|
77
|
-
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
78
|
-
def #{method_name}(*args, &block)
|
79
|
-
response = data.public_send(#{method_name.inspect}, *args, &block)
|
80
|
-
|
81
|
-
if response.equal?(data)
|
82
|
-
self
|
83
|
-
elsif response.is_a?(data.class)
|
84
|
-
self.class.new(response)
|
85
|
-
else
|
86
|
-
response
|
87
|
-
end
|
88
|
-
end
|
89
|
-
RUBY
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|