Class: Neutral::Voting
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Neutral::Voting
- Defined in:
- app/models/neutral/voting.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_to_existing(nature) ⇒ Object
- #difference ⇒ Object
- #edit(nature) ⇒ Object
- #remove(nature) ⇒ Object
Class Method Details
.init(vote) ⇒ Object
13 14 15 16 17 |
# File 'app/models/neutral/voting.rb', line 13 def self.init(vote) create(votingable_type: vote.voteable_type, votingable_id: vote.voteable_id) do |voting| voting.increment(vote.nature) end end |
Instance Method Details
#add_to_existing(nature) ⇒ Object
19 20 21 |
# File 'app/models/neutral/voting.rb', line 19 def add_to_existing(nature) increment!(nature) end |
#difference ⇒ Object
9 10 11 |
# File 'app/models/neutral/voting.rb', line 9 def difference positive - negative end |
#edit(nature) ⇒ Object
23 24 25 26 27 |
# File 'app/models/neutral/voting.rb', line 23 def edit(nature) increment(nature) decrement(nature==:positive ? :negative : :positive) save end |
#remove(nature) ⇒ Object
29 30 31 |
# File 'app/models/neutral/voting.rb', line 29 def remove(nature) decrement!(nature) end |