Class: Kwipper::User

Inherits:
Model
  • Object
show all
Defined in:
app/models/user.rb

Constant Summary

Constants inherited from Model

Model::DB_FILE_NAME, Model::DB_NAME, Model::ID_COLUMN, Model::UnknownAttribute

Instance Attribute Summary

Attributes inherited from Model

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

all, attr_array_to_hash, column, count, create, db, destroy, #destroy, exists?, find, generate_id, hash_to_key_vals, #initialize, normalize_value_for_db, #save, sql, #sql, table_name, #update, update, where

Constructor Details

This class inherits a constructor from Kwipper::Model

Class Method Details

.authenticate(username, password) ⇒ Object



7
8
9
10
# File 'app/models/user.rb', line 7

def self.authenticate(username, password)
  user = where(username: username).first
  user && user.hashed_password == password && user
end

Instance Method Details

#favorite?(post) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'app/models/user.rb', line 12

def favorite?(post)
  result = sql("SELECT COUNT(id) FROM post_favorites WHERE user_id = #{id} AND post_id = #{post.id} LIMIT 1").first
  result.first && result.first > 0
end

#postsObject



17
18
19
# File 'app/models/user.rb', line 17

def posts
  Post.recent "SELECT * FROM posts WHERE user_id = #{id}"
end