Skip to content

Commit

Permalink
Merge pull request #167 from ryanto/improve-code-climate
Browse files Browse the repository at this point in the history
New method find_votes_by
  • Loading branch information
epergo authored Oct 21, 2017
2 parents ed1b93d + 57d06cf commit b471419
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/acts_as_votable/votable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ def vote_by(args = {})
end

# find the vote
votes = find_votes_for(voter_id: options[:voter].id,
vote_scope: options[:vote_scope],
voter_type: options[:voter].class.base_class.name)
votes = find_votes_by(options[:voter], options[:vote_scope])

if votes.count == (0) || options[:duplicate]
# this voter has never voted
Expand Down Expand Up @@ -112,7 +110,7 @@ def vote_by(args = {})

def unvote(args = {})
return false if args[:voter].nil?
votes = find_votes_for(voter_id: args[:voter].id, vote_scope: args[:vote_scope], voter_type: args[:voter].class.base_class.name)
votes = find_votes_by(args[:voter], args[:vote_scope])

return true if votes.size == 0
votes.each(&:destroy)
Expand All @@ -138,6 +136,12 @@ def find_votes_for(extra_conditions = {})
votes_for.where(extra_conditions)
end

def find_votes_by(voter, vote_scope)
find_votes_for(voter_id: voter.id,
vote_scope: vote_scope,
voter_type: voter.class.base_class.name)
end

def get_up_votes(options = {})
vote_scope_hash = scope_or_empty_hash(options[:vote_scope])
find_votes_for({ vote_flag: true }.merge(vote_scope_hash))
Expand Down

0 comments on commit b471419

Please sign in to comment.