Class: Epiphy::Repository::Cursor
- Inherits:
-
Object
- Object
- Epiphy::Repository::Cursor
- Includes:
- Enumerable
- Defined in:
- lib/epiphy/repository/cursor.rb
Overview
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
Instance Attribute Summary collapse
- #cursor ⇒ Object readonly
- #transform ⇒ Object readonly
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(cursor, &transform) ⇒ Cursor
constructor
A new instance of Cursor.
Constructor Details
#initialize(cursor, &transform) ⇒ Cursor
Returns a new instance of Cursor.
28 29 30 31 |
# File 'lib/epiphy/repository/cursor.rb', line 28 def initialize(cursor, &transform) @cursor = cursor @transform = transform end |
Instance Attribute Details
#cursor ⇒ Object (readonly)
26 27 28 |
# File 'lib/epiphy/repository/cursor.rb', line 26 def cursor @cursor end |
#transform ⇒ Object (readonly)
26 27 28 |
# File 'lib/epiphy/repository/cursor.rb', line 26 def transform @transform end |
Instance Method Details
#each ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 |