Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use in-memory row for Dictionary#first and #last when loaded

  • Loading branch information...
commit 53081954f77e689c3ca0bbbe4097b0077f49cb72 1 parent 9de47f2
@outoftime outoftime authored
View
11 lib/cequel/model/readable_dictionary.rb
@@ -98,11 +98,18 @@ def slice(*columns)
end
def first
- slice(:first => 1).first
+ @loaded ? @row.first : slice(:first => 1).first
end
def last
- slice(:last => 1).first
+ if @loaded
+ unless @row.empty?
+ key = @row.keys.last
+ [key, @row[key]]
+ end
+ else
+ slice(:last => 1).first
+ end
end
def key?(column)
View
12 spec/shared/readable_dictionary.rb
@@ -134,6 +134,18 @@
end
end
+ describe '#first' do
+ it 'should return first element in memory' do
+ dictionary.first.should == [uuid1, 1]
+ end
+ end
+
+ describe '#last' do
+ it 'should return first element in memory' do
+ dictionary.last.should == [uuid3, 3]
+ end
+ end
+
describe '#keys' do
it 'should return keys from memory' do
dictionary.keys.should == [uuid1, uuid2, uuid3]
Please sign in to comment.
Something went wrong with that request. Please try again.