Class: User

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allObject



93
94
95
# File 'app/models/user.rb', line 93

def self.all
  self.where( :is_trash => false ).order_by( :created_at => :desc )
end

.clearObject



112
113
114
115
116
# File 'app/models/user.rb', line 112

def self.clear
  if Rails.env.test?
    User.unscoped.each { |u| u.remove }
  end
end

.list(conditions = { :is_trash => false }) ⇒ Object



86
87
88
89
# File 'app/models/user.rb', line 86

def self.list conditions = { :is_trash => false }
  out = self.where( conditions ).order_by( :name => :asc )
  [['', nil]] + out.map { |item| [ item.name, item.id ] }
end

.per_pageObject



108
109
110
# File 'app/models/user.rb', line 108

def self.per_page
  16
end

Instance Method Details

#create_newsitem(args = {}) ⇒ Object



97
98
99
100
101
102
103
104
105
106
# File 'app/models/user.rb', line 97

def create_newsitem args = {}
  unless args[:photo].blank?
    n = Newsitem.new
    n.photo = args[:photo]
    n.descr = 'uploaded new photo on'
    n.username = self.username
    self.newsitems << n
    self.save
  end
end

#emailObject

Database authenticatable



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

field :email, type: String, default: ""

#generate_auth_tokenObject



118
119
120
121
# File 'app/models/user.rb', line 118

def generate_auth_token
  payload = { user_id: self.id }
  AuthToken.encode(payload)
end

#remember_created_atObject

Rememberable



20
# File 'app/models/user.rb', line 20

field :remember_created_at, type: Time

#reset_password_tokenObject

Recoverable



16
# File 'app/models/user.rb', line 16

field :reset_password_token,   type: String

#sign_in_countObject

Trackable



23
# File 'app/models/user.rb', line 23

field :sign_in_count,      type: Integer, default: 0