rom 2.0.2 → 4.2.1
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 +5 -5
- data/CHANGELOG.md +35 -430
- data/LICENSE +1 -1
- data/README.md +83 -11
- data/lib/rom/version.rb +1 -1
- data/lib/rom.rb +3 -46
- metadata +30 -236
- data/.gitignore +0 -24
- data/.rspec +0 -3
- data/.rubocop.yml +0 -87
- data/.rubocop_todo.yml +0 -46
- data/.travis.yml +0 -28
- data/CODE_OF_CONDUCT.md +0 -13
- data/CONTRIBUTING.md +0 -1
- data/Gemfile +0 -41
- data/Guardfile +0 -24
- data/Rakefile +0 -22
- data/lib/rom/association_set.rb +0 -26
- data/lib/rom/command.rb +0 -173
- data/lib/rom/command_registry.rb +0 -153
- data/lib/rom/commands/class_interface.rb +0 -148
- data/lib/rom/commands/composite.rb +0 -54
- 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 -103
- 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 -88
- data/lib/rom/configuration_dsl/command.rb +0 -43
- data/lib/rom/configuration_dsl/command_dsl.rb +0 -35
- data/lib/rom/configuration_dsl/mapper.rb +0 -37
- data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -44
- data/lib/rom/configuration_dsl/relation.rb +0 -26
- data/lib/rom/configuration_dsl.rb +0 -78
- data/lib/rom/configuration_plugin.rb +0 -17
- data/lib/rom/constants.rb +0 -30
- data/lib/rom/container.rb +0 -231
- data/lib/rom/create_container.rb +0 -61
- data/lib/rom/environment.rb +0 -70
- data/lib/rom/gateway.rb +0 -154
- data/lib/rom/global/plugin_dsl.rb +0 -49
- data/lib/rom/global.rb +0 -60
- data/lib/rom/lint/enumerable_dataset.rb +0 -54
- data/lib/rom/lint/gateway.rb +0 -94
- 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 -58
- data/lib/rom/memory/dataset.rb +0 -98
- data/lib/rom/memory/gateway.rb +0 -64
- data/lib/rom/memory/relation.rb +0 -49
- 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 -106
- data/lib/rom/plugin.rb +0 -17
- data/lib/rom/plugin_base.rb +0 -31
- 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 -17
- data/lib/rom/plugins/relation/key_inference.rb +0 -46
- data/lib/rom/plugins/relation/registry_reader.rb +0 -32
- data/lib/rom/plugins/relation/view/dsl.rb +0 -32
- data/lib/rom/plugins/relation/view.rb +0 -95
- data/lib/rom/relation/class_interface.rb +0 -230
- data/lib/rom/relation/composite.rb +0 -46
- data/lib/rom/relation/curried.rb +0 -104
- data/lib/rom/relation/graph.rb +0 -115
- data/lib/rom/relation/loaded.rb +0 -118
- data/lib/rom/relation/materializable.rb +0 -66
- data/lib/rom/relation/name.rb +0 -102
- data/lib/rom/relation.rb +0 -172
- data/lib/rom/relation_registry.rb +0 -9
- data/lib/rom/schema/dsl.rb +0 -58
- data/lib/rom/schema.rb +0 -89
- data/lib/rom/setup/auto_registration.rb +0 -69
- data/lib/rom/setup/auto_registration_strategies/base.rb +0 -11
- data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +0 -22
- data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +0 -19
- 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 -60
- data/lib/rom/setup/finalize.rb +0 -146
- data/lib/rom/setup.rb +0 -55
- data/lib/rom/support/configurable.rb +0 -80
- data/lib/rom/types.rb +0 -18
- 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 -26
- 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/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/integration/command_registry_spec.rb +0 -60
- data/spec/integration/commands/create_spec.rb +0 -177
- 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 -288
- data/spec/integration/commands/update_spec.rb +0 -109
- data/spec/integration/commands_spec.rb +0 -67
- 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/repositories/extending_relations_spec.rb +0 -58
- data/spec/integration/repositories/setting_logger_spec.rb +0 -34
- data/spec/integration/setup_spec.rb +0 -160
- data/spec/shared/command_behavior.rb +0 -28
- data/spec/shared/command_graph.rb +0 -50
- 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 -52
- data/spec/support/constant_leak_finder.rb +0 -14
- data/spec/support/mutant.rb +0 -10
- data/spec/support/types.rb +0 -5
- data/spec/test/memory_repository_lint_test.rb +0 -27
- data/spec/unit/rom/association_set_spec.rb +0 -23
- data/spec/unit/rom/commands/graph_spec.rb +0 -191
- data/spec/unit/rom/commands/lazy_spec.rb +0 -307
- data/spec/unit/rom/commands/result_spec.rb +0 -70
- data/spec/unit/rom/commands_spec.rb +0 -165
- 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 -99
- data/spec/unit/rom/create_container_spec.rb +0 -151
- 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/relation_spec.rb +0 -109
- data/spec/unit/rom/memory/repository_spec.rb +0 -12
- 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/key_inference_spec.rb +0 -85
- data/spec/unit/rom/plugins/relation/view_spec.rb +0 -51
- data/spec/unit/rom/relation/composite_spec.rb +0 -89
- data/spec/unit/rom/relation/curried_spec.rb +0 -52
- data/spec/unit/rom/relation/graph_spec.rb +0 -92
- data/spec/unit/rom/relation/lazy/combine_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/schema_spec.rb +0 -117
- data/spec/unit/rom/relation_spec.rb +0 -237
- data/spec/unit/rom/schema_spec.rb +0 -10
- data/spec/unit/rom/setup/auto_registration_spec.rb +0 -152
data/lib/rom/relation/name.rb
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
require 'dry/equalizer'
|
|
2
|
-
require 'concurrent/map'
|
|
3
|
-
|
|
4
|
-
module ROM
|
|
5
|
-
class Relation
|
|
6
|
-
# Relation name container
|
|
7
|
-
#
|
|
8
|
-
# This is a simple struct with two fields.
|
|
9
|
-
# It handles both relation registration name (i.e. Symbol) and dataset name.
|
|
10
|
-
# The reason we need it is a simplification of passing around these two objects.
|
|
11
|
-
# It is quite common to have a dataset named differently from a relation
|
|
12
|
-
# built on top if you are dealing with a legacy DB and often you need both
|
|
13
|
-
# to support things such as associations (rom-sql as an example).
|
|
14
|
-
#
|
|
15
|
-
# @api private
|
|
16
|
-
class Name
|
|
17
|
-
include Dry::Equalizer(:relation, :dataset)
|
|
18
|
-
|
|
19
|
-
# Coerce an object to a Name instance
|
|
20
|
-
#
|
|
21
|
-
# @return [ROM::Relation::Name]
|
|
22
|
-
#
|
|
23
|
-
# @api private
|
|
24
|
-
def self.[](*args)
|
|
25
|
-
cache.fetch_or_store(args.hash) do
|
|
26
|
-
relation, dataset = args
|
|
27
|
-
|
|
28
|
-
if relation.is_a?(Name)
|
|
29
|
-
relation
|
|
30
|
-
else
|
|
31
|
-
new(relation, dataset)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# @api private
|
|
37
|
-
def self.cache
|
|
38
|
-
@cache ||= Concurrent::Map.new
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# Relation registration name
|
|
42
|
-
#
|
|
43
|
-
# @return [Symbol]
|
|
44
|
-
#
|
|
45
|
-
# @api private
|
|
46
|
-
attr_reader :relation
|
|
47
|
-
|
|
48
|
-
# Underlying dataset name
|
|
49
|
-
#
|
|
50
|
-
# @return [Symbol]
|
|
51
|
-
#
|
|
52
|
-
# @api private
|
|
53
|
-
attr_reader :dataset
|
|
54
|
-
|
|
55
|
-
# @api private
|
|
56
|
-
def initialize(relation, dataset = nil)
|
|
57
|
-
@relation = relation
|
|
58
|
-
@dataset = dataset || relation
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# Return relation name
|
|
62
|
-
#
|
|
63
|
-
# @return [String]
|
|
64
|
-
#
|
|
65
|
-
# @api private
|
|
66
|
-
def to_s
|
|
67
|
-
if relation == dataset
|
|
68
|
-
relation.to_s
|
|
69
|
-
else
|
|
70
|
-
"#{relation} on #{dataset}"
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# Alias for registration key implicitly called by ROM::Registry
|
|
75
|
-
#
|
|
76
|
-
# @return [Symbol]
|
|
77
|
-
#
|
|
78
|
-
# @api private
|
|
79
|
-
def to_sym
|
|
80
|
-
relation
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
# Return inspected relation
|
|
84
|
-
#
|
|
85
|
-
# @return [String]
|
|
86
|
-
#
|
|
87
|
-
# @api private
|
|
88
|
-
def inspect
|
|
89
|
-
"#{self.class.name}(#{to_s})"
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
# Build a new name. Useful for Curried and other relation proxies
|
|
93
|
-
#
|
|
94
|
-
# @return [ROM::Relation::Name]
|
|
95
|
-
#
|
|
96
|
-
# @api private
|
|
97
|
-
def with(relation)
|
|
98
|
-
self.class[relation, dataset]
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
data/lib/rom/relation.rb
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
require 'rom/relation/class_interface'
|
|
2
|
-
|
|
3
|
-
require 'rom/pipeline'
|
|
4
|
-
require 'rom/mapper_registry'
|
|
5
|
-
|
|
6
|
-
require 'rom/relation/loaded'
|
|
7
|
-
require 'rom/relation/curried'
|
|
8
|
-
require 'rom/relation/composite'
|
|
9
|
-
require 'rom/relation/graph'
|
|
10
|
-
require 'rom/relation/materializable'
|
|
11
|
-
require 'rom/association_set'
|
|
12
|
-
|
|
13
|
-
require 'rom/types'
|
|
14
|
-
require 'rom/schema'
|
|
15
|
-
|
|
16
|
-
module ROM
|
|
17
|
-
# Base relation class
|
|
18
|
-
#
|
|
19
|
-
# Relation is a proxy for the dataset object provided by the gateway. It
|
|
20
|
-
# forwards every method to the dataset, which is why the "native" interface of
|
|
21
|
-
# the underlying gateway is available in the relation. This interface,
|
|
22
|
-
# however, is considered private and should not be used outside of the
|
|
23
|
-
# relation instance.
|
|
24
|
-
#
|
|
25
|
-
# ROM builds sub-classes of this class for every relation defined in the
|
|
26
|
-
# environment for easy inspection and extensibility - every gateway can
|
|
27
|
-
# provide extensions for those sub-classes but there is always a vanilla
|
|
28
|
-
# relation instance stored in the schema registry.
|
|
29
|
-
#
|
|
30
|
-
# @api public
|
|
31
|
-
class Relation
|
|
32
|
-
extend ClassInterface
|
|
33
|
-
|
|
34
|
-
include Options
|
|
35
|
-
include Dry::Equalizer(:dataset)
|
|
36
|
-
include Materializable
|
|
37
|
-
include Pipeline
|
|
38
|
-
|
|
39
|
-
# @!attribute [r] mappers
|
|
40
|
-
# @return [MapperRegistry] an optional mapper registry (empty by default)
|
|
41
|
-
option :mappers, reader: true, default: proc { MapperRegistry.new }
|
|
42
|
-
|
|
43
|
-
# @!attribute [r] schema_hash
|
|
44
|
-
# @return [Object#[]] tuple processing function, uses schema or defaults to Hash[]
|
|
45
|
-
# @api private
|
|
46
|
-
option :schema_hash, reader: true, default: -> relation {
|
|
47
|
-
relation.schema? ? Types::Coercible::Hash.schema(relation.schema.to_h) : Hash
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
# @!attribute [r] associations
|
|
51
|
-
# @return [AssociationSet] Schema's association set (empty by default)
|
|
52
|
-
option :associations, reader: true, default: -> rel {
|
|
53
|
-
rel.schema? ? rel.schema.associations : Schema::EMPTY_ASSOCIATION_SET
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
# @!attribute [r] dataset
|
|
57
|
-
# @return [Object] dataset used by the relation provided by relation's gateway
|
|
58
|
-
# @api public
|
|
59
|
-
attr_reader :dataset
|
|
60
|
-
|
|
61
|
-
# @!attribute [r] schema
|
|
62
|
-
# @return [Schema] returns relation schema object (if defined)
|
|
63
|
-
# @api public
|
|
64
|
-
attr_reader :schema
|
|
65
|
-
|
|
66
|
-
# Initializes a relation object
|
|
67
|
-
#
|
|
68
|
-
# @param dataset [Object]
|
|
69
|
-
#
|
|
70
|
-
# @param options [Hash]
|
|
71
|
-
# @option :mappers [MapperRegistry]
|
|
72
|
-
# @option :schema_hash [#[]]
|
|
73
|
-
# @option :associations [AssociationSet]
|
|
74
|
-
#
|
|
75
|
-
# @api public
|
|
76
|
-
def initialize(dataset, options = EMPTY_HASH)
|
|
77
|
-
@dataset = dataset
|
|
78
|
-
@schema = self.class.schema
|
|
79
|
-
super
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# Yields relation tuples
|
|
83
|
-
#
|
|
84
|
-
# @yield [Hash]
|
|
85
|
-
# @return [Enumerator] if block is not provided
|
|
86
|
-
#
|
|
87
|
-
# @api public
|
|
88
|
-
def each(&block)
|
|
89
|
-
return to_enum unless block
|
|
90
|
-
dataset.each { |tuple| yield(tuple) }
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# Composes with other relations
|
|
94
|
-
#
|
|
95
|
-
# @param *others [Array<Relation>] The other relation(s) to compose with
|
|
96
|
-
#
|
|
97
|
-
# @return [Relation::Graph]
|
|
98
|
-
#
|
|
99
|
-
# @api public
|
|
100
|
-
def combine(*others)
|
|
101
|
-
Graph.build(self, others)
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
# Loads relation
|
|
105
|
-
#
|
|
106
|
-
# @return [Relation::Loaded]
|
|
107
|
-
#
|
|
108
|
-
# @api public
|
|
109
|
-
def call
|
|
110
|
-
Loaded.new(self)
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
# Materializes a relation into an array
|
|
114
|
-
#
|
|
115
|
-
# @return [Array<Hash>]
|
|
116
|
-
#
|
|
117
|
-
# @api public
|
|
118
|
-
def to_a
|
|
119
|
-
to_enum.to_a
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
# Returns if this relation is curried
|
|
123
|
-
#
|
|
124
|
-
# @return [false]
|
|
125
|
-
#
|
|
126
|
-
# @api private
|
|
127
|
-
def curried?
|
|
128
|
-
false
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
# Returns if this relation is a graph
|
|
132
|
-
#
|
|
133
|
-
# @return [false]
|
|
134
|
-
#
|
|
135
|
-
# @api private
|
|
136
|
-
def graph?
|
|
137
|
-
false
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
# Returns true if a relation has schema defined
|
|
141
|
-
#
|
|
142
|
-
# @return [TrueClass, FalseClass]
|
|
143
|
-
#
|
|
144
|
-
# @api private
|
|
145
|
-
def schema?
|
|
146
|
-
! schema.nil?
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
# Returns a new instance with the same dataset but new options
|
|
150
|
-
#
|
|
151
|
-
# @param new_options [Hash]
|
|
152
|
-
#
|
|
153
|
-
# @return [Relation]
|
|
154
|
-
#
|
|
155
|
-
# @api private
|
|
156
|
-
def with(new_options)
|
|
157
|
-
__new__(dataset, options.merge(new_options))
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
private
|
|
161
|
-
|
|
162
|
-
# @api private
|
|
163
|
-
def __new__(dataset, new_opts = EMPTY_HASH)
|
|
164
|
-
self.class.new(dataset, options.merge(new_opts))
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
# @api private
|
|
168
|
-
def composite_class
|
|
169
|
-
Relation::Composite
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
end
|
data/lib/rom/schema/dsl.rb
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
require 'dry-equalizer'
|
|
2
|
-
require 'rom/types'
|
|
3
|
-
|
|
4
|
-
module ROM
|
|
5
|
-
# Relation schema
|
|
6
|
-
#
|
|
7
|
-
# @api public
|
|
8
|
-
class Schema
|
|
9
|
-
include Dry::Equalizer(:name, :attributes)
|
|
10
|
-
include Enumerable
|
|
11
|
-
|
|
12
|
-
attr_reader :name, :attributes, :inferrer
|
|
13
|
-
|
|
14
|
-
# @api public
|
|
15
|
-
class DSL < BasicObject
|
|
16
|
-
attr_reader :name, :attributes, :inferrer
|
|
17
|
-
|
|
18
|
-
# @api private
|
|
19
|
-
def initialize(name, inferrer, &block)
|
|
20
|
-
@name = name
|
|
21
|
-
@inferrer = inferrer
|
|
22
|
-
@attributes = nil
|
|
23
|
-
|
|
24
|
-
if block
|
|
25
|
-
instance_exec(&block)
|
|
26
|
-
elsif inferrer.nil?
|
|
27
|
-
raise ArgumentError,
|
|
28
|
-
'You must pass a block to define a schema or set an inferrer for automatic inferring'
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# Defines a relation attribute with its type
|
|
33
|
-
#
|
|
34
|
-
# @see Relation.schema
|
|
35
|
-
#
|
|
36
|
-
# @api public
|
|
37
|
-
def attribute(name, type)
|
|
38
|
-
@attributes ||= {}
|
|
39
|
-
@attributes[name] = type.meta(name: name)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Specify which key(s) should be the primary key
|
|
43
|
-
#
|
|
44
|
-
# @api public
|
|
45
|
-
def primary_key(*names)
|
|
46
|
-
names.each do |name|
|
|
47
|
-
attributes[name] = attributes[name].meta(primary_key: true)
|
|
48
|
-
end
|
|
49
|
-
self
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# @api private
|
|
53
|
-
def call
|
|
54
|
-
Schema.new(name, attributes, inferrer: inferrer)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
data/lib/rom/schema.rb
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
require 'dry-equalizer'
|
|
2
|
-
|
|
3
|
-
require 'rom/support/constants'
|
|
4
|
-
require 'rom/schema/dsl'
|
|
5
|
-
require 'rom/association_set'
|
|
6
|
-
|
|
7
|
-
module ROM
|
|
8
|
-
# Relation schema
|
|
9
|
-
#
|
|
10
|
-
# @api public
|
|
11
|
-
class Schema
|
|
12
|
-
EMPTY_ASSOCIATION_SET = AssociationSet.new(EMPTY_HASH).freeze
|
|
13
|
-
|
|
14
|
-
include Dry::Equalizer(:name, :attributes, :associations)
|
|
15
|
-
include Enumerable
|
|
16
|
-
|
|
17
|
-
# @!attribute [r] name
|
|
18
|
-
# @return [Symbol] The name of this schema
|
|
19
|
-
attr_reader :name
|
|
20
|
-
|
|
21
|
-
# @!attribute [r] attributes
|
|
22
|
-
# @return [Hash] The hash with schema attribute types
|
|
23
|
-
attr_reader :attributes
|
|
24
|
-
|
|
25
|
-
# @!attribute [r] associations
|
|
26
|
-
# @return [AssociationSet] Optional association set (this is adapter-specific)
|
|
27
|
-
attr_reader :associations
|
|
28
|
-
|
|
29
|
-
# @!attribute [r] inferrer
|
|
30
|
-
# @return [#call] An optional inferrer object used in `finalize!`
|
|
31
|
-
attr_reader :inferrer
|
|
32
|
-
|
|
33
|
-
# @!attribute [r] primary_key
|
|
34
|
-
# @return [Array<Dry::Types::Definition] Primary key array
|
|
35
|
-
attr_reader :primary_key
|
|
36
|
-
|
|
37
|
-
alias_method :to_h, :attributes
|
|
38
|
-
|
|
39
|
-
# @api private
|
|
40
|
-
def initialize(name, attributes, inferrer: nil, associations: EMPTY_ASSOCIATION_SET)
|
|
41
|
-
@name = name
|
|
42
|
-
@attributes = attributes
|
|
43
|
-
@associations = associations
|
|
44
|
-
@inferrer = inferrer
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# Iterate over schema's attributes
|
|
48
|
-
#
|
|
49
|
-
# @yield [Dry::Data::Type]
|
|
50
|
-
#
|
|
51
|
-
# @api public
|
|
52
|
-
def each(&block)
|
|
53
|
-
attributes.each_value(&block)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# Return attribute
|
|
57
|
-
#
|
|
58
|
-
# @api public
|
|
59
|
-
def [](name)
|
|
60
|
-
attributes.fetch(name)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# Return FK attribute for a given relation name
|
|
64
|
-
#
|
|
65
|
-
# @return [Dry::Types::Definition]
|
|
66
|
-
#
|
|
67
|
-
# @api public
|
|
68
|
-
def foreign_key(relation)
|
|
69
|
-
detect { |attr| attr.meta[:foreign_key] && attr.meta[:relation] == relation }
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
# This hook is called when relation is being build during container finalization
|
|
73
|
-
#
|
|
74
|
-
# When block is provided it'll be called just before freezing the instance
|
|
75
|
-
# so that additional ivars can be set
|
|
76
|
-
#
|
|
77
|
-
# @return [self]
|
|
78
|
-
#
|
|
79
|
-
# @api private
|
|
80
|
-
def finalize!(gateway = nil, &block)
|
|
81
|
-
return self if frozen?
|
|
82
|
-
|
|
83
|
-
@attributes = inferrer.call(name.dataset, gateway) if inferrer
|
|
84
|
-
@primary_key = select { |attr| attr.meta[:primary_key] == true }
|
|
85
|
-
block.call if block
|
|
86
|
-
freeze
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
require 'pathname'
|
|
2
|
-
|
|
3
|
-
require 'rom/support/constants'
|
|
4
|
-
require 'rom/support/inflector'
|
|
5
|
-
require 'rom/support/options'
|
|
6
|
-
|
|
7
|
-
require 'rom/setup/auto_registration_strategies/no_namespace'
|
|
8
|
-
require 'rom/setup/auto_registration_strategies/with_namespace'
|
|
9
|
-
require 'rom/setup/auto_registration_strategies/custom_namespace'
|
|
10
|
-
|
|
11
|
-
module ROM
|
|
12
|
-
class AutoRegistration
|
|
13
|
-
include Options
|
|
14
|
-
|
|
15
|
-
option :namespace, reader: true, type: [TrueClass, FalseClass, String], default: true
|
|
16
|
-
|
|
17
|
-
option :component_dirs, reader: true, type: ::Hash, default: {
|
|
18
|
-
relations: :relations,
|
|
19
|
-
mappers: :mappers,
|
|
20
|
-
commands: :commands
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
attr_reader :globs, :directory
|
|
24
|
-
|
|
25
|
-
def initialize(directory, options = EMPTY_HASH)
|
|
26
|
-
super
|
|
27
|
-
@directory = Pathname(directory)
|
|
28
|
-
@globs = Hash[component_dirs.map { |component, directory|
|
|
29
|
-
[component, @directory.join("#{directory}/**/*.rb")]
|
|
30
|
-
}]
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def relations
|
|
34
|
-
load_entities(:relations)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def commands
|
|
38
|
-
load_entities(:commands)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def mappers
|
|
42
|
-
load_entities(:mappers)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
private
|
|
46
|
-
|
|
47
|
-
def load_entities(entity)
|
|
48
|
-
Dir[globs[entity]].map do |file|
|
|
49
|
-
require file
|
|
50
|
-
klass_name =
|
|
51
|
-
case namespace
|
|
52
|
-
when String
|
|
53
|
-
AutoRegistrationStrategies::CustomNamespace.new(
|
|
54
|
-
namespace: namespace, file: file
|
|
55
|
-
).call
|
|
56
|
-
when TrueClass
|
|
57
|
-
AutoRegistrationStrategies::WithNamespace.new(
|
|
58
|
-
file: file, directory: directory
|
|
59
|
-
).call
|
|
60
|
-
when FalseClass
|
|
61
|
-
AutoRegistrationStrategies::NoNamespace.new(
|
|
62
|
-
file: file, directory: directory, entity: component_dirs.fetch(entity)
|
|
63
|
-
).call
|
|
64
|
-
end
|
|
65
|
-
Inflector.constantize(klass_name)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require 'pathname'
|
|
2
|
-
|
|
3
|
-
require 'rom/support/inflector'
|
|
4
|
-
require 'rom/setup/auto_registration_strategies/base'
|
|
5
|
-
|
|
6
|
-
module ROM
|
|
7
|
-
module AutoRegistrationStrategies
|
|
8
|
-
class CustomNamespace < Base
|
|
9
|
-
option :namespace, reader: true, type: String
|
|
10
|
-
|
|
11
|
-
def call
|
|
12
|
-
"#{namespace}::#{Inflector.camelize(filename)}"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
def filename
|
|
18
|
-
Pathname(file).basename('.rb')
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require 'pathname'
|
|
2
|
-
|
|
3
|
-
require 'rom/support/inflector'
|
|
4
|
-
require 'rom/setup/auto_registration_strategies/base'
|
|
5
|
-
|
|
6
|
-
module ROM
|
|
7
|
-
module AutoRegistrationStrategies
|
|
8
|
-
class NoNamespace < Base
|
|
9
|
-
option :directory, reader: true, type: Pathname
|
|
10
|
-
option :entity, reader: true, type: Symbol
|
|
11
|
-
|
|
12
|
-
def call
|
|
13
|
-
Inflector.camelize(
|
|
14
|
-
file.sub(/^#{directory}\/#{entity}\//, '').sub(EXTENSION_REGEX, '')
|
|
15
|
-
)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require 'pathname'
|
|
2
|
-
|
|
3
|
-
require 'rom/support/inflector'
|
|
4
|
-
require 'rom/setup/auto_registration_strategies/base'
|
|
5
|
-
|
|
6
|
-
module ROM
|
|
7
|
-
module AutoRegistrationStrategies
|
|
8
|
-
class WithNamespace < Base
|
|
9
|
-
option :directory, reader: true, type: Pathname
|
|
10
|
-
|
|
11
|
-
def call
|
|
12
|
-
Inflector.camelize(
|
|
13
|
-
file.sub(/^#{directory.dirname}\//, '').sub(EXTENSION_REGEX, '')
|
|
14
|
-
)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
require 'rom/support/registry'
|
|
2
|
-
require 'rom/command_registry'
|
|
3
|
-
|
|
4
|
-
module ROM
|
|
5
|
-
class Finalize
|
|
6
|
-
class FinalizeCommands
|
|
7
|
-
# Build command registry hash for provided relations
|
|
8
|
-
#
|
|
9
|
-
# @param [RelationRegistry] relations registry
|
|
10
|
-
# @param [Hash] gateways
|
|
11
|
-
# @param [Array] command_classes a list of command subclasses
|
|
12
|
-
#
|
|
13
|
-
# @api private
|
|
14
|
-
def initialize(relations, gateways, command_classes)
|
|
15
|
-
@relations = relations
|
|
16
|
-
@gateways = gateways
|
|
17
|
-
@command_classes = command_classes
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# @return [Hash]
|
|
21
|
-
#
|
|
22
|
-
# @api private
|
|
23
|
-
def run!
|
|
24
|
-
registry = @command_classes.each_with_object({}) do |klass, h|
|
|
25
|
-
rel_name = klass.relation
|
|
26
|
-
next unless rel_name
|
|
27
|
-
|
|
28
|
-
relation = @relations[rel_name]
|
|
29
|
-
name = klass.register_as || klass.default_name
|
|
30
|
-
|
|
31
|
-
gateway = @gateways[relation.class.gateway]
|
|
32
|
-
gateway.extend_command_class(klass, relation.dataset)
|
|
33
|
-
|
|
34
|
-
klass.extend_for_relation(relation) if klass.restrictable
|
|
35
|
-
|
|
36
|
-
(h[rel_name] ||= {})[name] = klass.build(relation)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
commands = registry.each_with_object({}) do |(name, rel_commands), h|
|
|
40
|
-
h[name] = CommandRegistry.new(name, rel_commands)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
Registry.new(commands)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
require 'rom/support/registry'
|
|
2
|
-
|
|
3
|
-
module ROM
|
|
4
|
-
class Finalize
|
|
5
|
-
class FinalizeMappers
|
|
6
|
-
# @api private
|
|
7
|
-
def initialize(mapper_classes, mapper_objects)
|
|
8
|
-
@mapper_classes = mapper_classes
|
|
9
|
-
@mapper_objects = mapper_objects
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# @api private
|
|
13
|
-
def run!
|
|
14
|
-
registry = @mapper_classes.each_with_object({}) do |klass, h|
|
|
15
|
-
name = klass.register_as || klass.relation
|
|
16
|
-
(h[klass.base_relation] ||= {})[name] = klass.build
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
registry_hash = registry.each_with_object({}).each { |(relation, mappers), h|
|
|
20
|
-
h[relation] = MapperRegistry.new(mappers)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@mapper_objects.each do |relation, mappers|
|
|
24
|
-
if registry_hash.key?(relation)
|
|
25
|
-
mappers_registry = registry_hash[relation]
|
|
26
|
-
mappers.each { |name, mapper| mappers_registry[name] = mapper }
|
|
27
|
-
else
|
|
28
|
-
registry_hash[relation] = MapperRegistry.new(mappers)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
Registry.new(registry_hash)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|