Class: Course::DashboardStats
- Inherits:
-
Object
- Object
- Course::DashboardStats
- Defined in:
- app/services/course/dashboard_stats.rb
Overview
Service object: computes course dashboard statistics and eager-loads related data.
Consolidates duplicate logic across multiple controllers that display course stats:
- eager loads topic categories/topics/responses
- eager loads topic exams
- loads recent enrollments
- computes enrollment statistics (count, active, completed)
- computes exam statistics (graded attempts, passed attempts)
Usage:
stats = Course::DashboardStats.call(course)
@topic_categories = stats.topic_categories
@topic_exams = stats.topic_exams
@stats = stats.stats_hash
Defined Under Namespace
Classes: Result
Class Method Summary collapse
-
.call(course, limit: 10) ⇒ Result
Convenience class method for consistent API.
Instance Method Summary collapse
-
#call ⇒ Result
Computes and returns the dashboard stats result.
-
#initialize(course, limit: 10) ⇒ DashboardStats
constructor
A new instance of DashboardStats.
Constructor Details
#initialize(course, limit: 10) ⇒ DashboardStats
Returns a new instance of DashboardStats.
31 32 33 34 |
# File 'app/services/course/dashboard_stats.rb', line 31 def initialize(course, limit: 10) @course = course @limit = limit end |
Class Method Details
.call(course, limit: 10) ⇒ Result
Convenience class method for consistent API.
53 54 55 |
# File 'app/services/course/dashboard_stats.rb', line 53 def self.call(course, limit: 10) new(course, limit: limit).call end |
Instance Method Details
#call ⇒ Result
Computes and returns the dashboard stats result.
39 40 41 42 43 44 45 46 47 48 |
# File 'app/services/course/dashboard_stats.rb', line 39 def call raise ArgumentError, 'course is required' if @course.nil? Result.new( topic_categories: load_topic_categories, topic_exams: load_topic_exams, recent_enrollments: load_recent_enrollments, stats: compute_stats ) end |