Module: Mongoid::Timeline::Tracker
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/obscured-timeline/tracker.rb
Defined Under Namespace
Classes: Record
Instance Method Summary collapse
-
#add_event(event) ⇒ document
Adds event to the x_timeline collection for document.
-
#clear_events ⇒ documents
Clear events from the x_timeline collection for document.
-
#delete_event(id) ⇒ document
Delete an event from the x_timeline collection by id.
-
#edit_event(id, params = {}) ⇒ document
Edit an event from the x_timeline collection by id.
-
#find_events(params, options) ⇒ documents
Find events from the x_timeline collection for document.
-
#get_event(id) ⇒ document
Get an event from the x_timeline collection for document.
-
#get_events ⇒ documents
(also: #events)
Get events from the x_timeline collection for document by proprietor.
-
#search_events(text, options) ⇒ documents
Search events from the x_timeline collection for document.
Instance Method Details
#add_event(event) ⇒ document
Adds event to the x_timeline collection for document. This is only called on manually.
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_events ⇒ documents
Clear events from the x_timeline collection for document. This is only called on manually.
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.
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.
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. = 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.
62 63 64 65 66 |
# File 'lib/obscured-timeline/tracker.rb', line 62 def find_events(params, ) 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), ) end end |
#get_event(id) ⇒ document
Get an event from the x_timeline collection for document. This is only called on manually.
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_events ⇒ documents Also known as: events
Get events from the x_timeline collection for document by proprietor. This is only called on manually.
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.
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, ) 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}_timeline") do |m| query = {} query[:type] = [:type].to_sym if [:type] query[:severity] = [:severity].to_sym if [: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 |