rom 0.5.0 → 0.6.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +19 -15
  3. data/.rubocop_todo.yml +28 -0
  4. data/.travis.yml +8 -1
  5. data/CHANGELOG.md +40 -0
  6. data/Gemfile +10 -2
  7. data/Guardfile +12 -10
  8. data/README.md +42 -43
  9. data/Rakefile +13 -23
  10. data/lib/rom.rb +19 -27
  11. data/lib/rom/command.rb +118 -0
  12. data/lib/rom/command_registry.rb +13 -27
  13. data/lib/rom/commands.rb +1 -59
  14. data/lib/rom/commands/abstract.rb +147 -0
  15. data/lib/rom/commands/composite.rb +47 -0
  16. data/lib/rom/commands/create.rb +2 -17
  17. data/lib/rom/commands/delete.rb +5 -25
  18. data/lib/rom/commands/result.rb +5 -5
  19. data/lib/rom/commands/update.rb +3 -27
  20. data/lib/rom/constants.rb +19 -0
  21. data/lib/rom/env.rb +85 -35
  22. data/lib/rom/global.rb +173 -42
  23. data/lib/rom/header.rb +5 -5
  24. data/lib/rom/header/attribute.rb +2 -2
  25. data/lib/rom/lint/enumerable_dataset.rb +52 -0
  26. data/lib/rom/lint/linter.rb +64 -0
  27. data/lib/rom/lint/repository.rb +78 -0
  28. data/lib/rom/lint/spec.rb +20 -0
  29. data/lib/rom/lint/test.rb +98 -0
  30. data/lib/rom/mapper.rb +32 -5
  31. data/lib/rom/mapper/attribute_dsl.rb +240 -0
  32. data/lib/rom/mapper/dsl.rb +100 -0
  33. data/lib/rom/mapper/model_dsl.rb +55 -0
  34. data/lib/rom/mapper_registry.rb +8 -1
  35. data/lib/rom/memory.rb +4 -0
  36. data/lib/rom/memory/commands.rb +46 -0
  37. data/lib/rom/memory/dataset.rb +72 -0
  38. data/lib/rom/memory/relation.rb +44 -0
  39. data/lib/rom/memory/repository.rb +62 -0
  40. data/lib/rom/memory/storage.rb +57 -0
  41. data/lib/rom/model_builder.rb +44 -5
  42. data/lib/rom/processor.rb +1 -1
  43. data/lib/rom/processor/transproc.rb +109 -16
  44. data/lib/rom/reader.rb +91 -39
  45. data/lib/rom/relation.rb +165 -26
  46. data/lib/rom/relation/composite.rb +132 -0
  47. data/lib/rom/relation/curried.rb +48 -0
  48. data/lib/rom/relation/lazy.rb +173 -0
  49. data/lib/rom/relation/loaded.rb +75 -0
  50. data/lib/rom/relation/registry_reader.rb +23 -0
  51. data/lib/rom/repository.rb +93 -34
  52. data/lib/rom/setup.rb +54 -98
  53. data/lib/rom/setup/finalize.rb +85 -76
  54. data/lib/rom/setup_dsl/command.rb +36 -0
  55. data/lib/rom/setup_dsl/command_dsl.rb +34 -0
  56. data/lib/rom/setup_dsl/mapper.rb +32 -0
  57. data/lib/rom/setup_dsl/mapper_dsl.rb +30 -0
  58. data/lib/rom/setup_dsl/relation.rb +21 -0
  59. data/lib/rom/setup_dsl/setup.rb +75 -0
  60. data/lib/rom/support/array_dataset.rb +38 -0
  61. data/lib/rom/support/class_builder.rb +44 -0
  62. data/lib/rom/support/class_macros.rb +56 -0
  63. data/lib/rom/support/data_proxy.rb +102 -0
  64. data/lib/rom/support/enumerable_dataset.rb +58 -0
  65. data/lib/rom/support/inflector.rb +73 -0
  66. data/lib/rom/support/options.rb +188 -0
  67. data/lib/rom/support/registry.rb +4 -8
  68. data/lib/rom/version.rb +1 -1
  69. data/rakelib/benchmark.rake +13 -0
  70. data/rakelib/mutant.rake +16 -0
  71. data/rakelib/rubocop.rake +18 -0
  72. data/rom.gemspec +4 -7
  73. data/spec/integration/commands/create_spec.rb +32 -24
  74. data/spec/integration/commands/delete_spec.rb +15 -7
  75. data/spec/integration/commands/update_spec.rb +13 -11
  76. data/spec/integration/mappers/deep_embedded_spec.rb +4 -11
  77. data/spec/integration/mappers/definition_dsl_spec.rb +31 -44
  78. data/spec/integration/mappers/embedded_spec.rb +9 -24
  79. data/spec/integration/mappers/group_spec.rb +22 -30
  80. data/spec/integration/mappers/prefixing_attributes_spec.rb +18 -23
  81. data/spec/integration/mappers/renaming_attributes_spec.rb +23 -38
  82. data/spec/integration/mappers/symbolizing_attributes_spec.rb +18 -24
  83. data/spec/integration/mappers/wrap_spec.rb +22 -30
  84. data/spec/integration/multi_repo_spec.rb +15 -37
  85. data/spec/integration/relations/reading_spec.rb +82 -14
  86. data/spec/integration/repositories/extending_relations_spec.rb +50 -0
  87. data/spec/integration/{adapters → repositories}/setting_logger_spec.rb +6 -5
  88. data/spec/integration/setup_spec.rb +59 -62
  89. data/spec/shared/enumerable_dataset.rb +49 -0
  90. data/spec/shared/one_behavior.rb +26 -0
  91. data/spec/shared/users_and_tasks.rb +11 -23
  92. data/spec/spec_helper.rb +16 -7
  93. data/spec/support/constant_leak_finder.rb +14 -0
  94. data/spec/test/memory_repository_lint_test.rb +27 -0
  95. data/spec/unit/rom/command_registry_spec.rb +44 -0
  96. data/spec/unit/rom/commands/result_spec.rb +14 -0
  97. data/spec/unit/rom/commands_spec.rb +174 -0
  98. data/spec/unit/rom/env_spec.rb +40 -7
  99. data/spec/unit/rom/global_spec.rb +14 -0
  100. data/spec/unit/rom/{mapper_builder_spec.rb → mapper/dsl_spec.rb} +52 -38
  101. data/spec/unit/rom/mapper_spec.rb +51 -10
  102. data/spec/unit/rom/{adapter/memory → memory}/dataset_spec.rb +6 -4
  103. data/spec/unit/rom/memory/repository_spec.rb +12 -0
  104. data/spec/unit/rom/memory/storage_spec.rb +45 -0
  105. data/spec/unit/rom/model_builder_spec.rb +4 -3
  106. data/spec/unit/rom/processor/transproc_spec.rb +1 -0
  107. data/spec/unit/rom/reader_spec.rb +97 -24
  108. data/spec/unit/rom/relation/composite_spec.rb +65 -0
  109. data/spec/unit/rom/relation/lazy_spec.rb +145 -0
  110. data/spec/unit/rom/relation/loaded_spec.rb +28 -0
  111. data/spec/unit/rom/relation_spec.rb +111 -6
  112. data/spec/unit/rom/repository_spec.rb +59 -9
  113. data/spec/unit/rom/setup_spec.rb +99 -11
  114. data/spec/unit/rom/support/array_dataset_spec.rb +59 -0
  115. data/spec/unit/rom/support/class_builder_spec.rb +42 -0
  116. data/spec/unit/rom/support/enumerable_dataset_spec.rb +17 -0
  117. data/spec/unit/rom/support/inflector_spec.rb +89 -0
  118. data/spec/unit/rom/support/options_spec.rb +119 -0
  119. metadata +74 -112
  120. data/lib/rom/adapter.rb +0 -191
  121. data/lib/rom/adapter/memory.rb +0 -32
  122. data/lib/rom/adapter/memory/commands.rb +0 -31
  123. data/lib/rom/adapter/memory/dataset.rb +0 -67
  124. data/lib/rom/adapter/memory/storage.rb +0 -26
  125. data/lib/rom/commands/with_options.rb +0 -18
  126. data/lib/rom/config.rb +0 -70
  127. data/lib/rom/mapper_builder.rb +0 -52
  128. data/lib/rom/mapper_builder/mapper_dsl.rb +0 -114
  129. data/lib/rom/mapper_builder/model_dsl.rb +0 -29
  130. data/lib/rom/reader_builder.rb +0 -48
  131. data/lib/rom/relation_builder.rb +0 -62
  132. data/lib/rom/setup/base_relation_dsl.rb +0 -46
  133. data/lib/rom/setup/command_dsl.rb +0 -46
  134. data/lib/rom/setup/mapper_dsl.rb +0 -19
  135. data/lib/rom/setup/relation_dsl.rb +0 -20
  136. data/lib/rom/setup/schema_dsl.rb +0 -33
  137. data/spec/integration/adapters/extending_relations_spec.rb +0 -41
  138. data/spec/integration/commands/try_spec.rb +0 -27
  139. data/spec/integration/schema_spec.rb +0 -77
  140. data/spec/unit/config_spec.rb +0 -60
  141. data/spec/unit/rom/adapter_spec.rb +0 -79
  142. data/spec/unit/rom_spec.rb +0 -14
@@ -1,23 +1,16 @@
1
1
  require 'spec_helper'
2
+ require 'rom/memory'
2
3
 
3
4
  describe 'Mappers / embedded' do
4
- let(:setup) { ROM.setup('memory://test') }
5
+ let(:setup) { ROM.setup(:memory) }
5
6
  let(:rom) { setup.finalize }
6
7
 
7
8
  it 'allows mapping embedded tuples' do
8
- setup.schema do
9
- base_relation(:users) do
10
- repository :default
11
- attribute 'name'
12
- attribute 'tasks'
13
- end
14
- end
15
-
16
9
  setup.relation(:users)
17
10
 
18
11
  setup.mappers do
19
12
  define(:users) do
20
- model name: 'User'
13
+ model name: 'Test::User'
21
14
 
22
15
  attribute :name, from: 'name'
23
16
 
@@ -27,7 +20,7 @@ describe 'Mappers / embedded' do
27
20
  end
28
21
  end
29
22
 
30
- rom.schema.users << {
23
+ rom.relations.users << {
31
24
  'name' => 'Jane',
32
25
  'tasks' => [{ 'title' => 'Task One' }, { 'title' => 'Task Two' }]
33
26
  }
@@ -41,31 +34,23 @@ describe 'Mappers / embedded' do
41
34
  end
42
35
 
43
36
  it 'allows mapping embedded tuple' do
44
- setup.schema do
45
- base_relation(:users) do
46
- repository :default
47
- attribute 'name'
48
- attribute 'address'
49
- end
50
- end
51
-
52
37
  setup.relation(:users)
53
38
 
54
39
  setup.mappers do
55
40
  define(:users) do
56
- model name: 'User'
41
+ model name: 'Test::User'
57
42
 
58
43
  attribute :name, from: 'name'
59
44
 
60
45
  embedded :address, from: 'address', type: :hash do
61
- model name: 'Address'
46
+ model name: 'Test::Address'
62
47
  attribute :street, from: 'street'
63
48
  attribute :city, from: 'city'
64
49
  end
65
50
  end
66
51
  end
67
52
 
68
- rom.schema.users << {
53
+ rom.relations.users << {
69
54
  'name' => 'Jane',
70
55
  'address' => { 'street' => 'Somewhere 1', 'city' => 'NYC' }
71
56
  }
@@ -74,9 +59,9 @@ describe 'Mappers / embedded' do
74
59
 
75
60
  expect(rom.read(:users).mapper.header.map(&:name)).to eql([:name, :address])
76
61
 
77
- Address.send(:include, Equalizer.new(:street, :city))
62
+ Test::Address.send(:include, Equalizer.new(:street, :city))
78
63
 
79
64
  expect(jane.name).to eql('Jane')
80
- expect(jane.address).to eql(Address.new(street: 'Somewhere 1', city: 'NYC'))
65
+ expect(jane.address).to eql(Test::Address.new(street: 'Somewhere 1', city: 'NYC'))
81
66
  end
82
67
  end
@@ -5,14 +5,6 @@ describe 'Mapper definition DSL' do
5
5
 
6
6
  let(:header) { mapper.header }
7
7
 
8
- before do
9
- setup.relation(:users) do
10
- def email_index
11
- project(:email)
12
- end
13
- end
14
- end
15
-
16
8
  describe 'grouped relation mapper' do
17
9
  before do
18
10
  setup.relation(:tasks) do
@@ -29,7 +21,7 @@ describe 'Mapper definition DSL' do
29
21
 
30
22
  setup.mappers do
31
23
  define(:users) do
32
- model name: 'User'
24
+ model name: 'Test::User'
33
25
 
34
26
  attribute :name
35
27
  attribute :email
@@ -40,7 +32,7 @@ describe 'Mapper definition DSL' do
40
32
  it 'allows defining grouped attributes via options hash' do
41
33
  setup.mappers do
42
34
  define(:with_tasks, parent: :users) do
43
- model name: 'UserWithTasks'
35
+ model name: 'Test::UserWithTasks'
44
36
 
45
37
  attribute :name
46
38
  attribute :email
@@ -51,12 +43,12 @@ describe 'Mapper definition DSL' do
51
43
 
52
44
  rom = setup.finalize
53
45
 
54
- UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
46
+ Test::UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
55
47
 
56
48
  jane = rom.read(:users).with_tasks.to_a.last
57
49
 
58
50
  expect(jane).to eql(
59
- UserWithTasks.new(
51
+ Test::UserWithTasks.new(
60
52
  name: 'Jane',
61
53
  email: 'jane@doe.org',
62
54
  tasks: [{ title: 'be cool', priority: 2 }]
@@ -67,7 +59,7 @@ describe 'Mapper definition DSL' do
67
59
  it 'allows defining grouped attributes via block' do
68
60
  setup.mappers do
69
61
  define(:with_tasks, parent: :users) do
70
- model name: 'UserWithTasks'
62
+ model name: 'Test::UserWithTasks'
71
63
 
72
64
  attribute :name
73
65
  attribute :email
@@ -81,12 +73,12 @@ describe 'Mapper definition DSL' do
81
73
 
82
74
  rom = setup.finalize
83
75
 
84
- UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
76
+ Test::UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
85
77
 
86
78
  jane = rom.read(:users).with_tasks.to_a.last
87
79
 
88
80
  expect(jane).to eql(
89
- UserWithTasks.new(
81
+ Test::UserWithTasks.new(
90
82
  name: 'Jane',
91
83
  email: 'jane@doe.org',
92
84
  tasks: [{ title: 'be cool', priority: 2 }]
@@ -97,13 +89,13 @@ describe 'Mapper definition DSL' do
97
89
  it 'allows defining grouped attributes mapped to a model via block' do
98
90
  setup.mappers do
99
91
  define(:with_tasks, parent: :users) do
100
- model name: 'UserWithTasks'
92
+ model name: 'Test::UserWithTasks'
101
93
 
102
94
  attribute :name
103
95
  attribute :email
104
96
 
105
97
  group :tasks do
106
- model name: 'Task'
98
+ model name: 'Test::Task'
107
99
 
108
100
  attribute :title
109
101
  attribute :priority
@@ -113,16 +105,16 @@ describe 'Mapper definition DSL' do
113
105
 
114
106
  rom = setup.finalize
115
107
 
116
- UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
117
- Task.send(:include, Equalizer.new(:title, :priority))
108
+ Test::UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
109
+ Test::Task.send(:include, Equalizer.new(:title, :priority))
118
110
 
119
111
  jane = rom.read(:users).with_tasks.to_a.last
120
112
 
121
113
  expect(jane).to eql(
122
- UserWithTasks.new(
114
+ Test::UserWithTasks.new(
123
115
  name: 'Jane',
124
116
  email: 'jane@doe.org',
125
- tasks: [Task.new(title: 'be cool', priority: 2)]
117
+ tasks: [Test::Task.new(title: 'be cool', priority: 2)]
126
118
  )
127
119
  )
128
120
  end
@@ -132,18 +124,18 @@ describe 'Mapper definition DSL' do
132
124
  define(:tasks)
133
125
 
134
126
  define(:with_users, parent: :tasks, inherit_header: false) do
135
- model name: 'TaskWithUsers'
127
+ model name: 'Test::TaskWithUsers'
136
128
 
137
129
  attribute :title
138
130
  attribute :priority
139
131
 
140
132
  group :users do
141
- model name: 'TaskUser'
133
+ model name: 'Test::TaskUser'
142
134
 
143
135
  attribute :name
144
136
 
145
137
  group :contacts do
146
- model name: 'Contact'
138
+ model name: 'Test::Contact'
147
139
  attribute :email
148
140
  end
149
141
  end
@@ -152,16 +144,16 @@ describe 'Mapper definition DSL' do
152
144
 
153
145
  rom = setup.finalize
154
146
 
155
- TaskWithUsers.send(:include, Equalizer.new(:title, :priority, :users))
156
- TaskUser.send(:include, Equalizer.new(:name, :contacts))
157
- Contact.send(:include, Equalizer.new(:email))
147
+ Test::TaskWithUsers.send(:include, Equalizer.new(:title, :priority, :users))
148
+ Test::TaskUser.send(:include, Equalizer.new(:name, :contacts))
149
+ Test::Contact.send(:include, Equalizer.new(:email))
158
150
 
159
151
  task = rom.read(:tasks).with_users.to_a.first
160
152
 
161
153
  expect(task).to eql(
162
- TaskWithUsers.new(title: 'be nice', priority: 1, users: [
163
- TaskUser.new(name: 'Joe', contacts: [
164
- Contact.new(email: 'joe@doe.org')
154
+ Test::TaskWithUsers.new(title: 'be nice', priority: 1, users: [
155
+ Test::TaskUser.new(name: 'Joe', contacts: [
156
+ Test::Contact.new(email: 'joe@doe.org')
165
157
  ])
166
158
  ])
167
159
  )
@@ -1,42 +1,37 @@
1
1
  require 'spec_helper'
2
+ require 'rom/memory'
2
3
 
3
4
  describe 'Mappers / Prefixing attributes' do
4
- let(:setup) { ROM.setup(memory: 'memory://test') }
5
+ let(:setup) { ROM.setup(:memory) }
5
6
 
6
7
  before do
7
- setup.schema do
8
- base_relation(:users) do
9
- repository :memory
10
-
11
- attribute :user_id
12
- attribute :user_name
13
- attribute :user_email
14
- end
15
- end
16
-
17
8
  setup.relation(:users)
18
9
  end
19
10
 
20
11
  it 'automatically maps all attributes using the provided prefix' do
21
- setup.mappers do
22
- define(:users, prefix: :user) do
23
- model name: 'User'
24
-
25
- attribute :id
26
- attribute :name
27
- attribute :email
28
- end
12
+ class Test::UserMapper < ROM::Mapper
13
+ relation :users
14
+ prefix :user
15
+
16
+ model name: 'Test::User'
17
+
18
+ attribute :id
19
+ attribute :name
20
+ attribute :email
29
21
  end
30
22
 
31
23
  rom = setup.finalize
32
24
 
33
- User.send(:include, Equalizer.new(:id, :name, :email))
25
+ Test::User.send(:include, Equalizer.new(:id, :name, :email))
34
26
 
35
- rom.schema.users << { user_id: 123, user_name: 'Jane',
36
- user_email: 'jane@doe.org' }
27
+ rom.relations.users << {
28
+ user_id: 123,
29
+ user_name: 'Jane',
30
+ user_email: 'jane@doe.org'
31
+ }
37
32
 
38
33
  jane = rom.read(:users).to_a.first
39
34
 
40
- expect(jane).to eql(User.new(id: 123, name: 'Jane', email: 'jane@doe.org'))
35
+ expect(jane).to eql(Test::User.new(id: 123, name: 'Jane', email: 'jane@doe.org'))
41
36
  end
42
37
  end
@@ -1,25 +1,10 @@
1
1
  require 'spec_helper'
2
+ require 'rom/memory'
2
3
 
3
4
  describe 'Mappers / Renaming attributes' do
4
- let(:setup) { ROM.setup(memory: 'memory://test') }
5
+ let(:setup) { ROM.setup(:memory) }
5
6
 
6
7
  before do
7
- setup.schema do
8
- base_relation(:users) do
9
- repository :memory
10
-
11
- attribute :_id
12
- attribute :user_name
13
- end
14
-
15
- base_relation(:addresses) do
16
- repository :memory
17
-
18
- attribute :address_id
19
- attribute :address_street
20
- end
21
- end
22
-
23
8
  setup.relation(:addresses)
24
9
 
25
10
  setup.relation(:users) do
@@ -36,7 +21,7 @@ describe 'Mappers / Renaming attributes' do
36
21
  it 'maps renamed attributes for a base relation' do
37
22
  setup.mappers do
38
23
  define(:users) do
39
- model name: 'User'
24
+ model name: 'Test::User'
40
25
 
41
26
  attribute :id, from: :_id
42
27
  attribute :name, from: :user_name
@@ -45,26 +30,26 @@ describe 'Mappers / Renaming attributes' do
45
30
 
46
31
  rom = setup.finalize
47
32
 
48
- User.send(:include, Equalizer.new(:id, :name))
33
+ Test::User.send(:include, Equalizer.new(:id, :name))
49
34
 
50
- rom.schema.users << { _id: 123, user_name: 'Jane' }
35
+ rom.relations.users << { _id: 123, user_name: 'Jane' }
51
36
 
52
37
  jane = rom.read(:users).to_a.first
53
38
 
54
- expect(jane).to eql(User.new(id: 123, name: 'Jane'))
39
+ expect(jane).to eql(Test::User.new(id: 123, name: 'Jane'))
55
40
  end
56
41
 
57
42
  it 'maps renamed attributes for a wrapped relation' do
58
43
  setup.mappers do
59
44
  define(:users) do
60
- model name: 'User'
45
+ model name: 'Test::User'
61
46
 
62
47
  attribute :id, from: :_id
63
48
  attribute :name, from: :user_name
64
49
  end
65
50
 
66
51
  define(:with_address, parent: :users) do
67
- model name: 'UserWithAddress'
52
+ model name: 'Test::UserWithAddress'
68
53
 
69
54
  attribute :id, from: :_id
70
55
  attribute :name, from: :user_name
@@ -78,31 +63,31 @@ describe 'Mappers / Renaming attributes' do
78
63
 
79
64
  rom = setup.finalize
80
65
 
81
- UserWithAddress.send(:include, Equalizer.new(:id, :name, :address))
66
+ Test::UserWithAddress.send(:include, Equalizer.new(:id, :name, :address))
82
67
 
83
- rom.schema.users << { _id: 123, user_name: 'Jane' }
84
- rom.schema.addresses << { _id: 123, address_id: 321,
85
- address_street: 'Street 1' }
68
+ rom.relations.users << { _id: 123, user_name: 'Jane' }
69
+ rom.relations.addresses <<
70
+ { _id: 123, address_id: 321, address_street: 'Street 1' }
86
71
 
87
72
  jane = rom.read(:users).with_address.first
88
73
 
89
74
  expect(jane).to eql(
90
- UserWithAddress.new(id: 123, name: 'Jane',
91
- address: { id: 321, street: 'Street 1' })
75
+ Test::UserWithAddress.new(id: 123, name: 'Jane',
76
+ address: { id: 321, street: 'Street 1' })
92
77
  )
93
78
  end
94
79
 
95
80
  it 'maps renamed attributes for a grouped relation' do
96
81
  setup.mappers do
97
82
  define(:users) do
98
- model name: 'User'
83
+ model name: 'Test::User'
99
84
 
100
85
  attribute :id, from: :_id
101
86
  attribute :name, from: :user_name
102
87
  end
103
88
 
104
89
  define(:with_addresses, parent: :users) do
105
- model name: 'UserWithAddresses'
90
+ model name: 'Test::UserWithAddresses'
106
91
 
107
92
  attribute :id, from: :_id
108
93
  attribute :name, from: :user_name
@@ -116,18 +101,18 @@ describe 'Mappers / Renaming attributes' do
116
101
 
117
102
  rom = setup.finalize
118
103
 
119
- UserWithAddresses.send(:include, Equalizer.new(:id, :name, :addresses))
104
+ Test::UserWithAddresses.send(:include, Equalizer.new(:id, :name, :addresses))
120
105
 
121
- rom.schema.users << { _id: 123, user_name: 'Jane' }
122
- rom.schema.addresses << { _id: 123, address_id: 321,
123
- address_street: 'Street 1' }
124
- rom.schema.addresses << { _id: 123, address_id: 654,
125
- address_street: 'Street 2' }
106
+ rom.relations.users << { _id: 123, user_name: 'Jane' }
107
+ rom.relations.addresses <<
108
+ { _id: 123, address_id: 321, address_street: 'Street 1' }
109
+ rom.relations.addresses <<
110
+ { _id: 123, address_id: 654, address_street: 'Street 2' }
126
111
 
127
112
  jane = rom.read(:users).with_addresses.first
128
113
 
129
114
  expect(jane).to eql(
130
- UserWithAddresses.new(
115
+ Test::UserWithAddresses.new(
131
116
  id: 123,
132
117
  name: 'Jane',
133
118
  addresses: [{ id: 321, street: 'Street 1' },
@@ -1,32 +1,23 @@
1
1
  require 'spec_helper'
2
+ require 'rom/memory'
2
3
 
3
4
  describe 'Mappers / Symbolizing atributes' do
4
- let(:setup) { ROM.setup(memory: 'memory://test') }
5
+ let(:setup) { ROM.setup(:memory) }
5
6
  let(:rom) { setup.finalize }
6
7
 
7
8
  before do
8
- setup.schema do
9
- base_relation(:users) do
10
- repository :memory
11
-
12
- attribute 'user_id'
13
- attribute 'first_name'
14
- attribute 'email'
15
- end
16
-
17
- base_relation(:tasks) do
18
- repository :memory
19
-
20
- attribute 'title'
21
- attribute 'task_priority'
22
- attribute 'task_description'
23
- end
24
- end
9
+ setup.relation(:users)
10
+ setup.relation(:tasks)
25
11
  end
26
12
 
27
13
  it 'automatically maps all attributes using top-level settings' do
28
- setup.mappers do
29
- define(:users, symbolize_keys: true, inherit_header: false, prefix: 'user') do
14
+ module Test
15
+ class UserMapper < ROM::Mapper
16
+ relation :users
17
+
18
+ symbolize_keys true
19
+ prefix 'user'
20
+
30
21
  attribute :id
31
22
 
32
23
  wrap :details, prefix: 'first' do
@@ -39,7 +30,7 @@ describe 'Mappers / Symbolizing atributes' do
39
30
  end
40
31
  end
41
32
 
42
- rom.schema.users << {
33
+ rom.relations.users << {
43
34
  'user_id' => 123,
44
35
  'first_name' => 'Jane',
45
36
  'email' => 'jane@doe.org'
@@ -53,8 +44,11 @@ describe 'Mappers / Symbolizing atributes' do
53
44
  end
54
45
 
55
46
  it 'automatically maps all attributes using settings for wrap block' do
56
- setup.mappers do
57
- define(:tasks, symbolize_keys: true) do
47
+ module Test
48
+ class TaskMapper < ROM::Mapper
49
+ relation :tasks
50
+ symbolize_keys true
51
+
58
52
  attribute :title
59
53
 
60
54
  wrap :details, prefix: 'task' do
@@ -64,7 +58,7 @@ describe 'Mappers / Symbolizing atributes' do
64
58
  end
65
59
  end
66
60
 
67
- rom.schema.tasks << {
61
+ rom.relations.tasks << {
68
62
  'title' => 'Task One',
69
63
  'task_priority' => 1,
70
64
  'task_description' => 'It is a task'