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
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'rom/relation_registry'
|
2
|
-
require 'rom/mapper_registry'
|
3
|
-
|
4
|
-
module ROM
|
5
|
-
class Finalize
|
6
|
-
class FinalizeRelations
|
7
|
-
# Build relation registry of specified descendant classes
|
8
|
-
#
|
9
|
-
# This is used by the setup
|
10
|
-
#
|
11
|
-
# @param [Hash] gateways
|
12
|
-
# @param [Array] relation_classes a list of relation descendants
|
13
|
-
#
|
14
|
-
# @api private
|
15
|
-
def initialize(gateways, relation_classes, mappers: EMPTY_HASH, plugins: EMPTY_ARRAY)
|
16
|
-
@gateways = gateways
|
17
|
-
@relation_classes = relation_classes
|
18
|
-
@mappers = mappers
|
19
|
-
@plugins = plugins
|
20
|
-
end
|
21
|
-
|
22
|
-
# @return [Hash]
|
23
|
-
#
|
24
|
-
# @api private
|
25
|
-
def run!
|
26
|
-
RelationRegistry.new do |registry, relations|
|
27
|
-
@relation_classes.each do |klass|
|
28
|
-
relation = build_relation(klass, registry)
|
29
|
-
|
30
|
-
key = relation.name.to_sym
|
31
|
-
|
32
|
-
if registry.key?(key)
|
33
|
-
raise RelationAlreadyDefinedError,
|
34
|
-
"Relation with `register_as #{key.inspect}` registered more " \
|
35
|
-
"than once"
|
36
|
-
end
|
37
|
-
|
38
|
-
relations[key] = relation
|
39
|
-
end
|
40
|
-
|
41
|
-
relations.each_value do |relation|
|
42
|
-
relation.class.finalize(registry, relation)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# @return [ROM::Relation]
|
48
|
-
#
|
49
|
-
# @api private
|
50
|
-
def build_relation(klass, registry)
|
51
|
-
# TODO: raise a meaningful error here and add spec covering the case
|
52
|
-
# where klass' gateway points to non-existant repo
|
53
|
-
gateway = @gateways.fetch(klass.gateway)
|
54
|
-
ds_proc = klass.dataset_proc || -> _ { self }
|
55
|
-
|
56
|
-
klass.schema(infer: true) unless klass.schema
|
57
|
-
schema = klass.schema.finalize!(gateway: gateway, relations: registry)
|
58
|
-
|
59
|
-
@plugins.each do |plugin|
|
60
|
-
plugin.apply_to(klass)
|
61
|
-
end
|
62
|
-
|
63
|
-
relname = klass.register_as
|
64
|
-
dataset = gateway.dataset(klass.schema.name.dataset).instance_exec(klass, &ds_proc)
|
65
|
-
mappers = @mappers.key?(relname) ? @mappers[relname] : MapperRegistry.new
|
66
|
-
|
67
|
-
options = {
|
68
|
-
__registry__: registry,
|
69
|
-
schema: schema.with(relations: registry),
|
70
|
-
mappers: mappers,
|
71
|
-
**plugin_options
|
72
|
-
}
|
73
|
-
|
74
|
-
klass.new(dataset, options)
|
75
|
-
end
|
76
|
-
|
77
|
-
# @api private
|
78
|
-
def plugin_options
|
79
|
-
@plugins.map(&:config).map(&:to_hash).reduce(:merge) || EMPTY_HASH
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
data/lib/rom/setup/finalize.rb
DELETED
@@ -1,152 +0,0 @@
|
|
1
|
-
require 'rom/relation'
|
2
|
-
require 'rom/command'
|
3
|
-
|
4
|
-
require 'rom/registry'
|
5
|
-
require 'rom/command_registry'
|
6
|
-
require 'rom/mapper_registry'
|
7
|
-
|
8
|
-
require 'rom/container'
|
9
|
-
require 'rom/setup/finalize/finalize_commands'
|
10
|
-
require 'rom/setup/finalize/finalize_relations'
|
11
|
-
require 'rom/setup/finalize/finalize_mappers'
|
12
|
-
|
13
|
-
# temporary
|
14
|
-
require 'rom/configuration_dsl/relation'
|
15
|
-
|
16
|
-
module ROM
|
17
|
-
# This giant builds an container using defined classes for core parts of ROM
|
18
|
-
#
|
19
|
-
# It is used by the setup object after it's done gathering class definitions
|
20
|
-
#
|
21
|
-
# @private
|
22
|
-
class Finalize
|
23
|
-
attr_reader :gateways, :repo_adapter, :datasets, :gateway_map,
|
24
|
-
:relation_classes, :mapper_classes, :mapper_objects, :command_classes, :plugins, :config
|
25
|
-
|
26
|
-
# @api private
|
27
|
-
def initialize(options)
|
28
|
-
@gateways = options.fetch(:gateways)
|
29
|
-
@gateway_map = options.fetch(:gateway_map)
|
30
|
-
|
31
|
-
@relation_classes = options.fetch(:relation_classes)
|
32
|
-
@command_classes = options.fetch(:command_classes)
|
33
|
-
|
34
|
-
mappers = options.fetch(:mappers, [])
|
35
|
-
@mapper_classes = mappers.select { |mapper| mapper.is_a?(Class) }
|
36
|
-
@mapper_objects = (mappers - @mapper_classes).reduce(:merge) || {}
|
37
|
-
|
38
|
-
@config = options.fetch(:config)
|
39
|
-
|
40
|
-
@plugins = options.fetch(:plugins)
|
41
|
-
|
42
|
-
initialize_datasets
|
43
|
-
end
|
44
|
-
|
45
|
-
# Return adapter identifier for a given gateway object
|
46
|
-
#
|
47
|
-
# @return [Symbol]
|
48
|
-
#
|
49
|
-
# @api private
|
50
|
-
def adapter_for(gateway)
|
51
|
-
@gateway_map.fetch(gateways[gateway])
|
52
|
-
end
|
53
|
-
|
54
|
-
# Run the finalization process
|
55
|
-
#
|
56
|
-
# This creates relations, mappers and commands
|
57
|
-
#
|
58
|
-
# @return [Container]
|
59
|
-
#
|
60
|
-
# @api private
|
61
|
-
def run!
|
62
|
-
infer_relations
|
63
|
-
|
64
|
-
mappers = load_mappers
|
65
|
-
relations = load_relations(mappers)
|
66
|
-
commands = load_commands(relations)
|
67
|
-
|
68
|
-
container = Container.new(gateways, relations, mappers, commands)
|
69
|
-
container.freeze
|
70
|
-
container
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
# Infer all datasets using configured gateways
|
76
|
-
#
|
77
|
-
# Not all gateways can do that, by default an empty array is returned
|
78
|
-
#
|
79
|
-
# @return [Hash] gateway name => array with datasets map
|
80
|
-
#
|
81
|
-
# @api private
|
82
|
-
def initialize_datasets
|
83
|
-
@datasets = gateways.each_with_object({}) do |(key, gateway), h|
|
84
|
-
infer_relations = config.gateways && config.gateways[key] && config.gateways[key][:infer_relations]
|
85
|
-
h[key] = gateway.schema if infer_relations
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# Build entire relation registry from all known relation subclasses
|
90
|
-
#
|
91
|
-
# This includes both classes created via DSL and explicit definitions
|
92
|
-
#
|
93
|
-
# @api private
|
94
|
-
def load_relations(mappers)
|
95
|
-
FinalizeRelations.new(
|
96
|
-
gateways,
|
97
|
-
relation_classes,
|
98
|
-
mappers: mappers, plugins: plugins.select(&:relation?)
|
99
|
-
).run!
|
100
|
-
end
|
101
|
-
|
102
|
-
# @api private
|
103
|
-
def load_mappers
|
104
|
-
FinalizeMappers.new(mapper_classes, mapper_objects).run!
|
105
|
-
end
|
106
|
-
|
107
|
-
# Build entire command registries
|
108
|
-
#
|
109
|
-
# This includes both classes created via DSL and explicit definitions
|
110
|
-
#
|
111
|
-
# @api private
|
112
|
-
def load_commands(relations)
|
113
|
-
FinalizeCommands.new(relations, gateways, command_classes).run!
|
114
|
-
end
|
115
|
-
|
116
|
-
# For every dataset infered from gateways we infer a relation
|
117
|
-
#
|
118
|
-
# Relations explicitly defined are being skipped
|
119
|
-
#
|
120
|
-
# @api private
|
121
|
-
def infer_relations
|
122
|
-
datasets.each do |gateway, schema|
|
123
|
-
schema.each do |name|
|
124
|
-
if infer_relation?(gateway, name)
|
125
|
-
klass = ROM::ConfigurationDSL::Relation.build_class(name, adapter: adapter_for(gateway))
|
126
|
-
klass.gateway(gateway)
|
127
|
-
klass.dataset(name, deprecation: false)
|
128
|
-
@relation_classes << klass
|
129
|
-
else
|
130
|
-
next
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def infer_relation?(gateway, name)
|
137
|
-
inferrable_relations(gateway).include?(name) && relation_classes.none? { |klass|
|
138
|
-
klass.dataset == name
|
139
|
-
}
|
140
|
-
end
|
141
|
-
|
142
|
-
def inferrable_relations(gateway)
|
143
|
-
gateway_config = config.gateways[gateway]
|
144
|
-
schema = gateways[gateway].schema
|
145
|
-
|
146
|
-
allowed = gateway_config[:inferrable_relations] || schema
|
147
|
-
skipped = gateway_config[:not_inferrable_relations] || []
|
148
|
-
|
149
|
-
schema & allowed - skipped
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
data/lib/rom/setup.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'rom/setup/auto_registration'
|
2
|
-
|
3
|
-
module ROM
|
4
|
-
class Setup
|
5
|
-
# @return [Array] registered relation subclasses
|
6
|
-
#
|
7
|
-
# @api private
|
8
|
-
attr_reader :relation_classes
|
9
|
-
|
10
|
-
# @return [Array] registered mapper subclasses
|
11
|
-
#
|
12
|
-
# @api private
|
13
|
-
attr_reader :mapper_classes
|
14
|
-
|
15
|
-
# @return [Array] registered command subclasses
|
16
|
-
#
|
17
|
-
# @api private
|
18
|
-
attr_reader :command_classes
|
19
|
-
|
20
|
-
|
21
|
-
# @api private
|
22
|
-
attr_reader :plugins
|
23
|
-
|
24
|
-
# @api private
|
25
|
-
def initialize
|
26
|
-
@relation_classes = []
|
27
|
-
@command_classes = []
|
28
|
-
@mapper_classes = []
|
29
|
-
@plugins = []
|
30
|
-
end
|
31
|
-
|
32
|
-
# Relation sub-classes are being registered with this method during setup
|
33
|
-
#
|
34
|
-
# @api private
|
35
|
-
def register_relation(*klasses)
|
36
|
-
klasses.reduce(@relation_classes, :<<)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Mapper sub-classes are being registered with this method during setup
|
40
|
-
#
|
41
|
-
# @api private
|
42
|
-
def register_mapper(*klasses)
|
43
|
-
klasses.reduce(@mapper_classes, :<<)
|
44
|
-
end
|
45
|
-
|
46
|
-
# Command sub-classes are being registered with this method during setup
|
47
|
-
#
|
48
|
-
# @api private
|
49
|
-
def register_command(*klasses)
|
50
|
-
klasses.reduce(@command_classes, :<<)
|
51
|
-
end
|
52
|
-
|
53
|
-
# @api private
|
54
|
-
def register_plugin(plugin)
|
55
|
-
plugins << plugin
|
56
|
-
end
|
57
|
-
|
58
|
-
def auto_registration(directory, options = {})
|
59
|
-
auto_registration = AutoRegistration.new(directory, options)
|
60
|
-
auto_registration.relations.map { |r| register_relation(r) }
|
61
|
-
auto_registration.commands.map { |r| register_command(r) }
|
62
|
-
auto_registration.mappers.map { |r| register_mapper(r) }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
module ROM
|
2
|
-
# @api private
|
3
|
-
module Configurable
|
4
|
-
class Config
|
5
|
-
WRITER_REGEXP = /=$/.freeze
|
6
|
-
|
7
|
-
attr_reader :settings
|
8
|
-
|
9
|
-
# @api private
|
10
|
-
def initialize(settings = {})
|
11
|
-
@settings = settings
|
12
|
-
end
|
13
|
-
|
14
|
-
# @api public
|
15
|
-
def [](name)
|
16
|
-
public_send(name)
|
17
|
-
end
|
18
|
-
|
19
|
-
# @api private
|
20
|
-
def key?(name)
|
21
|
-
settings.key?(name)
|
22
|
-
end
|
23
|
-
|
24
|
-
def to_hash
|
25
|
-
settings
|
26
|
-
end
|
27
|
-
|
28
|
-
# @api private
|
29
|
-
def freeze
|
30
|
-
settings.each_value(&:freeze)
|
31
|
-
super
|
32
|
-
end
|
33
|
-
|
34
|
-
# @api private
|
35
|
-
def respond_to_missing?(_name, _include_private = false)
|
36
|
-
true
|
37
|
-
end
|
38
|
-
|
39
|
-
def dup
|
40
|
-
self.class.new(dup_settings(settings))
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def dup_settings(settings)
|
46
|
-
settings.each_with_object({}) do |(key, value), new_settings|
|
47
|
-
if value.is_a?(self.class)
|
48
|
-
new_settings[key] = value.dup
|
49
|
-
else
|
50
|
-
new_settings[key] = value
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# @api private
|
56
|
-
def method_missing(meth, *args, &_block)
|
57
|
-
return settings.fetch(meth, nil) if frozen?
|
58
|
-
|
59
|
-
name = meth.to_s
|
60
|
-
key = name.gsub(WRITER_REGEXP, '').to_sym
|
61
|
-
|
62
|
-
if writer?(name)
|
63
|
-
settings[key] = args.first
|
64
|
-
else
|
65
|
-
settings.fetch(key) { settings[key] = self.class.new }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# @api private
|
70
|
-
def writer?(name)
|
71
|
-
!WRITER_REGEXP.match(name).nil?
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def config
|
76
|
-
@config ||= Config.new
|
77
|
-
end
|
78
|
-
|
79
|
-
# @api public
|
80
|
-
def configure
|
81
|
-
yield(config)
|
82
|
-
self
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
data/lib/rom/transaction.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module ROM
|
2
|
-
# @api private
|
3
|
-
class Transaction
|
4
|
-
# @api private
|
5
|
-
Rollback = Class.new(StandardError)
|
6
|
-
|
7
|
-
# @api private
|
8
|
-
def run(opts = EMPTY_HASH)
|
9
|
-
yield(self)
|
10
|
-
rescue Rollback
|
11
|
-
# noop
|
12
|
-
end
|
13
|
-
|
14
|
-
# Unconditionally roll back the current transaction
|
15
|
-
#
|
16
|
-
# @api public
|
17
|
-
def rollback!
|
18
|
-
raise Rollback
|
19
|
-
end
|
20
|
-
|
21
|
-
# @api private
|
22
|
-
NoOp = Transaction.new.freeze
|
23
|
-
end
|
24
|
-
end
|
data/lib/rom/types.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'dry-types'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
module ROM
|
5
|
-
module Types
|
6
|
-
include Dry::Types.module
|
7
|
-
|
8
|
-
def self.included(other)
|
9
|
-
other.extend(Methods)
|
10
|
-
super
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.Definition(primitive)
|
14
|
-
Dry::Types::Definition.new(primitive)
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.Constructor(primitive, &block)
|
18
|
-
Types.Definition(primitive).constructor(&block)
|
19
|
-
end
|
20
|
-
|
21
|
-
module Methods
|
22
|
-
def ForeignKey(relation, type = Types::Int)
|
23
|
-
type.meta(foreign_key: true, target: relation)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def Coercible.JSONHash(symbol_keys: false, type: Types::Hash)
|
28
|
-
Types.Constructor(type) do |value|
|
29
|
-
begin
|
30
|
-
::JSON.parse(value.to_s, symbolize_names: symbol_keys)
|
31
|
-
rescue ::JSON::ParserError
|
32
|
-
value
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def Coercible.HashJSON(type: Types::String)
|
38
|
-
Types.Constructor(type) { |value| ::JSON.dump(value) }
|
39
|
-
end
|
40
|
-
|
41
|
-
def Coercible.JSON(symbol_keys: false)
|
42
|
-
self.HashJSON.meta(read: self.JSONHash(symbol_keys: symbol_keys))
|
43
|
-
end
|
44
|
-
|
45
|
-
Coercible::JSON = Coercible.JSON
|
46
|
-
Coercible::JSONHash = Coercible.JSONHash
|
47
|
-
Coercible::HashJSON = Coercible.HashJSON
|
48
|
-
end
|
49
|
-
end
|
data/log/.gitkeep
DELETED
File without changes
|
data/rakelib/benchmark.rake
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
desc "Run benchmarks (tweak count via COUNT envvar)"
|
2
|
-
task :benchmark do
|
3
|
-
FileList["benchmarks/**/*_bench.rb"].each do |bench|
|
4
|
-
sh "ruby #{bench}"
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
namespace :benchmark do
|
9
|
-
desc "Verify benchmarks"
|
10
|
-
task :verify do
|
11
|
-
ENV['VERIFY'] = "true"
|
12
|
-
ENV['COUNT'] = "1"
|
13
|
-
Rake::Task[:benchmark].invoke
|
14
|
-
end
|
15
|
-
end
|
data/rakelib/mutant.rake
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
desc "Run mutant against a specific subject"
|
2
|
-
task :mutant do
|
3
|
-
subject = ARGV.last
|
4
|
-
if subject == 'mutant'
|
5
|
-
abort "usage: rake mutant SUBJECT\nexample: rake mutant ROM::Header"
|
6
|
-
else
|
7
|
-
sep = subject.include?('#') ? '#' : '.'
|
8
|
-
ns = subject.split(sep).first
|
9
|
-
|
10
|
-
opts = {
|
11
|
-
'include' => 'lib',
|
12
|
-
'require' => 'rom',
|
13
|
-
'use' => 'rspec',
|
14
|
-
'ignore-subject' => "#{ns}#respond_to_missing?"
|
15
|
-
}.to_a.map { |k, v| "--#{k} #{v}" }.join(' ')
|
16
|
-
|
17
|
-
exec("bundle exec mutant #{opts} #{subject}")
|
18
|
-
end
|
19
|
-
end
|
data/rakelib/rubocop.rake
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require "rubocop/rake_task"
|
3
|
-
|
4
|
-
Rake::Task[:default].enhance [:rubocop]
|
5
|
-
|
6
|
-
RuboCop::RakeTask.new do |task|
|
7
|
-
task.options << "--display-cop-names"
|
8
|
-
end
|
9
|
-
|
10
|
-
namespace :rubocop do
|
11
|
-
desc 'Generate a configuration file acting as a TODO list.'
|
12
|
-
task :auto_gen_config do
|
13
|
-
exec "bundle exec rubocop --auto-gen-config"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
rescue LoadError
|
18
|
-
end
|
data/rom.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require File.expand_path('../lib/rom/version', __FILE__)
|
2
|
-
|
3
|
-
Gem::Specification.new do |gem|
|
4
|
-
gem.name = 'rom'
|
5
|
-
gem.summary = 'Ruby Object Mapper'
|
6
|
-
gem.description = 'Persistence and mapping toolkit for Ruby'
|
7
|
-
gem.author = 'Piotr Solnica'
|
8
|
-
gem.email = 'piotr.solnica@gmail.com'
|
9
|
-
gem.homepage = 'http://rom-rb.org'
|
10
|
-
gem.require_paths = ['lib']
|
11
|
-
gem.version = ROM::VERSION.dup
|
12
|
-
gem.files = `git ls-files`.split("\n").reject { |name| name.include?('benchmarks') }
|
13
|
-
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
14
|
-
gem.license = 'MIT'
|
15
|
-
|
16
|
-
gem.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
|
17
|
-
gem.add_runtime_dependency 'dry-equalizer', '~> 0.2'
|
18
|
-
gem.add_runtime_dependency 'dry-types', '~> 0.9', '>= 0.9.4'
|
19
|
-
gem.add_runtime_dependency 'dry-core', '~> 0.3'
|
20
|
-
gem.add_runtime_dependency 'dry-initializer', '~> 1.3'
|
21
|
-
gem.add_runtime_dependency 'rom-mapper', '~> 0.5', '>= 0.5.1'
|
22
|
-
|
23
|
-
gem.add_development_dependency 'rake', '~> 10.3'
|
24
|
-
gem.add_development_dependency 'rspec', '~> 3.5'
|
25
|
-
end
|