Class: Epiphy::Repository::Cursor

Inherits:
Object
  • Object
show all
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

Examples:

cursor = r.table()...
all = Epiphy::Repository::Cursor.new(cursor) do |item|
  item = transform_item_with_something_if_need
end

See Also:

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cursor, &transform) ⇒ Cursor

Returns a new instance of Cursor.

Since:

  • 0.1.0



28
29
30
31
# File 'lib/epiphy/repository/cursor.rb', line 28

def initialize(cursor, &transform)
  @cursor = cursor  
  @transform = transform 
end

Instance Attribute Details

#cursorObject (readonly)

Since:

  • 0.1.0



26
27
28
# File 'lib/epiphy/repository/cursor.rb', line 26

def cursor
  @cursor
end

#transformObject (readonly)

Since:

  • 0.1.0



26
27
28
# File 'lib/epiphy/repository/cursor.rb', line 26

def transform
  @transform
end

Instance Method Details

#eachObject

Raises:

  • (ArgumentError)

Since:

  • 0.1.0



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