Class: Mongo::Collection

Inherits:
Object show all
Defined in:
lib/goat/mongo.rb

Instance Method Summary collapse

Instance Method Details

#notify_update_or_save(more_info) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/goat/mongo.rb', line 8

def notify_update_or_save(more_info)
  notif = more_info.merge(
    'type' => 'mongo_change',
    'db' => self.db.name,
    'collection' => self.name
  )

  Goat::NotificationCenter.notify(notif)
end

#old_saveObject



5
# File 'lib/goat/mongo.rb', line 5

alias_method :old_save, :save

#old_updateObject



6
# File 'lib/goat/mongo.rb', line 6

alias_method :old_update, :update

#save(doc, opts = {}) ⇒ Object



18
19
20
21
# File 'lib/goat/mongo.rb', line 18

def save(doc, opts={})
  id = old_save(doc, opts)
  notify_update_or_save('_id' => id)
end

#update(sel, doc, opts = {}) ⇒ Object



23
24
25
26
# File 'lib/goat/mongo.rb', line 23

def update(sel, doc, opts={})
 old_update(sel, doc, opts)
 notify_update_or_save(sel)
end