cassandra-cql 1.1.3 → 1.1.4

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.
@@ -35,8 +35,10 @@ module CassandraCQL
35
35
  }
36
36
  end
37
37
  end
38
-
38
+
39
39
  class Result
40
+ include Enumerable
41
+
40
42
  attr_reader :result, :schema, :cursor
41
43
 
42
44
  def initialize(result)
@@ -44,11 +46,11 @@ module CassandraCQL
44
46
  @schema = ResultSchema.new(result.schema) if rows?
45
47
  @cursor = 0
46
48
  end
47
-
49
+
48
50
  def void?
49
51
  @result.type == CassandraCQL::Thrift::CqlResultType::VOID
50
52
  end
51
-
53
+
52
54
  def int?
53
55
  @result.type == CassandraCQL::Thrift::CqlResultType::INT
54
56
  end
@@ -61,12 +63,20 @@ module CassandraCQL
61
63
  @result.rows.size
62
64
  end
63
65
 
66
+ alias_method :size, :rows
67
+ alias_method :count, :rows
68
+ alias_method :length, :rows
69
+
64
70
  def cursor=(cursor)
65
71
  @cursor = cursor.to_i
66
72
  rescue Exception => e
67
73
  raise Error::InvalidCursor, e.to_s
68
74
  end
69
-
75
+
76
+ def each
77
+ fetch { |row| yield row }
78
+ end
79
+
70
80
  def fetch_row
71
81
  case @result.type
72
82
  when CassandraCQL::Thrift::CqlResultType::ROWS
@@ -113,7 +123,7 @@ module CassandraCQL
113
123
  end
114
124
  end
115
125
  end
116
-
126
+
117
127
  def fetch_array
118
128
  if block_given?
119
129
  while row = fetch_row
@@ -90,7 +90,7 @@ module CassandraCQL
90
90
  obj.strftime('%Y-%m-%d')
91
91
  elsif obj.kind_of?(Time)
92
92
  (obj.to_f * 1000).to_i
93
- elsif obj.kind_of?(UUID)
93
+ elsif obj.kind_of?(SimpleUUID::UUID)
94
94
  obj.to_guid
95
95
  # There are corner cases where this is an invalid assumption but they are extremely rare.
96
96
  # The alternative is to make the user pack the data on their own .. let's not do that until we have to
@@ -15,5 +15,5 @@ limitations under the License.
15
15
  =end
16
16
 
17
17
  module CassandraCQL
18
- VERSION = "1.1.3"
18
+ VERSION = "1.1.4"
19
19
  end
@@ -57,30 +57,42 @@ describe "row results" do
57
57
  it "should have two rows" do
58
58
  @result.rows.should eq(2)
59
59
  end
60
-
60
+
61
+ it "should know size of rows" do
62
+ @result.size.should eq(2)
63
+ end
64
+
65
+ it "should know count of rows" do
66
+ @result.count.should eq(2)
67
+ end
68
+
69
+ it "should know length of rows" do
70
+ @result.length.should eq(2)
71
+ end
72
+
61
73
  context "initialize" do
62
74
  it "should have a cursor set to 0" do
63
75
  @result.instance_variable_get(:@cursor).should eq(0)
64
76
  end
65
-
77
+
66
78
  it "should have a result" do
67
79
  @result.instance_variable_get(:@result).should be_kind_of(CassandraCQL::Thrift::CqlResult)
68
80
  end
69
81
  end
70
-
82
+
71
83
  context "setting the cursor" do
72
84
  it "should set the cursor" do
73
85
  expect {
74
86
  @result.cursor = 15
75
87
  }.to_not raise_error
76
88
  @result.instance_variable_get(:@cursor).should eq(15)
77
- end
89
+ end
78
90
 
79
91
  it "should not set the cursor" do
80
92
  expect {
81
93
  @result.cursor = Object
82
94
  }.to raise_error(CassandraCQL::Error::InvalidCursor)
83
- end
95
+ end
84
96
  end
85
97
 
86
98
  context "fetching a single row" do
@@ -90,12 +102,12 @@ describe "row results" do
90
102
 
91
103
  @result.fetch_row.should be_kind_of(Row)
92
104
  @result.instance_variable_get(:@cursor).should eq(2)
93
-
105
+
94
106
  @result.fetch_row.should be_nil
95
107
  @result.instance_variable_get(:@cursor).should eq(2)
96
108
  end
97
109
  end
98
-
110
+
99
111
  context "resetting cursor should fetch the same row" do
100
112
  it "should return the same row" do
101
113
  @result.instance_variable_get(:@cursor).should eq(0)
@@ -104,7 +116,7 @@ describe "row results" do
104
116
  arr.should eq(@result.fetch_array)
105
117
  end
106
118
  end
107
-
119
+
108
120
  context "fetch without a block" do
109
121
  it "should return a row twice then nil" do
110
122
  @result.fetch.should be_kind_of(Row)
@@ -112,12 +124,12 @@ describe "row results" do
112
124
 
113
125
  @result.fetch.should be_kind_of(Row)
114
126
  @result.instance_variable_get(:@cursor).should eq(2)
115
-
127
+
116
128
  @result.fetch.should be_nil
117
129
  @result.instance_variable_get(:@cursor).should eq(2)
118
130
  end
119
131
  end
120
-
132
+
121
133
  context "fetch with a block" do
122
134
  it "fetched count should equal the number of rows" do
123
135
  counter = 0
@@ -138,7 +150,7 @@ describe "row results" do
138
150
  arr.should eq(row.column_values)
139
151
  end
140
152
  end
141
-
153
+
142
154
  context "fetch_array_with a block" do
143
155
  it "fetched count should equal the number of rows" do
144
156
  counter = 0
@@ -164,7 +176,7 @@ describe "row results" do
164
176
  @result.fetch_hash.should be_nil
165
177
  end
166
178
  end
167
-
179
+
168
180
  context "fetch_hash_with a block" do
169
181
  it "should iterate rows() times and return hashes" do
170
182
  counter = 0
@@ -175,4 +187,20 @@ describe "row results" do
175
187
  counter.should eq(@result.rows)
176
188
  end
177
189
  end
190
+
191
+ describe "#each" do
192
+ it "yields each row as a hash" do
193
+ rows = []
194
+ @result.each { |row| rows << row }
195
+ rows.each do |row|
196
+ row.should be_instance_of(CassandraCQL::Row)
197
+ row.column_names.should eq(['col1', 'col2', 'col3', 'col4'])
198
+ end
199
+ end
200
+ end
201
+
202
+ it "is enumerable" do
203
+ @result.class.ancestors.should include(Enumerable)
204
+ @result.map { |row| row['col1'] }.should eq(['val1', nil])
205
+ end
178
206
  end
@@ -130,6 +130,14 @@ describe "cast_to_cql" do
130
130
  end
131
131
  end
132
132
 
133
+ context "with a SimpleUUID::UUID object" do
134
+ it "should return the guid" do
135
+ uuid = SimpleUUID::UUID.new
136
+ guid = Statement.cast_to_cql(uuid)
137
+ guid.should eq(uuid.to_guid)
138
+ end
139
+ end
140
+
133
141
  context "with a String without quotes" do
134
142
  it "should return a copy of itself" do
135
143
  str = "This is a string"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassandra-cql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-10 00:00:00.000000000 Z
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -209,9 +209,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
209
  - - ! '>='
210
210
  - !ruby/object:Gem::Version
211
211
  version: '0'
212
- segments:
213
- - 0
214
- hash: -2241138987958010983
215
212
  required_rubygems_version: !ruby/object:Gem::Requirement
216
213
  none: false
217
214
  requirements: