Class: FeatureBox::User
- Inherits:
-
Object
show all
- Defined in:
- app/models/feature_box/user.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/models/feature_box/user.rb', line 42
def method_missing(method, *args, &block)
if method == :name
self.errors[:base] << ("You need to define 'name' and other methods in your User model")
"You need to define 'name' and other methods in your User model"
elsif method == :name=
self.errors[:base] << ("You need to define 'name=' and other methods in your User model")
false
elsif method == :admin?
self.errors[:base] << ("You need to define 'admin?' and other methods in your User model")
false
elsif method == :admin=
self.errors[:base] << ("You need to define 'admin=' and other methods in your User model")
false
else
super
end
end
|
Instance Method Details
#can_vote?(suggestion) ⇒ Boolean
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/models/feature_box/user.rb', line 13
def can_vote? suggestion
if !Settings.can_vote_own_suggestions && suggestion.user == self
return false
end
if votes_left <= 0 then
return false
end
if Settings.per_suggestion_limit == -1
return true
else
return Vote.where(:user_id => id, :suggestion_id=>suggestion.id).size < Settings.per_suggestion_limit
end
end
|
#can_vote_date ⇒ Object
36
37
38
39
40
|
# File 'app/models/feature_box/user.rb', line 36
def can_vote_date
condition = Settings.time_limit.ago
last_vote = Vote.where("user_id = ? AND created_at > ?", self.id, condition).order("created_at ASC").limit(1).first
return last_vote.created_at.in(Settings.time_limit)
end
|
#votes_left ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'app/models/feature_box/user.rb', line 27
def votes_left
if Settings.total_limit == -1 then
return 100
end
condition = Settings.time_limit.ago
used = Vote.where("user_id = ? AND created_at > ?", self.id, condition).size
return Settings.total_limit - used
end
|