* Initial automatic cleanup with rubocop * Fix syntax error introduced by rubocop * Cleanup seeds file * Cleanup lib folder * Exclude bin folder because it contains auto generated files * Make Rubocop a little bit more chatty * Block length should not include comments in the count * Cleanup config folder * Cleanup specs * Updated Rubocop version and generated a todo file * Fix broken ArticlesApi spec * Fix tests * Restored rubocop pre-commit hook
22 lines
769 B
Ruby
22 lines
769 B
Ruby
class FollowChecker
|
|
attr_accessor :follower, :followable_type, :followable_id
|
|
|
|
def initialize(follower, followable_type, followable_id)
|
|
@follower = follower
|
|
@followable_type = followable_type
|
|
@followable_id = followable_id
|
|
end
|
|
|
|
def cached_follow_check
|
|
Rails.cache.fetch("user-#{follower.id}-#{follower.updated_at}/is_following_#{followable_type}_#{followable_id}", expires_in: 100.hours) do
|
|
followable = if followable_type == "Tag"
|
|
Tag.find(followable_id)
|
|
elsif followable_type == "Organization"
|
|
Organization.find(followable_id)
|
|
else
|
|
User.find(followable_id)
|
|
end
|
|
follower.following?(followable)
|
|
end
|
|
end
|
|
end
|