Skip to content

Instantly share code, notes, and snippets.

@nicholasjhenry
Forked from brynary/active_user_policy.rb
Created January 7, 2014 23:09
Show Gist options
  • Save nicholasjhenry/8308630 to your computer and use it in GitHub Desktop.
Save nicholasjhenry/8308630 to your computer and use it in GitHub Desktop.
class ActiveUserPolicy
LOGIN_PERIOD = 14.days
class Query
def initialize(relation = User.scoped)
@relation = relation
end
def find_each(&block)
@relation.
where(email_confirmed: true).
where('last_login < ?', LOGIN_PERIOD.ago).
find_each(&block)
end
end
def initialize(user)
@user = user
end
def active?
@user.email_confirmed? &&
@user.last_login_at < LOGIN_PERIOD.ago
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment