Module: Mongoid::Timeline::Tracker

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

Defined Under Namespace

Classes: Record

Instance Method Summary collapse

Instance Method Details

#add_event(event) ⇒ document

Adds event to the x_timeline collection for document. This is only called on manually.

Examples:

Add event.

document.add_event

Returns:

  • (document)


21
22
23
24
25
# File 'lib/obscured-timeline/tracker.rb', line 21

def add_event(event)
  Record.with(collection: "#{self.class.name.demodulize.downcase}_timeline") do |m|
    m.make!(event.merge(proprietor: { "#{self.class.name.demodulize.downcase}_id".to_sym => id }))
  end
end

#clear_eventsdocuments

Clear events from the x_timeline collection for document. This is only called on manually.

Examples:

Get event.

document.clear_events

Returns:

  • (documents)


130
131
132
133
134
# File 'lib/obscured-timeline/tracker.rb', line 130

def clear_events
  Record.with(collection: "#{self.class.name.demodulize.downcase}_timeline") do |m|
    m.where(proprietor: { "#{self.class.name.demodulize.downcase}_id".to_sym => id }).delete
  end
end

#delete_event(id) ⇒ document

Delete an event from the x_timeline collection by id. This is only called on manually.

Examples:

Get event.

document.get_event(id)

Returns:

  • (document)


117
118
119
120
121
# File 'lib/obscured-timeline/tracker.rb', line 117

def delete_event(id)
  Record.with(collection: "#{self.class.name.demodulize.downcase}_timeline") do |m|
    m.where(id: id).delete
  end
end

#edit_event(id, params = {}) ⇒ document

Edit an event from the x_timeline collection by id. This is only called on manually.

Examples:

Get event.

document.edit_event(id, params)

Returns:

  • (document)


101
102
103
104
105
106
107
108
# File 'lib/obscured-timeline/tracker.rb', line 101

def edit_event(id, params = {})
  Record.with(collection: "#{self.class.name.demodulize.downcase}_timeline") do |m|
    event = m.where(id: id).first
    event.message = params[:message] if params[:message]
    event.save
    event
  end
end

#find_events(params, options) ⇒ documents

Find events from the x_timeline collection for document. This is only called on manually.

Examples:

Get event.

document.find_events(params, options)

Returns:

  • (documents)


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

def find_events(params, options)
  Record.with(collection: "#{self.class.name.demodulize.downcase}_timeline") do |m|
    m.by({ proprietor: { "#{self.class.name.demodulize.downcase}_id".to_sym => id } }.merge(params), options)
  end
end

#get_event(id) ⇒ document

Get an event from the x_timeline collection for document. This is only called on manually.

Examples:

Get event.

document.get_event(id)

Returns:

  • (document)


34
35
36
37
38
# File 'lib/obscured-timeline/tracker.rb', line 34

def get_event(id)
  Record.with(collection: "#{self.class.name.demodulize.downcase}_timeline") do |m|
    m.find(id)
  end
end

#get_eventsdocuments Also known as: events

Get events from the x_timeline collection for document by proprietor. This is only called on manually.

Examples:

Get event.

document.get_events
document.events

Returns:

  • (documents)


48
49
50
51
52
# File 'lib/obscured-timeline/tracker.rb', line 48

def get_events
  Record.with(collection: "#{self.class.name.demodulize.downcase}_timeline") do |m|
    m.by(proprietor: { "#{self.class.name.demodulize.downcase}_id".to_sym => id })
  end
end

#search_events(text, options) ⇒ documents

Search events from the x_timeline collection for document. This is only called on manually.

Examples:

Get event.

document.search_events(text, options)

Returns:

  • (documents)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/obscured-timeline/tracker.rb', line 75

def search_events(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}_timeline") do |m|
    query = {}
    query[:type] = options[:type].to_sym if options[:type]
    query[:severity] = options[:severity].to_sym if options[:severity]

    criteria = m.where(query).full_text_search(text)
    criteria = criteria.order_by(order) if order
    criteria = criteria.limit(limit).skip(skip)

    docs = criteria.to_a
    docs
  end
end