class Epiphy::Repository::Cursor
Custom enumetable on top of RethinkDB cursor so we can convert the hash to the Entity
object.
For the ReQL that returns a cursor, we won’t grab the array and convet the hash into Entity
object. Instead, we will use aan enumerable and the Repository
leverage it to convert the hash to entity object.
An cursor can be convert to an arrya with ‘.to_a` method
@see Epiphy::Repository#all @see Epiphy::Adapter::Rethinkdb#all
@example
cursor = r.table()... all = Epiphy::Repository::Cursor.new(cursor) do |item| item = transform_item_with_something_if_need end
@since 0.1.0 @api public
Attributes
cursor[R]
transform[R]
Public Class Methods
new(cursor, &transform)
click to toggle source
# File lib/epiphy/repository/cursor.rb, line 28 def initialize(cursor, &transform) @cursor = cursor @transform = transform end
Public Instance Methods
each() { |item| ... }
click to toggle source
# File lib/epiphy/repository/cursor.rb, line 33 def each raise ArgumentError, 'Missing a block to enumate cursor' unless block_given? @cursor.each do |item| item = @transform.call item yield item #if block_given? #block.call person #else #yield person #end end end