Module: Persona::Summary
- Defined in:
- lib/persona/summary.rb
Class Method Summary collapse
-
.class_summary(klass) ⇒ Object
Class-wide action breakdown.
-
.compare(record_a, record_b) ⇒ Object
Compare two records side by side.
-
.leaderboard(klass, limit: 10) ⇒ Object
Top N most active records of a given class.
Class Method Details
.class_summary(klass) ⇒ Object
Class-wide action breakdown
29 30 31 32 33 34 35 36 |
# File 'lib/persona/summary.rb', line 29 def self.class_summary(klass) PersonaEvent .where(trackable_type: klass.name) .group(:action) .order("count_all DESC") .count .transform_keys(&:to_sym) end |
.compare(record_a, record_b) ⇒ Object
Compare two records side by side
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/persona/summary.rb', line 4 def self.compare(record_a, record_b) actions = (record_a.persona_summary.keys + record_b.persona_summary.keys).uniq actions.each_with_object({}) do |action, hash| hash[action] = { record_a.class.name.downcase + "_#{record_a.id}" => record_a.action_count(action), record_b.class.name.downcase + "_#{record_b.id}" => record_b.action_count(action) } end end |
.leaderboard(klass, limit: 10) ⇒ Object
Top N most active records of a given class
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/persona/summary.rb', line 16 def self.leaderboard(klass, limit: 10) PersonaEvent .where(trackable_type: klass.name) .group(:trackable_id) .order("count_all DESC") .limit(limit) .count .map do |id, count| { record: klass.find(id), total_events: count } end end |