docbrown/app/labor/user_states.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

44 lines
1.1 KiB
Ruby

class UserStates
attr_accessor :user
def initialize(user)
@user = user
end
def cached_onboarding_checklist
Rails.cache.fetch("user-#{user.id}-#{user.updated_at}-#{user.comments_count}-#{user.articles_count}-#{user.reactions_count}/onboarding_checklist", expires_in: 100.hours) do
{
write_your_first_article: made_first_article,
follow_your_first_tag: follows_a_tag,
fill_out_your_profile: fill_out_your_profile,
leave_your_first_reaction: leave_reactions,
follow_your_first_dev: follow_people,
leave_your_first_comment: leave_comments,
}
end
end
def made_first_article
!user.articles.where(published: true).empty?
end
def follows_a_tag
!user.follows.where(followable_type: "ActsAsTaggableOn::Tag").empty?
end
def fill_out_your_profile
user.summary.present? && !user.summary.empty?
end
def leave_reactions
!user.reactions.empty?
end
def follow_people
!user.follows.where(followable_type: "User").empty?
end
def leave_comments
!user.comments.empty?
end
end