Skip to content

Commit

Permalink
[#71] undefined local variable or method scope when cache is used (#72
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jonhue committed May 10, 2019
1 parent d0ec13f commit 7706740
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/acts_as_favoritor/favoritor.rb
Expand Up @@ -49,7 +49,7 @@ def favorite(favoritable,
self.class.build_result_for_scopes scopes do |scope|
return nil if self == favoritable

inc_cache if ActsAsFavoritor.configuration.cache
inc_cache(scope) if ActsAsFavoritor.configuration.cache

favorites.for_favoritable(favoritable).send("#{scope}_list")
.first_or_create!
Expand All @@ -62,7 +62,7 @@ def unfavorite(favoritable,
favorite_record = get_favorite(favoritable, scope)
return nil unless favorite_record.present?

dec_cache if ActsAsFavoritor.configuration.cache
dec_cache(scope) if ActsAsFavoritor.configuration.cache
favorite_record.destroy!
end
end
Expand Down Expand Up @@ -129,7 +129,7 @@ def get_favorite(favoritable, scope)
end

# rubocop:disable Metrics/AbcSize
def inc_cache
def inc_cache(scope)
favoritor_score[scope] = (favoritor_score[scope] || 0) + 1
favoritor_total[scope] = (favoritor_total[scope] || 0) + 1
save!
Expand All @@ -141,7 +141,7 @@ def inc_cache
favoritable.save!
end

def dec_cache
def dec_cache(scope)
favoritor_score[scope] = (favoritor_score[scope] || 0) - 1
favoritor_score.delete(scope) unless favoritor_score[scope].positive?
save!
Expand Down

0 comments on commit 7706740

Please sign in to comment.