module Hello::RailsActiveRecord::Access

Public Instance Methods

active_token_or_destroy() click to toggle source
# File lib/hello/rails_active_record/access.rb, line 29
def active_token_or_destroy
  if expires_at.future?
    token
  else
    destroy && (return nil)
  end
end
as_json_web_api() click to toggle source
# File lib/hello/rails_active_record/access.rb, line 37
def as_json_web_api
  as_json.slice(*%w(expires_at token user_id)).merge({ user: user.as_json_web_api })
end
full_device_name() click to toggle source
# File lib/hello/rails_active_record/access.rb, line 25
def full_device_name
  Hello::Utils::DeviceName.instance.parse(user_agent_string)
end
keep_alive!() click to toggle source

CUSTOM METHODS

# File lib/hello/rails_active_record/access.rb, line 21
def keep_alive!
  renew! if expiring?
end
sudo_expire!() click to toggle source
# File lib/hello/rails_active_record/access.rb, line 41
def sudo_expire!
  update! sudo_expires_at: 1.second.ago
end

Private Instance Methods

expiring?() click to toggle source
# File lib/hello/rails_active_record/access.rb, line 47
def expiring?
  expires_at < 20.minutes.from_now
end
renew!() click to toggle source
# File lib/hello/rails_active_record/access.rb, line 51
def renew!
  update_attributes!(expires_at: 30.minutes.from_now)
end