module Voting::Extension
Public Instance Methods
down(resource, author: self, scope: nil)
click to toggle source
# File lib/voting/models/voting/extension.rb, line 8 def down(resource, author: self, scope: nil) vote resource, -1, author: author, scope: scope end
up(resource, author: self, scope: nil)
click to toggle source
# File lib/voting/models/voting/extension.rb, line 12 def up(resource, author: self, scope: nil) vote resource, 1, author: author, scope: scope end
vote(resource, value, author: self, scope: nil)
click to toggle source
# File lib/voting/models/voting/extension.rb, line 16 def vote(resource, value, author: self, scope: nil) Vote.create author: author, resource: resource, scopeable: scope, value: value end
vote_for(resource, scope: nil)
click to toggle source
# File lib/voting/models/voting/extension.rb, line 20 def vote_for(resource, scope: nil) Vote.vote_for author: self, resource: resource, scopeable: scope end
voted(scope: nil)
click to toggle source
# File lib/voting/models/voting/extension.rb, line 36 def voted(scope: nil) voted_records.where scopeable: scope end
voted?(resource, value = nil, scope: nil)
click to toggle source
# File lib/voting/models/voting/extension.rb, line 24 def voted?(resource, value = nil, scope: nil) query = { author: self, resource: resource, scopeable: scope } query[value] = 1 unless value.nil? Vote.exists? query end
votes(scope: nil)
click to toggle source
# File lib/voting/models/voting/extension.rb, line 32 def votes(scope: nil) votes_records.where scopeable: scope end
voting(scope: nil)
click to toggle source
# File lib/voting/models/voting/extension.rb, line 40 def voting(scope: nil) voting_records.find_by scopeable: scope end
voting_warm_up(scoping: nil)
click to toggle source
# File lib/voting/models/voting/extension.rb, line 44 def voting_warm_up(scoping: nil) return Voting.find_or_create_by(resource: self) if scoping.blank? [scoping].flatten.compact.map do |attribute| next unless respond_to?(attribute) [public_send(attribute)].flatten.compact.map do |object| Voting.find_or_create_by! resource: self, scopeable: object end end.flatten.compact end