Module: Mongoid::Heartbeat::Tracker
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/obscured-heartbeat/tracker.rb
Defined Under Namespace
Classes: Record
Instance Method Summary collapse
-
#add_heartbeat(event) ⇒ document
Adds heartbeat to the x_heartbeat collection for document.
-
#clear_heartbeats ⇒ documents
Clear heartbeats from the x_heartbeat collection for document.
-
#delete_heartbeat(id) ⇒ document
Delete an heartbeat from the x_heartbeat collection by id.
-
#edit_heartbeat(id, params = {}) ⇒ document
Edit an heartbeat from the x_heartbeat collection by id.
-
#find_heartbeats(params, options) ⇒ documents
Find heartbeats from the x_heartbeat collection for document.
-
#get_heartbeat(id) ⇒ document
Get an heartbeat from the x_heartbeat collection for document.
-
#get_heartbeats ⇒ documents
(also: #heartbeats)
Get heartbeats from the x_heartbeat collection for document by proprietor.
-
#search_heartbeats(text, options) ⇒ documents
Search heartbeats from the x_heartbeat collection for document.
Instance Method Details
#add_heartbeat(event) ⇒ document
Adds heartbeat to the x_heartbeat collection for document. This is only called on manually.
21 22 23 24 25 |
# File 'lib/obscured-heartbeat/tracker.rb', line 21 def add_heartbeat(event) Record.with(collection: "#{self.class.name.demodulize.downcase}_heartbeat") do |m| m.make!(event.merge(proprietor: { "#{self.class.name.demodulize.downcase}_id".to_sym => id })) end end |
#clear_heartbeats ⇒ documents
Clear heartbeats from the x_heartbeat collection for document. This is only called on manually.
126 127 128 129 130 |
# File 'lib/obscured-heartbeat/tracker.rb', line 126 def clear_heartbeats Record.with(collection: "#{self.class.name.demodulize.downcase}_heartbeat") do |m| m.where(proprietor: { "#{self.class.name.demodulize.downcase}_id".to_sym => id }).delete end end |
#delete_heartbeat(id) ⇒ document
Delete an heartbeat from the x_heartbeat collection by id. This is only called on manually.
113 114 115 116 117 |
# File 'lib/obscured-heartbeat/tracker.rb', line 113 def delete_heartbeat(id) Record.with(collection: "#{self.class.name.demodulize.downcase}_heartbeat") do |m| m.where(id: id).delete end end |
#edit_heartbeat(id, params = {}) ⇒ document
Edit an heartbeat from the x_heartbeat collection by id. This is only called on manually.
97 98 99 100 101 102 103 104 |
# File 'lib/obscured-heartbeat/tracker.rb', line 97 def edit_heartbeat(id, params = {}) Record.with(collection: "#{self.class.name.demodulize.downcase}_heartbeat") do |m| hb = m.where(id: id).first hb.hostname = params[:hostname] if params[:hostname] hb.save hb end end |
#find_heartbeats(params, options) ⇒ documents
Find heartbeats from the x_heartbeat collection for document. This is only called on manually.
62 63 64 65 66 |
# File 'lib/obscured-heartbeat/tracker.rb', line 62 def find_heartbeats(params, ) Record.with(collection: "#{self.class.name.demodulize.downcase}_heartbeat") do |m| m.by({ proprietor: { "#{self.class.name.demodulize.downcase}_id".to_sym => id } }.merge(params), ) end end |
#get_heartbeat(id) ⇒ document
Get an heartbeat from the x_heartbeat collection for document. This is only called on manually.
34 35 36 37 38 |
# File 'lib/obscured-heartbeat/tracker.rb', line 34 def get_heartbeat(id) Record.with(collection: "#{self.class.name.demodulize.downcase}_heartbeat") do |m| m.find(id) end end |
#get_heartbeats ⇒ documents Also known as: heartbeats
Get heartbeats from the x_heartbeat collection for document by proprietor. This is only called on manually.
48 49 50 51 52 |
# File 'lib/obscured-heartbeat/tracker.rb', line 48 def get_heartbeats Record.with(collection: "#{self.class.name.demodulize.downcase}_heartbeat") do |m| m.by(proprietor: { "#{self.class.name.demodulize.downcase}_id".to_sym => id }) end end |
#search_heartbeats(text, options) ⇒ documents
Search heartbeats from the x_heartbeat collection for document. This is only called on manually.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/obscured-heartbeat/tracker.rb', line 75 def search_heartbeats(text, ) limit = [:limit].blank? ? nil : [:limit].to_i skip = [:skip].blank? ? nil : [:skip].to_i order = [:order].blank? ? :created_at.desc : [:order] Record.with(collection: "#{self.class.name.demodulize.downcase}_heartbeat") do |m| criteria = m.full_text_search(text) criteria = criteria.order_by(order) if order criteria = criteria.limit(limit).skip(skip) docs = criteria.to_a docs end end |