Class: CouchTap::Destroyers::Table
- Inherits:
-
Object
- Object
- CouchTap::Destroyers::Table
- Defined in:
- lib/couch_tap/destroyers/table.rb
Overview
The table destroyer will go through a table definition and make sure that all rows that belong to the document’s id are deleted from the system.
It’ll automatically go through each collection definition and recursively ensure that everything has been cleaned up.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#primary_keys ⇒ Object
readonly
Returns the value of attribute primary_keys.
Instance Method Summary collapse
-
#collection(field, opts = {}, &block) ⇒ Object
DSL methods.
-
#column(*args) ⇒ Object
Dummy helper methods.
- #data ⇒ Object
- #document ⇒ Object (also: #doc)
- #execute ⇒ Object
- #handler ⇒ Object
-
#initialize(parent, name, opts = {}, &block) ⇒ Table
constructor
A new instance of Table.
-
#key_filter ⇒ Object
Unlike building new rows, delete only requires the main primary key to be available.
Constructor Details
#initialize(parent, name, opts = {}, &block) ⇒ Table
Returns a new instance of Table.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/couch_tap/destroyers/table.rb', line 17 def initialize(parent, name, opts = {}, &block) @_collections = [] @parent = parent @name = name @primary_keys = parent.primary_keys.dup # As we're deleting, only assign the primary key for the first table if @primary_keys.empty? @primary_keys << (opts[:primary_key] || "#{@name.to_s.singularize}_id").to_sym end instance_eval(&block) if block_given? end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/couch_tap/destroyers/table.rb', line 15 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
15 16 17 |
# File 'lib/couch_tap/destroyers/table.rb', line 15 def parent @parent end |
#primary_keys ⇒ Object (readonly)
Returns the value of attribute primary_keys.
15 16 17 |
# File 'lib/couch_tap/destroyers/table.rb', line 15 def primary_keys @primary_keys end |
Instance Method Details
#collection(field, opts = {}, &block) ⇒ Object
DSL methods
54 55 56 |
# File 'lib/couch_tap/destroyers/table.rb', line 54 def collection(field, opts = {}, &block) @_collections << Collection.new(self, opts, &block) end |
#column(*args) ⇒ Object
Dummy helper methods
60 61 62 |
# File 'lib/couch_tap/destroyers/table.rb', line 60 def column(*args) nil end |
#data ⇒ Object
69 70 71 |
# File 'lib/couch_tap/destroyers/table.rb', line 69 def data {} end |
#document ⇒ Object Also known as: doc
64 65 66 |
# File 'lib/couch_tap/destroyers/table.rb', line 64 def document {} end |
#execute ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/couch_tap/destroyers/table.rb', line 33 def execute dataset = handler.database[name] dataset.where(key_filter).delete @_collections.each do |collection| collection.execute end end |
#handler ⇒ Object
41 42 43 |
# File 'lib/couch_tap/destroyers/table.rb', line 41 def handler parent.handler end |
#key_filter ⇒ Object
Unlike building new rows, delete only requires the main primary key to be available.
46 47 48 49 50 |
# File 'lib/couch_tap/destroyers/table.rb', line 46 def key_filter { @primary_keys.first => handler.id } end |