Class: CouchTap::Builders::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/couch_tap/builders/collection.rb

Overview

Collection Builder. Go through each sub-table definition and recursively prepare the data ready to be inserted into the database.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, field, opts = {}, &block) ⇒ Collection

Returns a new instance of Collection.



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

def initialize(parent, field, opts = {}, &block)
  @_tables = []
  @parent  = parent
  @field   = field

  instance_eval(&block)
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



12
13
14
# File 'lib/couch_tap/builders/collection.rb', line 12

def field
  @field
end

#parentObject (readonly)

Returns the value of attribute parent.



12
13
14
# File 'lib/couch_tap/builders/collection.rb', line 12

def parent
  @parent
end

Instance Method Details

#executeObject



22
23
24
25
26
# File 'lib/couch_tap/builders/collection.rb', line 22

def execute
  @_tables.each do |table|
    table.execute
  end
end

#table(name, opts = {}, &block) ⇒ Object

DSL Methods



30
31
32
33
34
35
36
# File 'lib/couch_tap/builders/collection.rb', line 30

def table(name, opts = {}, &block)
  source = parent.data[field.to_s] || []
  source.each do |item|
    options = opts.merge(:data => item)
    @_tables << Table.new(parent, name, options, &block)
  end
end