Module: Mongoid::Heartbeat::Tracker

Extended by:
ActiveSupport::Concern
Defined in:
lib/obscured-heartbeat/tracker.rb

Defined Under Namespace

Classes: Record

Instance Method Summary collapse

Instance Method Details

#add_heartbeat(event) ⇒ document

Adds heartbeat to the x_heartbeat collection for document. This is only called on manually.

Examples:

Add heartbeat.

document.add_heartbeat

Returns:

  • (document)


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_heartbeatsdocuments

Clear heartbeats from the x_heartbeat collection for document. This is only called on manually.

Examples:

Get heartbeats.

document.clear_heartbeats

Returns:

  • (documents)


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.

Examples:

Get heartbeat.

document.delete_heartbeat(id)

Returns:

  • (document)


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.

Examples:

Get heartbeat.

document.edit_heartbeat(id, params)

Returns:

  • (document)


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.

Examples:

Get heartbeats.

document.find_heartbeats(params, options)

Returns:

  • (documents)


62
63
64
65
66
# File 'lib/obscured-heartbeat/tracker.rb', line 62

def find_heartbeats(params, options)
  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), options)
  end
end

#get_heartbeat(id) ⇒ document

Get an heartbeat from the x_heartbeat collection for document. This is only called on manually.

Examples:

Get heartbeat.

document.get_heartbeat(id)

Returns:

  • (document)


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_heartbeatsdocuments Also known as: heartbeats

Get heartbeats from the x_heartbeat collection for document by proprietor. This is only called on manually.

Examples:

Get heartbeats.

document.get_heartbeats
document.heartbeats

Returns:

  • (documents)


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.

Examples:

Get heartbeats.

document.search_heartbeats(text, options)

Returns:

  • (documents)


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, options)
  limit = options[:limit].blank? ? nil : options[:limit].to_i
  skip = options[:skip].blank? ? nil : options[:skip].to_i
  order = options[:order].blank? ? :created_at.desc : options[: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