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,206 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Mapper definition DSL' do
|
4
|
-
include_context 'container'
|
5
|
-
include_context 'users and tasks'
|
6
|
-
|
7
|
-
let(:header) { mapper.header }
|
8
|
-
|
9
|
-
before do
|
10
|
-
configuration.relation(:users) do
|
11
|
-
def email_index
|
12
|
-
project(:email)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'default PORO mapper' do
|
18
|
-
subject(:mapper) { container.mappers.users.entity }
|
19
|
-
|
20
|
-
before do
|
21
|
-
configuration.mappers do
|
22
|
-
define(:users) do
|
23
|
-
model name: 'Test::User'
|
24
|
-
|
25
|
-
register_as :entity
|
26
|
-
|
27
|
-
attribute :name
|
28
|
-
attribute :email
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'defines a constant for the model class' do
|
34
|
-
expect(mapper.model).to be(Test::User)
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'defines header with attributes' do
|
38
|
-
expect(header.keys).to eql([:name, :email])
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe 'excluding attributes' do
|
43
|
-
context 'by setting :inherit_header to false' do
|
44
|
-
subject(:mapper) { container.mappers.users.email_index }
|
45
|
-
|
46
|
-
before do
|
47
|
-
configuration.mappers do
|
48
|
-
define(:users) do
|
49
|
-
model name: 'Test::User'
|
50
|
-
|
51
|
-
attribute :name
|
52
|
-
attribute :email
|
53
|
-
end
|
54
|
-
|
55
|
-
define(:email_index, parent: :users, inherit_header: false) do
|
56
|
-
model name: 'Test::UserWithoutName'
|
57
|
-
attribute :email
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'only maps provided attributes' do
|
63
|
-
expect(header.keys).to eql([:email])
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe 'virtual relation mapper' do
|
69
|
-
subject(:mapper) { container.mappers.users.email_index }
|
70
|
-
|
71
|
-
before do
|
72
|
-
configuration.mappers do
|
73
|
-
define(:users) do
|
74
|
-
model name: 'Test::User'
|
75
|
-
|
76
|
-
attribute :name
|
77
|
-
attribute :email
|
78
|
-
end
|
79
|
-
|
80
|
-
define(:email_index, parent: :users) do
|
81
|
-
model name: 'Test::UserWithoutName'
|
82
|
-
exclude :name
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'inherits the attributes from the parent by default' do
|
88
|
-
expect(header.keys).to eql([:name, :email])
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'excludes an inherited attribute when requested' do
|
92
|
-
name = header.attributes[:name]
|
93
|
-
expect(name).to be_kind_of ROM::Header::Exclude
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'builds a new model' do
|
97
|
-
expect(mapper.model).to be(Test::UserWithoutName)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe 'wrapped relation mapper' do
|
102
|
-
before do
|
103
|
-
configuration.relation(:tasks) do
|
104
|
-
def with_user
|
105
|
-
join(users)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
configuration.mappers do
|
110
|
-
define(:tasks) do
|
111
|
-
model name: 'Test::Task'
|
112
|
-
|
113
|
-
attribute :title
|
114
|
-
attribute :priority
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'allows defining wrapped attributes via options hash' do
|
120
|
-
configuration.mappers do
|
121
|
-
define(:with_user, parent: :tasks) do
|
122
|
-
model name: 'Test::TaskWithUser'
|
123
|
-
|
124
|
-
attribute :title
|
125
|
-
attribute :priority
|
126
|
-
|
127
|
-
wrap user: [:email]
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
container
|
132
|
-
|
133
|
-
Test::TaskWithUser.send(:include, Dry::Equalizer(:title, :priority, :user))
|
134
|
-
|
135
|
-
jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
136
|
-
|
137
|
-
expect(jane).to eql(
|
138
|
-
Test::TaskWithUser.new(
|
139
|
-
title: 'be cool',
|
140
|
-
priority: 2,
|
141
|
-
user: { email: 'jane@doe.org' }
|
142
|
-
)
|
143
|
-
)
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'allows defining wrapped attributes via options block' do
|
147
|
-
configuration.mappers do
|
148
|
-
define(:with_user, parent: :tasks) do
|
149
|
-
model name: 'Test::TaskWithUser'
|
150
|
-
|
151
|
-
attribute :title
|
152
|
-
attribute :priority
|
153
|
-
|
154
|
-
wrap :user do
|
155
|
-
attribute :email
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
container
|
161
|
-
|
162
|
-
Test::TaskWithUser.send(:include, Dry::Equalizer(:title, :priority, :user))
|
163
|
-
|
164
|
-
jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
165
|
-
|
166
|
-
expect(jane).to eql(
|
167
|
-
Test::TaskWithUser.new(
|
168
|
-
title: 'be cool',
|
169
|
-
priority: 2,
|
170
|
-
user: { email: 'jane@doe.org' }
|
171
|
-
)
|
172
|
-
)
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'allows defining wrapped attributes mapped to a model' do
|
176
|
-
configuration.mappers do
|
177
|
-
define(:with_user, parent: :tasks) do
|
178
|
-
model name: 'Test::TaskWithUser'
|
179
|
-
|
180
|
-
attribute :title
|
181
|
-
attribute :priority
|
182
|
-
|
183
|
-
wrap :user do
|
184
|
-
model name: 'Test::User'
|
185
|
-
attribute :email
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
container
|
191
|
-
|
192
|
-
Test::TaskWithUser.send(:include, Dry::Equalizer(:title, :priority, :user))
|
193
|
-
Test::User.send(:include, Dry::Equalizer(:email))
|
194
|
-
|
195
|
-
jane = container.relation(:tasks).with_user.as(:with_user).to_a.last
|
196
|
-
|
197
|
-
expect(jane).to eql(
|
198
|
-
Test::TaskWithUser.new(
|
199
|
-
title: 'be cool',
|
200
|
-
priority: 2,
|
201
|
-
user: Test::User.new(email: 'jane@doe.org')
|
202
|
-
)
|
203
|
-
)
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rom/memory'
|
3
|
-
|
4
|
-
RSpec.describe 'Mappers / embedded' do
|
5
|
-
include_context 'container'
|
6
|
-
|
7
|
-
before do
|
8
|
-
configuration.relation(:users)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'allows mapping embedded tuples' do
|
12
|
-
configuration.mappers do
|
13
|
-
define(:users) do
|
14
|
-
model name: 'Test::User'
|
15
|
-
|
16
|
-
attribute :name, from: 'name'
|
17
|
-
|
18
|
-
embedded :tasks, from: 'tasks' do
|
19
|
-
attribute :title, from: 'title'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
container.relations.users << {
|
25
|
-
'name' => 'Jane',
|
26
|
-
'tasks' => [{ 'title' => 'Task One' }, { 'title' => 'Task Two' }]
|
27
|
-
}
|
28
|
-
|
29
|
-
jane = container.relation(:users).map_with(:users).first
|
30
|
-
|
31
|
-
expect(jane.name).to eql('Jane')
|
32
|
-
expect(jane.tasks).to eql([{ title: 'Task One' }, { title: 'Task Two' }])
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'allows mapping embedded tuple' do
|
36
|
-
configuration.mappers do
|
37
|
-
define(:users) do
|
38
|
-
model name: 'Test::User'
|
39
|
-
|
40
|
-
attribute :name, from: 'name'
|
41
|
-
|
42
|
-
embedded :address, from: 'address', type: :hash do
|
43
|
-
model name: 'Test::Address'
|
44
|
-
attribute :street, from: 'street'
|
45
|
-
attribute :city, from: 'city'
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
container.relations.users << {
|
51
|
-
'name' => 'Jane',
|
52
|
-
'address' => { 'street' => 'Somewhere 1', 'city' => 'NYC' }
|
53
|
-
}
|
54
|
-
|
55
|
-
jane = container.relation(:users).as(:users).first
|
56
|
-
|
57
|
-
Test::Address.send(:include, Dry::Equalizer(:street, :city))
|
58
|
-
|
59
|
-
expect(jane.name).to eql('Jane')
|
60
|
-
expect(jane.address).to eql(Test::Address.new(street: 'Somewhere 1', city: 'NYC'))
|
61
|
-
end
|
62
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rom/memory'
|
3
|
-
|
4
|
-
RSpec.describe 'Mapper definition DSL' do
|
5
|
-
include_context 'container'
|
6
|
-
|
7
|
-
before do
|
8
|
-
configuration.relation(:users)
|
9
|
-
|
10
|
-
users = configuration.default.dataset(:users)
|
11
|
-
|
12
|
-
users.insert(name: 'Joe', email: 'joe@doe.com')
|
13
|
-
users.insert(name: 'Jane', email: 'jane@doe.com')
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'exclude' do
|
17
|
-
let(:mapped_users) { container.relation(:users).as(:users).to_a }
|
18
|
-
|
19
|
-
it 'removes the attribute' do
|
20
|
-
configuration.mappers do
|
21
|
-
define(:users) { exclude :email }
|
22
|
-
end
|
23
|
-
|
24
|
-
expect(mapped_users).to eql [{ name: 'Joe' }, { name: 'Jane' }]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Mapper definition DSL' do
|
4
|
-
include_context 'container'
|
5
|
-
include_context 'users and tasks'
|
6
|
-
|
7
|
-
let(:header) { mapper.header }
|
8
|
-
|
9
|
-
describe 'folded relation mapper' do
|
10
|
-
before do
|
11
|
-
configuration.relation(:tasks) do
|
12
|
-
def with_users
|
13
|
-
join(users)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
configuration.relation(:users) do
|
18
|
-
def with_tasks
|
19
|
-
join(tasks)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
let(:container) { ROM.container(configuration) }
|
25
|
-
let(:actual) do
|
26
|
-
container.relation(:users).with_tasks.map_with(:users).to_a
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'groups all attributes and folds the first key' do
|
30
|
-
configuration.mappers do
|
31
|
-
define(:users) do
|
32
|
-
fold tasks: [:title, :priority]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
expect(actual).to eql [
|
37
|
-
{ name: 'Joe', email: 'joe@doe.org', tasks: ['be nice', 'sleep well'] },
|
38
|
-
{ name: 'Jane', email: 'jane@doe.org', tasks: ['be cool'] }
|
39
|
-
]
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'is sensitive to the order of keys' do
|
43
|
-
configuration.mappers do
|
44
|
-
define(:users) do
|
45
|
-
fold priorities: [:priority, :title]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
expect(actual).to eql [
|
50
|
-
{ name: 'Joe', email: 'joe@doe.org', priorities: [1, 2] },
|
51
|
-
{ name: 'Jane', email: 'jane@doe.org', priorities: [2] }
|
52
|
-
]
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'accepts the block syntax' do
|
56
|
-
configuration.mappers do
|
57
|
-
define(:users) do
|
58
|
-
fold :priorities do
|
59
|
-
attribute :priority
|
60
|
-
attribute :title
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
expect(actual).to eql [
|
66
|
-
{ name: 'Joe', email: 'joe@doe.org', priorities: [1, 2] },
|
67
|
-
{ name: 'Jane', email: 'jane@doe.org', priorities: [2] }
|
68
|
-
]
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,163 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Mapper definition DSL' do
|
4
|
-
include_context 'container'
|
5
|
-
include_context 'users and tasks'
|
6
|
-
|
7
|
-
let(:header) { mapper.header }
|
8
|
-
|
9
|
-
describe 'grouped relation mapper' do
|
10
|
-
before do
|
11
|
-
configuration.relation(:tasks) do
|
12
|
-
def with_users
|
13
|
-
join(users)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
configuration.relation(:users) do
|
18
|
-
def with_tasks
|
19
|
-
join(tasks)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
configuration.mappers do
|
24
|
-
define(:users) do
|
25
|
-
model name: 'Test::User'
|
26
|
-
|
27
|
-
attribute :name
|
28
|
-
attribute :email
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'allows defining grouped attributes via options hash' do
|
34
|
-
configuration.mappers do
|
35
|
-
define(:with_tasks, parent: :users) do
|
36
|
-
model name: 'Test::UserWithTasks'
|
37
|
-
|
38
|
-
attribute :name
|
39
|
-
attribute :email
|
40
|
-
|
41
|
-
group tasks: [:title, :priority]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
container
|
46
|
-
|
47
|
-
Test::UserWithTasks.send(:include, Dry::Equalizer(:name, :email, :tasks))
|
48
|
-
|
49
|
-
jane = container.relation(:users).with_tasks.map_with(:with_tasks).to_a.last
|
50
|
-
|
51
|
-
expect(jane).to eql(
|
52
|
-
Test::UserWithTasks.new(
|
53
|
-
name: 'Jane',
|
54
|
-
email: 'jane@doe.org',
|
55
|
-
tasks: [{ title: 'be cool', priority: 2 }]
|
56
|
-
)
|
57
|
-
)
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'allows defining grouped attributes via block' do
|
61
|
-
configuration.mappers do
|
62
|
-
define(:with_tasks, parent: :users) do
|
63
|
-
model name: 'Test::UserWithTasks'
|
64
|
-
|
65
|
-
attribute :name
|
66
|
-
attribute :email
|
67
|
-
|
68
|
-
group :tasks do
|
69
|
-
attribute :title
|
70
|
-
attribute :priority
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
container
|
76
|
-
|
77
|
-
Test::UserWithTasks.send(:include, Dry::Equalizer(:name, :email, :tasks))
|
78
|
-
|
79
|
-
jane = container.relation(:users).with_tasks.map_with(:with_tasks).to_a.last
|
80
|
-
|
81
|
-
expect(jane).to eql(
|
82
|
-
Test::UserWithTasks.new(
|
83
|
-
name: 'Jane',
|
84
|
-
email: 'jane@doe.org',
|
85
|
-
tasks: [{ title: 'be cool', priority: 2 }]
|
86
|
-
)
|
87
|
-
)
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'allows defining grouped attributes mapped to a model via block' do
|
91
|
-
configuration.mappers do
|
92
|
-
define(:with_tasks, parent: :users) do
|
93
|
-
model name: 'Test::UserWithTasks'
|
94
|
-
|
95
|
-
attribute :name
|
96
|
-
attribute :email
|
97
|
-
|
98
|
-
group :tasks do
|
99
|
-
model name: 'Test::Task'
|
100
|
-
|
101
|
-
attribute :title
|
102
|
-
attribute :priority
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
container
|
108
|
-
|
109
|
-
Test::UserWithTasks.send(:include, Dry::Equalizer(:name, :email, :tasks))
|
110
|
-
Test::Task.send(:include, Dry::Equalizer(:title, :priority))
|
111
|
-
|
112
|
-
jane = container.relation(:users).with_tasks.map_with(:with_tasks).to_a.last
|
113
|
-
|
114
|
-
expect(jane).to eql(
|
115
|
-
Test::UserWithTasks.new(
|
116
|
-
name: 'Jane',
|
117
|
-
email: 'jane@doe.org',
|
118
|
-
tasks: [Test::Task.new(title: 'be cool', priority: 2)]
|
119
|
-
)
|
120
|
-
)
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'allows defining nested grouped attributes mapped to a model via block' do
|
124
|
-
configuration.mappers do
|
125
|
-
define(:tasks)
|
126
|
-
|
127
|
-
define(:with_users, parent: :tasks, inherit_header: false) do
|
128
|
-
model name: 'Test::TaskWithUsers'
|
129
|
-
|
130
|
-
attribute :title
|
131
|
-
attribute :priority
|
132
|
-
|
133
|
-
group :users do
|
134
|
-
model name: 'Test::TaskUser'
|
135
|
-
|
136
|
-
attribute :name
|
137
|
-
|
138
|
-
group :contacts do
|
139
|
-
model name: 'Test::Contact'
|
140
|
-
attribute :email
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
container
|
147
|
-
|
148
|
-
Test::TaskWithUsers.send(:include, Dry::Equalizer(:title, :priority, :users))
|
149
|
-
Test::TaskUser.send(:include, Dry::Equalizer(:name, :contacts))
|
150
|
-
Test::Contact.send(:include, Dry::Equalizer(:email))
|
151
|
-
|
152
|
-
task = container.relation(:tasks).with_users.map_with(:with_users).first
|
153
|
-
|
154
|
-
expect(task).to eql(
|
155
|
-
Test::TaskWithUsers.new(title: 'be nice', priority: 1, users: [
|
156
|
-
Test::TaskUser.new(name: 'Joe', contacts: [
|
157
|
-
Test::Contact.new(email: 'joe@doe.org')
|
158
|
-
])
|
159
|
-
])
|
160
|
-
)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rom/memory'
|
3
|
-
|
4
|
-
RSpec.describe 'Mappers / Attributes value' do
|
5
|
-
include_context 'container'
|
6
|
-
|
7
|
-
before do
|
8
|
-
configuration.relation(:users)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'allows to manipulate attribute value' do
|
12
|
-
class Test::UserMapper < ROM::Mapper
|
13
|
-
relation :users
|
14
|
-
|
15
|
-
attribute :id
|
16
|
-
attribute :name, from: :first_name do
|
17
|
-
'John'
|
18
|
-
end
|
19
|
-
attribute :age do
|
20
|
-
9+9
|
21
|
-
end
|
22
|
-
attribute :weight do |t|
|
23
|
-
t+15
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
configuration.register_mapper(Test::UserMapper)
|
28
|
-
|
29
|
-
container.relations.users << {
|
30
|
-
id: 123,
|
31
|
-
first_name: 'Jane',
|
32
|
-
weight: 75
|
33
|
-
}
|
34
|
-
|
35
|
-
jane = container.relation(:users).as(:users).first
|
36
|
-
|
37
|
-
expect(jane).to eql(id: 123, name: 'John', weight: 90, age: 18)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'raise ArgumentError if type and block used at the same time' do
|
41
|
-
expect {
|
42
|
-
class Test::UserMapper < ROM::Mapper
|
43
|
-
relation :users
|
44
|
-
|
45
|
-
attribute :name, type: :string do
|
46
|
-
'John'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
}.to raise_error(ArgumentError, "can't specify type and block at the same time")
|
50
|
-
end
|
51
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rom/memory'
|
3
|
-
|
4
|
-
RSpec.describe 'Mapper definition DSL' do
|
5
|
-
include_context 'container'
|
6
|
-
|
7
|
-
before do
|
8
|
-
configuration.relation(:users)
|
9
|
-
|
10
|
-
users = configuration.default.dataset(:users)
|
11
|
-
users.insert(
|
12
|
-
user_id: 1,
|
13
|
-
user_name: 'Joe',
|
14
|
-
user_email: 'joe@doe.com',
|
15
|
-
'user.skype' => 'joe',
|
16
|
-
:'user.phone' => '1234567890'
|
17
|
-
)
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'prefix' do
|
21
|
-
subject(:mapped_users) { container.relation(:users).as(:users).to_a }
|
22
|
-
|
23
|
-
it 'applies new separator to the attributes following it' do
|
24
|
-
configuration.mappers do
|
25
|
-
define(:users) do
|
26
|
-
prefix :user
|
27
|
-
attribute :id
|
28
|
-
attribute :name
|
29
|
-
wrap :contacts do
|
30
|
-
attribute :email
|
31
|
-
|
32
|
-
prefix_separator '.'
|
33
|
-
attribute 'skype'
|
34
|
-
attribute :phone
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
expect(mapped_users).to eql [
|
40
|
-
{
|
41
|
-
id: 1,
|
42
|
-
name: 'Joe',
|
43
|
-
contacts: {
|
44
|
-
email: 'joe@doe.com',
|
45
|
-
'skype' => 'joe',
|
46
|
-
phone: '1234567890'
|
47
|
-
}
|
48
|
-
}
|
49
|
-
]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rom/memory'
|
3
|
-
|
4
|
-
RSpec.describe 'Mapper definition DSL' do
|
5
|
-
include_context 'container'
|
6
|
-
|
7
|
-
before do
|
8
|
-
configuration.relation(:users)
|
9
|
-
|
10
|
-
users = configuration.default.dataset(:users)
|
11
|
-
users.insert(
|
12
|
-
user_id: 1,
|
13
|
-
user_name: 'Joe',
|
14
|
-
user_email: 'joe@doe.com',
|
15
|
-
contact_skype: 'joe',
|
16
|
-
contact_phone: '1234567890'
|
17
|
-
)
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'prefix' do
|
21
|
-
subject(:mapped_users) { container.relation(:users).as(:users).to_a }
|
22
|
-
|
23
|
-
it 'applies new prefix to the attributes following it' do
|
24
|
-
configuration.mappers do
|
25
|
-
define(:users) do
|
26
|
-
prefix :user
|
27
|
-
attribute :id
|
28
|
-
attribute :name
|
29
|
-
wrap :contacts do
|
30
|
-
attribute :email
|
31
|
-
|
32
|
-
prefix :contact
|
33
|
-
attribute :skype
|
34
|
-
attribute :phone
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
expect(mapped_users).to eql [
|
40
|
-
{
|
41
|
-
id: 1,
|
42
|
-
name: 'Joe',
|
43
|
-
contacts: { email: 'joe@doe.com', skype: 'joe', phone: '1234567890' }
|
44
|
-
}
|
45
|
-
]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|