docbrown/app/labor/follow_checker.rb
rhymes e588fa7ece Code cleanups (#659)
* 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
2018-08-07 11:00:13 -04:00

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