Class: Vote
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Vote
- Includes:
- HasOwner
- Defined in:
- app/models/vote.rb
Constant Summary collapse
- METRIC_VOTE_HIT =
'votes.any.hit'- METRIC_UPVOTE_HIT =
'votes.upvote.hit'- METRIC_DOWNVOTE_HIT =
'votes.downvote.hit'
Class Method Summary collapse
- .count_vote(user, votable, delta = 1) ⇒ Object
- .creation_parameters ⇒ Object
- .page_for_administration(page = 1) ⇒ Object
- .slug_string(user, ip, agent_id) ⇒ Object
- .voted?(slug, votable) ⇒ Boolean
Instance Method Summary collapse
Class Method Details
.count_vote(user, votable, delta = 1) ⇒ Object
47 48 49 50 51 |
# File 'app/models/vote.rb', line 47 def self.count_vote(user, votable, delta = 1) create(user: user, votable: votable, delta: delta) unless voted? votable.reload votable.vote_result end |
.creation_parameters ⇒ Object
53 54 55 |
# File 'app/models/vote.rb', line 53 def self.creation_parameters i(votable_id votable_type delta) end |
.page_for_administration(page = 1) ⇒ Object
23 24 25 |
# File 'app/models/vote.rb', line 23 def self.page_for_administration(page = 1) list_for_administration.page(page) end |
.slug_string(user, ip, agent_id) ⇒ Object
30 31 32 33 34 35 36 |
# File 'app/models/vote.rb', line 30 def self.slug_string(user, ip, agent_id) if user.nil? "#{ip}:#{agent_id}" else user.id.to_s end end |
.voted?(slug, votable) ⇒ Boolean
40 41 42 |
# File 'app/models/vote.rb', line 40 def self.voted?(slug, votable) exists?(slug: slug, votable: votable) end |
Instance Method Details
#current_slug ⇒ Object
70 71 72 |
# File 'app/models/vote.rb', line 70 def current_slug self.class.slug_string(user, ip, agent_id) end |
#downvote? ⇒ Boolean
61 62 63 |
# File 'app/models/vote.rb', line 61 def downvote? delta < 0 end |
#editable_by?(user) ⇒ Boolean
66 67 68 |
# File 'app/models/vote.rb', line 66 def editable_by?(user) owned_by?(user) || UserPrivilege.user_has_privilege?(:user, :moderator) end |
#upvote? ⇒ Boolean
57 58 59 |
# File 'app/models/vote.rb', line 57 def upvote? delta >= 0 end |