Class: Stats::TopProjectsQuery
- Inherits:
-
Object
- Object
- Stats::TopProjectsQuery
- Defined in:
- app/models/stats/top_projects_query.rb
Instance Attribute Summary collapse
-
#cutoff ⇒ Object
readonly
Returns the value of attribute cutoff.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(user, cutoff = nil) ⇒ TopProjectsQuery
constructor
A new instance of TopProjectsQuery.
- #query_options ⇒ Object private
- #result ⇒ Object
- #sql ⇒ Object private
Constructor Details
#initialize(user, cutoff = nil) ⇒ TopProjectsQuery
Returns a new instance of TopProjectsQuery.
8 9 10 11 |
# File 'app/models/stats/top_projects_query.rb', line 8 def initialize(user, cutoff = nil) @user = user @cutoff = cutoff end |
Instance Attribute Details
#cutoff ⇒ Object (readonly)
Returns the value of attribute cutoff.
6 7 8 |
# File 'app/models/stats/top_projects_query.rb', line 6 def cutoff @cutoff end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
6 7 8 |
# File 'app/models/stats/top_projects_query.rb', line 6 def user @user end |
Instance Method Details
#query_options ⇒ Object (private)
19 20 21 22 23 |
# File 'app/models/stats/top_projects_query.rb', line 19 def = [sql, user.id] += [cutoff, cutoff] if cutoff end |
#result ⇒ Object
13 14 15 |
# File 'app/models/stats/top_projects_query.rb', line 13 def result user.projects.find_by_sql() end |
#sql ⇒ Object (private)
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/stats/top_projects_query.rb', line 25 def sql query = "SELECT p.id, p.name, count(p.id) AS count " query << "FROM todos t, projects p " query << "WHERE t.project_id = p.id " query << "AND t.user_id= ? " if cutoff query << "AND (t.created_at > ? OR t.completed_at > ?) " end query << "GROUP BY p.id, p.name " query << "ORDER BY count DESC " query << "LIMIT 10" end |