rom 2.0.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -7
- data/.yardopts +2 -0
- data/CHANGELOG.md +35 -1
- data/Gemfile +17 -2
- data/Rakefile +7 -2
- data/lib/rom/array_dataset.rb +44 -0
- data/lib/rom/association_set.rb +11 -5
- data/lib/rom/auto_curry.rb +55 -0
- data/lib/rom/command.rb +331 -47
- data/lib/rom/command_registry.rb +7 -18
- data/lib/rom/commands/class_interface.rb +120 -6
- data/lib/rom/commands/composite.rb +0 -1
- data/lib/rom/commands/graph.rb +7 -15
- data/lib/rom/commands/lazy/update.rb +1 -1
- data/lib/rom/configuration.rb +2 -0
- data/lib/rom/configuration_dsl/command.rb +6 -8
- data/lib/rom/configuration_dsl/mapper.rb +2 -3
- data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -1
- data/lib/rom/configuration_dsl/relation.rb +4 -4
- data/lib/rom/configuration_dsl.rb +0 -4
- data/lib/rom/constants.rb +7 -1
- data/lib/rom/container.rb +11 -17
- data/lib/rom/create_container.rb +0 -2
- data/lib/rom/data_proxy.rb +94 -0
- data/lib/rom/enumerable_dataset.rb +68 -0
- data/lib/rom/gateway.rb +74 -32
- data/lib/rom/global/plugin_dsl.rb +0 -2
- data/lib/rom/global.rb +0 -2
- data/lib/rom/initializer.rb +26 -0
- data/lib/rom/lint/gateway.rb +17 -0
- data/lib/rom/mapper_registry.rb +1 -1
- data/lib/rom/memory/commands.rb +0 -2
- data/lib/rom/memory/dataset.rb +1 -2
- data/lib/rom/memory/relation.rb +14 -1
- data/lib/rom/memory/schema.rb +13 -0
- data/lib/rom/plugin_registry.rb +1 -1
- data/lib/rom/plugins/command/schema.rb +2 -2
- data/lib/rom/plugins/configuration/configuration_dsl.rb +6 -2
- data/lib/rom/plugins/relation/key_inference.rb +4 -2
- data/lib/rom/plugins/relation/registry_reader.rb +5 -1
- data/lib/rom/registry.rb +50 -0
- data/lib/rom/relation/class_interface.rb +142 -30
- data/lib/rom/relation/curried.rb +15 -15
- data/lib/rom/relation/view_dsl.rb +31 -0
- data/lib/rom/relation.rb +101 -41
- data/lib/rom/schema/attribute.rb +367 -0
- data/lib/rom/schema/dsl.rb +14 -10
- data/lib/rom/schema.rb +337 -19
- data/lib/rom/setup/auto_registration.rb +20 -17
- data/lib/rom/setup/auto_registration_strategies/base.rb +8 -3
- data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +4 -3
- data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +5 -4
- data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +3 -3
- data/lib/rom/setup/finalize/finalize_commands.rb +1 -1
- data/lib/rom/setup/finalize/finalize_mappers.rb +1 -1
- data/lib/rom/setup/finalize/finalize_relations.rb +4 -2
- data/lib/rom/setup/finalize.rb +1 -1
- data/lib/rom/transaction.rb +24 -0
- data/lib/rom/types.rb +9 -1
- data/lib/rom/version.rb +1 -1
- data/lib/rom.rb +4 -8
- data/rom.gemspec +5 -4
- data/spec/integration/command_registry_spec.rb +1 -14
- data/spec/integration/commands/create_spec.rb +5 -25
- data/spec/integration/commands/delete_spec.rb +1 -1
- data/spec/integration/commands/error_handling_spec.rb +1 -1
- data/spec/integration/commands/graph_spec.rb +20 -14
- data/spec/integration/commands/update_spec.rb +4 -27
- data/spec/integration/commands_spec.rb +1 -1
- data/spec/integration/{repositories → gateways}/extending_relations_spec.rb +1 -1
- data/spec/integration/{repositories → gateways}/setting_logger_spec.rb +2 -2
- data/spec/integration/mappers/combine_spec.rb +1 -1
- data/spec/integration/mappers/deep_embedded_spec.rb +1 -1
- data/spec/integration/mappers/definition_dsl_spec.rb +1 -1
- data/spec/integration/mappers/embedded_spec.rb +1 -1
- data/spec/integration/mappers/exclude_spec.rb +1 -1
- data/spec/integration/mappers/fold_spec.rb +1 -1
- data/spec/integration/mappers/group_spec.rb +1 -1
- data/spec/integration/mappers/overwrite_attributes_value_spec.rb +1 -1
- data/spec/integration/mappers/prefix_separator_spec.rb +1 -1
- data/spec/integration/mappers/prefix_spec.rb +1 -1
- data/spec/integration/mappers/prefixing_attributes_spec.rb +1 -1
- data/spec/integration/mappers/registering_custom_mappers_spec.rb +1 -1
- data/spec/integration/mappers/renaming_attributes_spec.rb +1 -1
- data/spec/integration/mappers/reusing_mappers_spec.rb +1 -1
- data/spec/integration/mappers/step_spec.rb +1 -1
- data/spec/integration/mappers/symbolizing_attributes_spec.rb +1 -1
- data/spec/integration/mappers/unfold_spec.rb +1 -1
- data/spec/integration/mappers/ungroup_spec.rb +2 -2
- data/spec/integration/mappers/unwrap_spec.rb +2 -2
- data/spec/integration/mappers/wrap_spec.rb +1 -1
- data/spec/integration/memory/commands/create_spec.rb +1 -1
- data/spec/integration/memory/commands/delete_spec.rb +1 -1
- data/spec/integration/memory/commands/update_spec.rb +1 -1
- data/spec/integration/multi_env_spec.rb +1 -1
- data/spec/integration/multi_repo_spec.rb +1 -1
- data/spec/integration/relations/default_dataset_spec.rb +1 -1
- data/spec/integration/relations/reading_spec.rb +1 -1
- data/spec/integration/relations/registry_dsl_spec.rb +1 -1
- data/spec/integration/setup_spec.rb +10 -4
- data/spec/shared/command_graph.rb +8 -4
- data/spec/shared/enumerable_dataset.rb +1 -1
- data/spec/spec_helper.rb +7 -9
- data/spec/support/schema.rb +14 -0
- data/spec/unit/rom/array_dataset_spec.rb +59 -0
- data/spec/unit/rom/association_set_spec.rb +4 -0
- data/spec/unit/rom/auto_curry_spec.rb +63 -0
- data/spec/unit/rom/commands/graph_spec.rb +12 -11
- data/spec/unit/rom/commands/lazy_spec.rb +8 -5
- data/spec/unit/rom/commands/pre_and_post_processors_spec.rb +336 -0
- data/spec/unit/rom/commands/result_spec.rb +1 -1
- data/spec/unit/rom/commands_spec.rb +26 -3
- data/spec/unit/rom/configuration_spec.rb +1 -1
- data/spec/unit/rom/container_spec.rb +15 -5
- data/spec/unit/rom/create_container_spec.rb +1 -1
- data/spec/unit/rom/enumerable_dataset_spec.rb +15 -0
- data/spec/unit/rom/gateway_spec.rb +1 -1
- data/spec/unit/rom/mapper_registry_spec.rb +1 -1
- data/spec/unit/rom/memory/commands_spec.rb +1 -1
- data/spec/unit/rom/memory/dataset_spec.rb +1 -1
- data/spec/unit/rom/memory/{repository_spec.rb → gateway_spec.rb} +1 -1
- data/spec/unit/rom/memory/inheritance_spec.rb +32 -0
- data/spec/unit/rom/memory/relation_spec.rb +15 -3
- data/spec/unit/rom/memory/storage_spec.rb +1 -1
- data/spec/unit/rom/plugin_spec.rb +1 -1
- data/spec/unit/rom/plugins/command/schema_spec.rb +5 -5
- data/spec/unit/rom/plugins/relation/key_inference_spec.rb +1 -1
- data/spec/unit/rom/registry_spec.rb +86 -0
- data/spec/unit/rom/relation/attribute_reader_spec.rb +17 -0
- data/spec/unit/rom/relation/call_spec.rb +51 -0
- data/spec/unit/rom/relation/composite_spec.rb +1 -1
- data/spec/unit/rom/relation/graph_spec.rb +1 -1
- data/spec/unit/rom/relation/lazy/combine_spec.rb +1 -1
- data/spec/unit/rom/relation/lazy_spec.rb +1 -1
- data/spec/unit/rom/relation/loaded_spec.rb +1 -1
- data/spec/unit/rom/relation/schema_spec.rb +50 -6
- data/spec/unit/rom/relation/view_spec.rb +122 -0
- data/spec/unit/rom/relation_spec.rb +20 -5
- data/spec/unit/rom/schema/accessing_attributes_spec.rb +52 -0
- data/spec/unit/rom/schema/append_spec.rb +17 -0
- data/spec/unit/rom/schema/exclude_spec.rb +15 -0
- data/spec/unit/rom/schema/finalize_spec.rb +59 -0
- data/spec/unit/rom/schema/key_predicate_spec.rb +15 -0
- data/spec/unit/rom/schema/merge_spec.rb +17 -0
- data/spec/unit/rom/schema/prefix_spec.rb +16 -0
- data/spec/unit/rom/schema/project_spec.rb +15 -0
- data/spec/unit/rom/schema/rename_spec.rb +22 -0
- data/spec/unit/rom/schema/type_spec.rb +49 -0
- data/spec/unit/rom/schema/uniq_spec.rb +21 -0
- data/spec/unit/rom/schema/wrap_spec.rb +17 -0
- data/spec/unit/rom/schema_spec.rb +2 -2
- metadata +79 -17
- data/lib/rom/plugins/relation/view/dsl.rb +0 -32
- data/lib/rom/plugins/relation/view.rb +0 -95
- data/spec/unit/rom/plugins/relation/view_spec.rb +0 -51
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rom/memory'
|
2
2
|
|
3
|
-
describe ROM::Relation do
|
3
|
+
RSpec.describe ROM::Relation do
|
4
4
|
subject(:relation) { Class.new(ROM::Relation).new(dataset) }
|
5
5
|
|
6
6
|
let(:dataset) { ROM::Memory::Dataset.new([jane, joe]) }
|
@@ -196,7 +196,7 @@ describe ROM::Relation do
|
|
196
196
|
|
197
197
|
describe "#with" do
|
198
198
|
it "returns a new instance with the original dataset and given custom options" do
|
199
|
-
relation = Class.new(ROM::Relation) { option :custom }.new([])
|
199
|
+
relation = Class.new(ROM::Relation) { option :custom }.new([], custom: true)
|
200
200
|
|
201
201
|
custom_opts = { mappers: "Custom Mapper Registry" }
|
202
202
|
new_relation = relation.with(custom_opts).with(custom: true)
|
@@ -217,13 +217,28 @@ describe ROM::Relation do
|
|
217
217
|
end
|
218
218
|
end
|
219
219
|
|
220
|
-
describe '#
|
220
|
+
describe '#schema' do
|
221
|
+
it 'returns an empty schema by default' do
|
222
|
+
relation = Class.new(ROM::Relation) {
|
223
|
+
def self.name
|
224
|
+
'Test::SomeRelation'
|
225
|
+
end
|
226
|
+
}.new([])
|
227
|
+
|
228
|
+
expect(relation.schema).to be_empty
|
229
|
+
expect(relation.schema.inferrer).to be(ROM::Schema::DEFAULT_INFERRER)
|
230
|
+
expect(relation.schema.name).to be(:test_some_relation)
|
231
|
+
expect(relation.schema?).to be(false)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
describe '#input_schema' do
|
221
236
|
it 'returns a schema hash type' do
|
222
237
|
relation = Class.new(ROM::Relation[:memory]) do
|
223
238
|
schema { attribute :id, ROM::Types::Coercible::Int }
|
224
239
|
end.new([])
|
225
240
|
|
226
|
-
expect(relation.
|
241
|
+
expect(relation.input_schema[id: '1']).to eql(id: 1)
|
227
242
|
end
|
228
243
|
|
229
244
|
it 'returns a plain Hash coercer when there is no schema' do
|
@@ -231,7 +246,7 @@ describe ROM::Relation do
|
|
231
246
|
|
232
247
|
tuple = [[:id, '1']]
|
233
248
|
|
234
|
-
expect(relation.
|
249
|
+
expect(relation.input_schema[tuple]).to eql(id: '1')
|
235
250
|
end
|
236
251
|
end
|
237
252
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rom/schema'
|
2
|
+
|
3
|
+
RSpec.describe ROM::Schema, '#[]' do
|
4
|
+
context 'with a schema' do
|
5
|
+
subject(:schema) do
|
6
|
+
define_schema(:users, id: :Int, name: :String, email: :String)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'returns an attribute identified by its canonical name' do
|
10
|
+
expect(schema[:email]).to eql(define_type(:email, :String, source: :users))
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns an aliased attribute identified by its canonical name' do
|
14
|
+
expect(schema.rename(id: :user_id)[:id]).to eql(define_type(:id, :Int, source: :users, alias: :user_id))
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'raises KeyError when attribute is not found' do
|
18
|
+
expect { schema[:not_here] }.to raise_error(KeyError, /not_here/)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with a merged schema' do
|
23
|
+
subject(:schema) do
|
24
|
+
left.merge(right.__send__(:new, right.map { |attr| attr.meta(source: :tasks) }))
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:left) do
|
28
|
+
define_schema(:users, id: :Int, name: :String)
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:right) do
|
32
|
+
define_schema(:tasks, id: :Int, title: :String)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns an attribute identified by its canonical name' do
|
36
|
+
expect(schema[:id]).to eql(define_type(:id, :Int, source: :users))
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns an attribute identified by its canonical name when its unique' do
|
40
|
+
expect(schema[:title]).to eql(define_type(:title, :String, source: :tasks))
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns an attribute identified by its canonical name and its source' do
|
44
|
+
expect(schema[:id, :tasks]).to eql(define_type(:id, :Int, source: :tasks))
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'raises KeyError when attribute is not found' do
|
48
|
+
expect { schema[:not_here] }.to raise_error(KeyError, /not_here/)
|
49
|
+
expect { schema[:not_here, :tasks] }.to raise_error(KeyError, /not_here/)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rom/schema'
|
2
|
+
|
3
|
+
RSpec.describe ROM::Schema, '#append' do
|
4
|
+
subject(:schema) { left.append(*right) }
|
5
|
+
|
6
|
+
let(:left) do
|
7
|
+
define_schema(:users, id: :Int, name: :String)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:right) do
|
11
|
+
define_schema(:tasks, user_id: :Int)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns a new schema with attributes from two schemas' do
|
15
|
+
expect(schema.map(&:name)).to eql(%i[id name user_id])
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rom/schema'
|
2
|
+
|
3
|
+
RSpec.describe ROM::Schema, '#exclude' do
|
4
|
+
subject(:schema) do
|
5
|
+
define_schema(:users, id: :Int, name: :String, email: :String)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:excluded) do
|
9
|
+
schema.exclude(:id, :name)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns projected schema with renamed attributes using provided prefix' do
|
13
|
+
expect(excluded.map(&:name)).to eql(%i[email])
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rom/schema'
|
2
|
+
|
3
|
+
RSpec.describe ROM::Schema, '#finalize!' do
|
4
|
+
context 'without inferrer' do
|
5
|
+
subject(:schema) do
|
6
|
+
define_schema(:users, id: :Int, name: :String)
|
7
|
+
end
|
8
|
+
|
9
|
+
before { schema.finalize! }
|
10
|
+
|
11
|
+
it 'returns a frozen canonical schema' do
|
12
|
+
expect(schema).to be_frozen
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with inferrer' do
|
17
|
+
subject(:schema) do
|
18
|
+
ROM::Schema.define(:users, attributes: attributes, inferrer: inferrer)
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:inferrer) do
|
22
|
+
proc { [[define_type(:name, :String)], [:id, :age]]}
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when all required attributes are present' do
|
26
|
+
let(:attributes) do
|
27
|
+
[define_type(:id, :Int), define_type(:age, :Int)]
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'concats defined attributes with inferred attributes' do
|
31
|
+
expect(schema.finalize!.map(&:name)).to eql(%i[id age name])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when inferred attributes are overridden' do
|
36
|
+
let(:attributes) do
|
37
|
+
[define_type(:id, :Int),
|
38
|
+
define_type(:age, :Int),
|
39
|
+
define_type(:name, :String).meta(custom: true)]
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'respects overridden attributes' do
|
43
|
+
expect(schema.finalize!.map(&:name)).to eql(%i[id age name])
|
44
|
+
expect(schema[:name].meta[:custom]).to be(true)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when some attributes are missing' do
|
49
|
+
let(:attributes) do
|
50
|
+
[]
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'raises error' do
|
54
|
+
expect { schema.finalize! }.
|
55
|
+
to raise_error(ROM::Schema::MissingAttributesError, /missing attributes in :users schema: :id, :age/)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rom/schema'
|
2
|
+
|
3
|
+
RSpec.describe ROM::Schema, '#key?' do
|
4
|
+
subject(:schema) do
|
5
|
+
define_schema(:users, name: :String)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'returns true when an attribute exists' do
|
9
|
+
expect(schema.key?(:name)).to be(true)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns false when an attribute does not exist' do
|
13
|
+
expect(schema.key?(:foo)).to be(false)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rom/schema'
|
2
|
+
|
3
|
+
RSpec.describe ROM::Schema, '#merge' do
|
4
|
+
subject(:schema) { left.merge(right) }
|
5
|
+
|
6
|
+
let(:left) do
|
7
|
+
define_schema(:users, id: :Int, name: :String)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:right) do
|
11
|
+
define_schema(:tasks, user_id: :Int)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns a new schema with attributes from two schemas' do
|
15
|
+
expect(schema.map(&:name)).to eql(%i[id name user_id])
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rom/schema'
|
2
|
+
|
3
|
+
RSpec.describe ROM::Schema, '#prefix' do
|
4
|
+
subject(:schema) do
|
5
|
+
define_schema(:users, id: :Int, name: :String)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:prefixed) do
|
9
|
+
schema.prefix(:user)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns projected schema with renamed attributes using provided prefix' do
|
13
|
+
expect(prefixed.map(&:alias)).to eql(%i[user_id user_name])
|
14
|
+
expect(prefixed.map { |attr| attr.meta[:name] }).to eql(%i[id name])
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rom/schema'
|
2
|
+
|
3
|
+
RSpec.describe ROM::Schema, '#project' do
|
4
|
+
subject(:schema) do
|
5
|
+
define_schema(:users, id: :Int, name: :String, age: :Int)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'projects provided attribute names' do
|
9
|
+
expect(schema.project(:name, :age).map(&:name)).to eql(%i[name age])
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'projects provided attributes' do
|
13
|
+
expect(schema.project(schema[:name], schema[:age]).map(&:name)).to eql(%i[name age])
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rom/schema'
|
2
|
+
|
3
|
+
RSpec.describe ROM::Schema, '#rename' do
|
4
|
+
subject(:schema) do
|
5
|
+
define_schema(
|
6
|
+
:users,
|
7
|
+
user_id: :Int, user_name: :String, user_email: :String
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:renamed) do
|
12
|
+
schema.rename(user_id: :id, user_name: :name)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns projected schema with renamed attributes' do
|
16
|
+
expect(renamed.map(&:name)).to eql(%i[user_id user_name user_email])
|
17
|
+
expect(renamed.map(&:alias)).to eql([:id, :name, nil])
|
18
|
+
expect(renamed.all?(&:aliased?)).to be(false)
|
19
|
+
expect(renamed[:user_id]).to be_aliased
|
20
|
+
expect(renamed[:user_name]).to be_aliased
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rom/schema/attribute'
|
2
|
+
|
3
|
+
RSpec.describe ROM::Schema::Attribute do
|
4
|
+
describe '#inspect' do
|
5
|
+
context 'with a primitive definition' do
|
6
|
+
subject(:type) do
|
7
|
+
ROM::Schema::Attribute.new(ROM::Types::Int).meta(name: :id, primary_key: true)
|
8
|
+
end
|
9
|
+
|
10
|
+
specify do
|
11
|
+
expect(type.inspect).to eql("#<ROM::Schema::Attribute[Integer] name=:id primary_key=true>")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with a sum' do
|
16
|
+
subject(:type) do
|
17
|
+
ROM::Schema::Attribute.new(ROM::Types::Bool).meta(name: :admin)
|
18
|
+
end
|
19
|
+
|
20
|
+
specify do
|
21
|
+
expect(type.inspect).to eql("#<ROM::Schema::Attribute[TrueClass | FalseClass] name=:admin>")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#aliased' do
|
27
|
+
subject(:type) do
|
28
|
+
ROM::Schema::Attribute.new(ROM::Types::String).meta(name: :user_name)
|
29
|
+
end
|
30
|
+
|
31
|
+
specify do
|
32
|
+
expect(type.as(:name).meta[:alias]).to eql(:name)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#method_missing' do
|
37
|
+
subject(:type) do
|
38
|
+
ROM::Schema::Attribute.new(ROM::Types::Int).meta(name: :id, primary_key: true)
|
39
|
+
end
|
40
|
+
|
41
|
+
specify do
|
42
|
+
expect(type.meta).to eql(name: :id, primary_key: true)
|
43
|
+
end
|
44
|
+
|
45
|
+
specify do
|
46
|
+
expect { type.not_here }.to raise_error(NoMethodError, /not_here/)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rom/schema'
|
2
|
+
|
3
|
+
RSpec.describe ROM::Schema, '#uniq' do
|
4
|
+
subject(:schema) { left.merge(right) }
|
5
|
+
|
6
|
+
let(:left) do
|
7
|
+
define_schema(:users, id: :Int, name: :String)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:right) do
|
11
|
+
define_schema(:tasks, id: :Int, user_id: :Int)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns a new schema with unique attributes from two schemas' do
|
15
|
+
expect(schema.uniq.map(&:name)).to eql(%i[id name user_id])
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'accepts a block' do
|
19
|
+
expect(schema.uniq(&:primitive).map(&:name)).to eql(%i[id name])
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rom/schema'
|
2
|
+
|
3
|
+
RSpec.describe ROM::Schema, '#wrap' do
|
4
|
+
subject(:schema) do
|
5
|
+
define_schema(:users, id: :Int, name: :String)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:wrapped) do
|
9
|
+
schema.wrap(:users)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns projected schema with renamed attributes using provided prefix' do
|
13
|
+
expect(wrapped.map(&:alias)).to eql(%i[users_id users_name])
|
14
|
+
expect(wrapped.map { |attr| attr.meta[:name] }).to eql(%i[id name])
|
15
|
+
expect(wrapped.all?(&:wrapped?)).to be(true)
|
16
|
+
end
|
17
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
RSpec.describe ROM::Schema do
|
2
2
|
describe '#to_h' do
|
3
3
|
it 'returns hash with attributes' do
|
4
|
-
attrs = { id: ROM::Types::Int, name: ROM::Types::String }
|
5
|
-
schema = ROM::Schema.
|
4
|
+
attrs = { id: ROM::Types::Int.meta(name: :id), name: ROM::Types::String.meta(name: :name) }
|
5
|
+
schema = ROM::Schema.define(:name, attributes: attrs.values)
|
6
6
|
|
7
7
|
expect(schema.to_h).to eql(attrs)
|
8
8
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -44,42 +44,74 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.9'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 0.9.4
|
48
51
|
type: :runtime
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
55
|
- - "~>"
|
53
56
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
57
|
+
version: '0.9'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.9.4
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
62
|
+
name: dry-core
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
65
|
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: '2
|
67
|
+
version: '0.2'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 0.2.3
|
62
71
|
type: :runtime
|
63
72
|
prerelease: false
|
64
73
|
version_requirements: !ruby/object:Gem::Requirement
|
65
74
|
requirements:
|
66
75
|
- - "~>"
|
67
76
|
- !ruby/object:Gem::Version
|
68
|
-
version: '2
|
77
|
+
version: '0.2'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 0.2.3
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: dry-initializer
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0.10'
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 0.10.2
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0.10'
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 0.10.2
|
69
101
|
- !ruby/object:Gem::Dependency
|
70
102
|
name: rom-mapper
|
71
103
|
requirement: !ruby/object:Gem::Requirement
|
72
104
|
requirements:
|
73
105
|
- - "~>"
|
74
106
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
107
|
+
version: '0.5'
|
76
108
|
type: :runtime
|
77
109
|
prerelease: false
|
78
110
|
version_requirements: !ruby/object:Gem::Requirement
|
79
111
|
requirements:
|
80
112
|
- - "~>"
|
81
113
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
114
|
+
version: '0.5'
|
83
115
|
- !ruby/object:Gem::Dependency
|
84
116
|
name: rake
|
85
117
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +132,14 @@ dependencies:
|
|
100
132
|
requirements:
|
101
133
|
- - "~>"
|
102
134
|
- !ruby/object:Gem::Version
|
103
|
-
version: '3.
|
135
|
+
version: '3.5'
|
104
136
|
type: :development
|
105
137
|
prerelease: false
|
106
138
|
version_requirements: !ruby/object:Gem::Requirement
|
107
139
|
requirements:
|
108
140
|
- - "~>"
|
109
141
|
- !ruby/object:Gem::Version
|
110
|
-
version: '3.
|
142
|
+
version: '3.5'
|
111
143
|
description: Persistence and mapping toolkit for Ruby
|
112
144
|
email: piotr.solnica@gmail.com
|
113
145
|
executables: []
|
@@ -119,6 +151,7 @@ files:
|
|
119
151
|
- ".rubocop.yml"
|
120
152
|
- ".rubocop_todo.yml"
|
121
153
|
- ".travis.yml"
|
154
|
+
- ".yardopts"
|
122
155
|
- CHANGELOG.md
|
123
156
|
- CODE_OF_CONDUCT.md
|
124
157
|
- CONTRIBUTING.md
|
@@ -128,7 +161,9 @@ files:
|
|
128
161
|
- README.md
|
129
162
|
- Rakefile
|
130
163
|
- lib/rom.rb
|
164
|
+
- lib/rom/array_dataset.rb
|
131
165
|
- lib/rom/association_set.rb
|
166
|
+
- lib/rom/auto_curry.rb
|
132
167
|
- lib/rom/command.rb
|
133
168
|
- lib/rom/command_registry.rb
|
134
169
|
- lib/rom/commands.rb
|
@@ -157,10 +192,13 @@ files:
|
|
157
192
|
- lib/rom/constants.rb
|
158
193
|
- lib/rom/container.rb
|
159
194
|
- lib/rom/create_container.rb
|
195
|
+
- lib/rom/data_proxy.rb
|
196
|
+
- lib/rom/enumerable_dataset.rb
|
160
197
|
- lib/rom/environment.rb
|
161
198
|
- lib/rom/gateway.rb
|
162
199
|
- lib/rom/global.rb
|
163
200
|
- lib/rom/global/plugin_dsl.rb
|
201
|
+
- lib/rom/initializer.rb
|
164
202
|
- lib/rom/lint/enumerable_dataset.rb
|
165
203
|
- lib/rom/lint/gateway.rb
|
166
204
|
- lib/rom/lint/linter.rb
|
@@ -172,6 +210,7 @@ files:
|
|
172
210
|
- lib/rom/memory/dataset.rb
|
173
211
|
- lib/rom/memory/gateway.rb
|
174
212
|
- lib/rom/memory/relation.rb
|
213
|
+
- lib/rom/memory/schema.rb
|
175
214
|
- lib/rom/memory/storage.rb
|
176
215
|
- lib/rom/memory/types.rb
|
177
216
|
- lib/rom/pipeline.rb
|
@@ -182,8 +221,7 @@ files:
|
|
182
221
|
- lib/rom/plugins/configuration/configuration_dsl.rb
|
183
222
|
- lib/rom/plugins/relation/key_inference.rb
|
184
223
|
- lib/rom/plugins/relation/registry_reader.rb
|
185
|
-
- lib/rom/
|
186
|
-
- lib/rom/plugins/relation/view/dsl.rb
|
224
|
+
- lib/rom/registry.rb
|
187
225
|
- lib/rom/relation.rb
|
188
226
|
- lib/rom/relation/class_interface.rb
|
189
227
|
- lib/rom/relation/composite.rb
|
@@ -192,8 +230,10 @@ files:
|
|
192
230
|
- lib/rom/relation/loaded.rb
|
193
231
|
- lib/rom/relation/materializable.rb
|
194
232
|
- lib/rom/relation/name.rb
|
233
|
+
- lib/rom/relation/view_dsl.rb
|
195
234
|
- lib/rom/relation_registry.rb
|
196
235
|
- lib/rom/schema.rb
|
236
|
+
- lib/rom/schema/attribute.rb
|
197
237
|
- lib/rom/schema/dsl.rb
|
198
238
|
- lib/rom/setup.rb
|
199
239
|
- lib/rom/setup/auto_registration.rb
|
@@ -206,6 +246,7 @@ files:
|
|
206
246
|
- lib/rom/setup/finalize/finalize_mappers.rb
|
207
247
|
- lib/rom/setup/finalize/finalize_relations.rb
|
208
248
|
- lib/rom/support/configurable.rb
|
249
|
+
- lib/rom/transaction.rb
|
209
250
|
- lib/rom/types.rb
|
210
251
|
- lib/rom/version.rb
|
211
252
|
- log/.gitkeep
|
@@ -236,6 +277,8 @@ files:
|
|
236
277
|
- spec/integration/commands/graph_spec.rb
|
237
278
|
- spec/integration/commands/update_spec.rb
|
238
279
|
- spec/integration/commands_spec.rb
|
280
|
+
- spec/integration/gateways/extending_relations_spec.rb
|
281
|
+
- spec/integration/gateways/setting_logger_spec.rb
|
239
282
|
- spec/integration/mappers/combine_spec.rb
|
240
283
|
- spec/integration/mappers/deep_embedded_spec.rb
|
241
284
|
- spec/integration/mappers/definition_dsl_spec.rb
|
@@ -265,8 +308,6 @@ files:
|
|
265
308
|
- spec/integration/relations/inheritance_spec.rb
|
266
309
|
- spec/integration/relations/reading_spec.rb
|
267
310
|
- spec/integration/relations/registry_dsl_spec.rb
|
268
|
-
- spec/integration/repositories/extending_relations_spec.rb
|
269
|
-
- spec/integration/repositories/setting_logger_spec.rb
|
270
311
|
- spec/integration/setup_spec.rb
|
271
312
|
- spec/shared/command_behavior.rb
|
272
313
|
- spec/shared/command_graph.rb
|
@@ -281,29 +322,37 @@ files:
|
|
281
322
|
- spec/spec_helper.rb
|
282
323
|
- spec/support/constant_leak_finder.rb
|
283
324
|
- spec/support/mutant.rb
|
325
|
+
- spec/support/schema.rb
|
284
326
|
- spec/support/types.rb
|
285
327
|
- spec/test/memory_repository_lint_test.rb
|
328
|
+
- spec/unit/rom/array_dataset_spec.rb
|
286
329
|
- spec/unit/rom/association_set_spec.rb
|
330
|
+
- spec/unit/rom/auto_curry_spec.rb
|
287
331
|
- spec/unit/rom/commands/graph_spec.rb
|
288
332
|
- spec/unit/rom/commands/lazy_spec.rb
|
333
|
+
- spec/unit/rom/commands/pre_and_post_processors_spec.rb
|
289
334
|
- spec/unit/rom/commands/result_spec.rb
|
290
335
|
- spec/unit/rom/commands_spec.rb
|
291
336
|
- spec/unit/rom/configurable_spec.rb
|
292
337
|
- spec/unit/rom/configuration_spec.rb
|
293
338
|
- spec/unit/rom/container_spec.rb
|
294
339
|
- spec/unit/rom/create_container_spec.rb
|
340
|
+
- spec/unit/rom/enumerable_dataset_spec.rb
|
295
341
|
- spec/unit/rom/environment_spec.rb
|
296
342
|
- spec/unit/rom/gateway_spec.rb
|
297
343
|
- spec/unit/rom/mapper_registry_spec.rb
|
298
344
|
- spec/unit/rom/memory/commands_spec.rb
|
299
345
|
- spec/unit/rom/memory/dataset_spec.rb
|
346
|
+
- spec/unit/rom/memory/gateway_spec.rb
|
347
|
+
- spec/unit/rom/memory/inheritance_spec.rb
|
300
348
|
- spec/unit/rom/memory/relation_spec.rb
|
301
|
-
- spec/unit/rom/memory/repository_spec.rb
|
302
349
|
- spec/unit/rom/memory/storage_spec.rb
|
303
350
|
- spec/unit/rom/plugin_spec.rb
|
304
351
|
- spec/unit/rom/plugins/command/schema_spec.rb
|
305
352
|
- spec/unit/rom/plugins/relation/key_inference_spec.rb
|
306
|
-
- spec/unit/rom/
|
353
|
+
- spec/unit/rom/registry_spec.rb
|
354
|
+
- spec/unit/rom/relation/attribute_reader_spec.rb
|
355
|
+
- spec/unit/rom/relation/call_spec.rb
|
307
356
|
- spec/unit/rom/relation/composite_spec.rb
|
308
357
|
- spec/unit/rom/relation/curried_spec.rb
|
309
358
|
- spec/unit/rom/relation/graph_spec.rb
|
@@ -312,7 +361,20 @@ files:
|
|
312
361
|
- spec/unit/rom/relation/loaded_spec.rb
|
313
362
|
- spec/unit/rom/relation/name_spec.rb
|
314
363
|
- spec/unit/rom/relation/schema_spec.rb
|
364
|
+
- spec/unit/rom/relation/view_spec.rb
|
315
365
|
- spec/unit/rom/relation_spec.rb
|
366
|
+
- spec/unit/rom/schema/accessing_attributes_spec.rb
|
367
|
+
- spec/unit/rom/schema/append_spec.rb
|
368
|
+
- spec/unit/rom/schema/exclude_spec.rb
|
369
|
+
- spec/unit/rom/schema/finalize_spec.rb
|
370
|
+
- spec/unit/rom/schema/key_predicate_spec.rb
|
371
|
+
- spec/unit/rom/schema/merge_spec.rb
|
372
|
+
- spec/unit/rom/schema/prefix_spec.rb
|
373
|
+
- spec/unit/rom/schema/project_spec.rb
|
374
|
+
- spec/unit/rom/schema/rename_spec.rb
|
375
|
+
- spec/unit/rom/schema/type_spec.rb
|
376
|
+
- spec/unit/rom/schema/uniq_spec.rb
|
377
|
+
- spec/unit/rom/schema/wrap_spec.rb
|
316
378
|
- spec/unit/rom/schema_spec.rb
|
317
379
|
- spec/unit/rom/setup/auto_registration_spec.rb
|
318
380
|
homepage: http://rom-rb.org
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module ROM
|
2
|
-
module Plugins
|
3
|
-
module Relation
|
4
|
-
module View
|
5
|
-
class DSL
|
6
|
-
attr_reader :name
|
7
|
-
|
8
|
-
attr_reader :attributes
|
9
|
-
|
10
|
-
attr_reader :relation_block
|
11
|
-
|
12
|
-
def initialize(name, &block)
|
13
|
-
@name = name
|
14
|
-
instance_eval(&block)
|
15
|
-
end
|
16
|
-
|
17
|
-
def header(*args, &block)
|
18
|
-
@attributes = args.size > 0 ? args.first : block
|
19
|
-
end
|
20
|
-
|
21
|
-
def relation(&block)
|
22
|
-
@relation_block = lambda(&block)
|
23
|
-
end
|
24
|
-
|
25
|
-
def call
|
26
|
-
[name, attributes, relation_block]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|