lib/airspace/reader.rb in airspace-1.0.0 vs lib/airspace/reader.rb in airspace-1.0.1
- old
+ new
@@ -64,16 +64,20 @@
freeze
end
def pages
+ return [] unless page_count.positive?
+
store.chunks(key, chunk_count).map do |chunk|
chunk.map { |r| serializer.deserialize_row(r) }
end
end
def page(number)
+ return [] unless within_bounds?(number)
+
page_index = number - 1
location = chunker.locate(page_index)
chunk = store.chunk(key, location.chunk_index)
chunk[location.page_index].map { |r| serializer.deserialize_row(r) }
@@ -82,9 +86,13 @@
def delete
store.delete(key, page_count)
end
private
+
+ def within_bounds?(number)
+ page_count.positive? && number.positive? && number <= page_count
+ end
def store
::Airspace::Store.new(client)
end
end