We were very inconsistent regarding these rules. Personally I prefer no empty lines around blocks, clases, etc... as recommended by the Ruby style guide [1], and they're the default values in rubocop, so those are the settings I'm applying. The exception is the `private` access modifier, since we were leaving empty lines around it most of the time. That's the default rubocop rule as well. Personally I don't have a strong preference about this one. [1] https://rubystyle.guide/#empty-lines-around-bodies
29 lines
907 B
Ruby
29 lines
907 B
Ruby
module CacheKeysHelper
|
|
def locale_and_user_status(authorable = nil)
|
|
@cache_key_user ||= calculate_user_status(authorable)
|
|
"#{I18n.locale}/#{@cache_key_user}"
|
|
end
|
|
|
|
def calculate_user_status(authorable = nil)
|
|
user_status = "user"
|
|
|
|
if user_signed_in?
|
|
user_status += ":signed"
|
|
user_status += ":verified" if current_user.level_two_or_three_verified?
|
|
user_status += ":org" if current_user.organization?
|
|
user_status += ":admin" if current_user.administrator?
|
|
user_status += ":moderator" if current_user.moderator?
|
|
user_status += ":author" if authorable && authorable.author == current_user
|
|
else
|
|
user_status += ":visitor"
|
|
end
|
|
|
|
user_status
|
|
end
|
|
|
|
# when commentable id and type are used but no need to update cache on updated_at changes
|
|
def commentable_cache_key(commentable)
|
|
"#{commentable.class.name}-#{commentable.id}"
|
|
end
|
|
end
|