Class: CouchTap::DocumentHandler
- Inherits:
-
Object
- Object
- CouchTap::DocumentHandler
- Defined in:
- lib/couch_tap/document_handler.rb
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#document ⇒ Object
Returns the value of attribute document.
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#id ⇒ Object
Returns the value of attribute id.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Instance Method Summary collapse
- #database ⇒ Object
- #delete(document) ⇒ Object
-
#handler ⇒ Object
END DSL.
- #handles?(doc) ⇒ Boolean
-
#initialize(changes, filter = {}, &block) ⇒ DocumentHandler
constructor
A new instance of DocumentHandler.
- #insert(document) ⇒ Object
- #key_filter ⇒ Object
- #primary_keys ⇒ Object
- #schema(name) ⇒ Object
-
#table(name, opts = {}, &block) ⇒ Object
Handle a table definition.
Constructor Details
#initialize(changes, filter = {}, &block) ⇒ DocumentHandler
Returns a new instance of DocumentHandler.
8 9 10 11 12 13 |
# File 'lib/couch_tap/document_handler.rb', line 8 def initialize(changes, filter = {}, &block) @changes = changes @filter = filter @_block = block @mode = nil end |
Instance Attribute Details
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
5 6 7 |
# File 'lib/couch_tap/document_handler.rb', line 5 def changes @changes end |
#document ⇒ Object
Returns the value of attribute document.
6 7 8 |
# File 'lib/couch_tap/document_handler.rb', line 6 def document @document end |
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
5 6 7 |
# File 'lib/couch_tap/document_handler.rb', line 5 def filter @filter end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/couch_tap/document_handler.rb', line 6 def id @id end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
5 6 7 |
# File 'lib/couch_tap/document_handler.rb', line 5 def mode @mode end |
Instance Method Details
#database ⇒ Object
67 68 69 |
# File 'lib/couch_tap/document_handler.rb', line 67 def database changes.database end |
#delete(document) ⇒ Object
57 58 59 60 61 |
# File 'lib/couch_tap/document_handler.rb', line 57 def delete(document) @mode = :delete self.document = document instance_eval(&@_block) end |
#handler ⇒ Object
END DSL
35 36 37 |
# File 'lib/couch_tap/document_handler.rb', line 35 def handler self end |
#handles?(doc) ⇒ Boolean
15 16 17 18 19 20 |
# File 'lib/couch_tap/document_handler.rb', line 15 def handles?(doc) @filter.each do |k,v| return false if doc[k.to_s] != v end true end |
#insert(document) ⇒ Object
51 52 53 54 55 |
# File 'lib/couch_tap/document_handler.rb', line 51 def insert(document) @mode = :insert self.document = document instance_eval(&@_block) end |
#key_filter ⇒ Object
43 44 45 |
# File 'lib/couch_tap/document_handler.rb', line 43 def key_filter {} end |
#primary_keys ⇒ Object
39 40 41 |
# File 'lib/couch_tap/document_handler.rb', line 39 def primary_keys [] end |
#schema(name) ⇒ Object
63 64 65 |
# File 'lib/couch_tap/document_handler.rb', line 63 def schema(name) changes.schema(name) end |
#table(name, opts = {}, &block) ⇒ Object
Handle a table definition.
25 26 27 28 29 30 31 |
# File 'lib/couch_tap/document_handler.rb', line 25 def table(name, opts = {}, &block) if @mode == :delete Destroyers::Table.new(self, name, opts, &block).execute elsif @mode == :insert Builders::Table.new(self, name, opts, &block).execute end end |