rom 0.6.0.beta1 → 0.6.0.beta2
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 +4 -4
- data/lib/rom/relation/curried.rb +10 -0
- data/lib/rom/relation/lazy.rb +19 -1
- data/lib/rom/relation/loaded.rb +7 -0
- data/lib/rom/support/options.rb +1 -1
- data/lib/rom/version.rb +1 -1
- data/spec/unit/rom/relation/lazy_spec.rb +51 -0
- data/spec/unit/rom/relation/loaded_spec.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0566fa80999c8309f81d1794f0a46cf0bd388ba
|
4
|
+
data.tar.gz: e826953ae0a313183e1982f0b9a6a2d7d3cd033b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5854435a14df8841408d3f8b3b2c4fc7226d7050e68198ca148775db4b06fe724c49bca5a54e253d8a81fc9adc428ab9b471fce440f3865f6ceaf0b3639bf07b
|
7
|
+
data.tar.gz: f375e69352c707c5ea33e512c1a337f0527deab4d864167831af24cf7937b62091bb9e907ca5f7fc4920efb507d54cd6095b812d013c46b6d9db732bcc1c9be0
|
data/lib/rom/relation/curried.rb
CHANGED
@@ -28,6 +28,16 @@ module ROM
|
|
28
28
|
end
|
29
29
|
alias_method :[], :call
|
30
30
|
|
31
|
+
# @api public
|
32
|
+
def to_a
|
33
|
+
raise(
|
34
|
+
ArgumentError,
|
35
|
+
"#{relation.class}##{name} arity is #{arity} " \
|
36
|
+
"(#{curry_args.size} args given)"
|
37
|
+
)
|
38
|
+
end
|
39
|
+
alias_method :to_ary, :to_a
|
40
|
+
|
31
41
|
# Return if this lazy relation is curried
|
32
42
|
#
|
33
43
|
# @return [true]
|
data/lib/rom/relation/lazy.rb
CHANGED
@@ -96,7 +96,16 @@ module ROM
|
|
96
96
|
def call
|
97
97
|
Loaded.new(relation)
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
|
+
# Yield relation tuples
|
101
|
+
#
|
102
|
+
# @yield [Object]
|
103
|
+
#
|
104
|
+
# @api public
|
105
|
+
def each(&block)
|
106
|
+
return to_enum unless block
|
107
|
+
to_a.each { |tuple| yield(tuple) }
|
108
|
+
end
|
100
109
|
|
101
110
|
# Delegate to loaded relation and return one object
|
102
111
|
#
|
@@ -120,6 +129,15 @@ module ROM
|
|
120
129
|
call.one!
|
121
130
|
end
|
122
131
|
|
132
|
+
# Return first tuple from a relation coerced to an array
|
133
|
+
#
|
134
|
+
# @return [Object]
|
135
|
+
#
|
136
|
+
# @api public
|
137
|
+
def first
|
138
|
+
to_a.first
|
139
|
+
end
|
140
|
+
|
123
141
|
# @api private
|
124
142
|
def respond_to_missing?(name, include_private = false)
|
125
143
|
methods.include?(name) || super
|
data/lib/rom/relation/loaded.rb
CHANGED
data/lib/rom/support/options.rb
CHANGED
data/lib/rom/version.rb
CHANGED
@@ -119,6 +119,57 @@ describe ROM::Relation::Lazy do
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
+
describe '#first' do
|
123
|
+
it 'return first tuple' do
|
124
|
+
expect(users.first).to eql(name: 'Joe', email: 'joe@doe.org')
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'raises when relation is curried and arity does not match' do
|
128
|
+
expect { users.by_name.first }.to raise_error(
|
129
|
+
ArgumentError, 'ROM::Relation[Users]#by_name arity is 1 (0 args given)'
|
130
|
+
)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#each' do
|
135
|
+
it 'yields relation tuples' do
|
136
|
+
result = []
|
137
|
+
users.each { |tuple| result << tuple }
|
138
|
+
expect(result).to match_array([
|
139
|
+
{ name: 'Jane', email: 'jane@doe.org' },
|
140
|
+
{ name: 'Joe', email: 'joe@doe.org' }
|
141
|
+
])
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'returns an enumerator if block is not provided' do
|
145
|
+
expect(users.each.to_a).to match_array([
|
146
|
+
{ name: 'Jane', email: 'jane@doe.org' },
|
147
|
+
{ name: 'Joe', email: 'joe@doe.org' }
|
148
|
+
])
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'raises when relation is curried and arity does not match' do
|
152
|
+
expect { users.by_name.each {} }.to raise_error(
|
153
|
+
ArgumentError, 'ROM::Relation[Users]#by_name arity is 1 (0 args given)'
|
154
|
+
)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '#to_ary' do
|
159
|
+
it 'returns an array with relation tuples' do
|
160
|
+
expect(users.to_ary).to match_array([
|
161
|
+
{ name: 'Jane', email: 'jane@doe.org' },
|
162
|
+
{ name: 'Joe', email: 'joe@doe.org' }
|
163
|
+
])
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'raises when relation is curried and arity does not match' do
|
167
|
+
expect { users.by_name.to_ary }.to raise_error(
|
168
|
+
ArgumentError, 'ROM::Relation[Users]#by_name arity is 1 (0 args given)'
|
169
|
+
)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
122
173
|
describe '#>>' do
|
123
174
|
it 'composes two relations' do
|
124
175
|
other = users.by_name('Jane') >> tasks.for_users
|
@@ -22,6 +22,15 @@ describe ROM::Relation::Loaded do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
describe '#to_ary' do
|
26
|
+
it 'coerces to an array' do
|
27
|
+
expect(users.to_ary).to match_array([
|
28
|
+
{ name: 'Jane', email: 'jane@doe.org' },
|
29
|
+
{ name: 'Joe', email: 'joe@doe.org' }
|
30
|
+
])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
25
34
|
it_behaves_like 'a relation that returns one tuple' do
|
26
35
|
let(:relation) { users }
|
27
36
|
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: 0.6.0.
|
4
|
+
version: 0.6.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: transproc
|