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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 814ed4ee8e88aefe0b86817fb61169b1e35f94ba
4
- data.tar.gz: 999033f0c7c9afb931cf8cb18a333026e8b3efae
3
+ metadata.gz: a0566fa80999c8309f81d1794f0a46cf0bd388ba
4
+ data.tar.gz: e826953ae0a313183e1982f0b9a6a2d7d3cd033b
5
5
  SHA512:
6
- metadata.gz: fac52ead0bcbbe6c2404b59b8520facb25374050e8dbf6d98964aab073896fe8dca05f589d91ad34769f169ca284006f14685d2b4808e18571794bf0a8fd635c
7
- data.tar.gz: 866166744b5e93f3fca5c623414579814efd7d6765d2cc695af3437e3b233f720e52f403f7f98b9cb288bc548e45e015f6ab3035692a4a05f57e6bdcbc893d69
6
+ metadata.gz: 5854435a14df8841408d3f8b3b2c4fc7226d7050e68198ca148775db4b06fe724c49bca5a54e253d8a81fc9adc428ab9b471fce440f3865f6ceaf0b3639bf07b
7
+ data.tar.gz: f375e69352c707c5ea33e512c1a337f0527deab4d864167831af24cf7937b62091bb9e907ca5f7fc4920efb507d54cd6095b812d013c46b6d9db732bcc1c9be0
@@ -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]
@@ -96,7 +96,16 @@ module ROM
96
96
  def call
97
97
  Loaded.new(relation)
98
98
  end
99
- alias_method :[], :call
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
@@ -6,6 +6,13 @@ module ROM
6
6
  class Loaded
7
7
  include Enumerable
8
8
 
9
+ # Coerce loaded relation to an array
10
+ #
11
+ # @return [Array]
12
+ #
13
+ # @api public
14
+ alias_method :to_ary, :to_a
15
+
9
16
  # Source relation
10
17
  #
11
18
  # @return [Relation]
@@ -64,7 +64,7 @@ module ROM
64
64
  end
65
65
 
66
66
  def allow?(value)
67
- allow.none? || allow.include?(value)
67
+ allow.empty? || allow.include?(value)
68
68
  end
69
69
  end
70
70
 
data/lib/rom/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ROM
2
- VERSION = '0.6.0.beta1'.freeze
2
+ VERSION = '0.6.0.beta2'.freeze
3
3
  end
@@ -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.beta1
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-26 00:00:00.000000000 Z
11
+ date: 2015-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: transproc