Class: Stats::UserTagsQuery

Inherits:
Object
  • Object
show all
Defined in:
app/models/stats/user_tags_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ UserTagsQuery

Returns a new instance of UserTagsQuery.



5
6
7
# File 'app/models/stats/user_tags_query.rb', line 5

def initialize(user)
  @user = user
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



3
4
5
# File 'app/models/stats/user_tags_query.rb', line 3

def user
  @user
end

Instance Method Details

#resultObject



9
10
11
# File 'app/models/stats/user_tags_query.rb', line 9

def result
  user.todos.find_by_sql([sql, user.id])
end

#sqlObject (private)



15
16
17
18
19
20
21
22
23
# File 'app/models/stats/user_tags_query.rb', line 15

def sql
  <<-SQL
    SELECT tags.id as id
    FROM tags, taggings, todos
    WHERE tags.id = taggings.tag_id
    AND taggings.taggable_id = todos.id
    AND todos.user_id = ?
  SQL
end