Class: FAP::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/fap/collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(relation, node) ⇒ Collection

Returns a new instance of Collection.



5
6
7
8
9
10
11
# File 'lib/fap/collection.rb', line 5

def initialize relation, node
  @nodes = []
  @fetched = false
  @node = node
  @relation = relation
  @klass = FAP.constantize relation.klass
end

Instance Method Details

#eachObject



13
14
15
16
17
18
19
20
# File 'lib/fap/collection.rb', line 13

def each
  fetch_nodes unless @fetched
  @nodes.map do |node|
    obj = @klass.new nil
    obj.from_relation @relation, node
    yield obj
  end
end