Class: CouchTap::Builders::Collection
- Inherits:
-
Object
- Object
- CouchTap::Builders::Collection
- 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
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(parent, field, opts = {}, &block) ⇒ Collection
constructor
A new instance of Collection.
-
#table(name, opts = {}, &block) ⇒ Object
DSL Methods.
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
#field ⇒ Object (readonly)
Returns the value of attribute field.
12 13 14 |
# File 'lib/couch_tap/builders/collection.rb', line 12 def field @field end |
#parent ⇒ Object (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
#execute ⇒ Object
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| = opts.merge(:data => item) @_tables << Table.new(parent, name, , &block) end end |