Module: Couch::Database::Bulk
- Included in:
- Couch::Database
- Defined in:
- lib/couch/database.rb
Overview
-- document bulk methods
Class Method Summary collapse
Instance Method Summary collapse
- #async(&block) ⇒ Object
- #create(doc) ⇒ Object
- #destroy(doc) ⇒ Object
- #do_bulked(&block) ⇒ Object
- #flush ⇒ Object
- #read(id) ⇒ Object
- #update(doc) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
74 75 76 |
# File 'lib/couch/database.rb', line 74 def self.included(klass) klass.send :protected, :do_bulked end |
Instance Method Details
#async(&block) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/couch/database.rb', line 102 def async(&block) if @bulk yield else do_bulked(&block) end end |
#create(doc) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/couch/database.rb', line 78 def create(doc) return super unless @bulk raise unless doc.new_record? doc.id ||= UUID.new.generate @bulk << doc end |
#destroy(doc) ⇒ Object
97 98 99 100 |
# File 'lib/couch/database.rb', line 97 def destroy(doc) flush super end |
#do_bulked(&block) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/couch/database.rb', line 110 def do_bulked(&block) @bulk = [] yield flush ensure @bulk = nil end |
#flush ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/couch/database.rb', line 118 def flush return unless @bulk bulk = @bulk @bulk = nil docs_by_id = {} bulk.each do |doc| docs_by_id[doc.id] = doc end post("_bulk_docs", :docs => bulk). each do |rev_data| id, rev = rev_data[:id], rev_data[:rev] docs_by_id[id].send :update_rev, rev end end |
#read(id) ⇒ Object
87 88 89 90 |
# File 'lib/couch/database.rb', line 87 def read(id) flush super end |
#update(doc) ⇒ Object
92 93 94 95 |
# File 'lib/couch/database.rb', line 92 def update(doc) flush super end |