Class: CouchTap::DocumentHandler

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#changesObject (readonly)

Returns the value of attribute changes.



5
6
7
# File 'lib/couch_tap/document_handler.rb', line 5

def changes
  @changes
end

#documentObject

Returns the value of attribute document.



6
7
8
# File 'lib/couch_tap/document_handler.rb', line 6

def document
  @document
end

#filterObject (readonly)

Returns the value of attribute filter.



5
6
7
# File 'lib/couch_tap/document_handler.rb', line 5

def filter
  @filter
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/couch_tap/document_handler.rb', line 6

def id
  @id
end

#modeObject (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

#databaseObject



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

#handlerObject

END DSL



35
36
37
# File 'lib/couch_tap/document_handler.rb', line 35

def handler
  self
end

#handles?(doc) ⇒ Boolean

Returns:

  • (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_filterObject



43
44
45
# File 'lib/couch_tap/document_handler.rb', line 43

def key_filter
  {}
end

#primary_keysObject



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