Module: Hello::RailsActiveRecord::Access

Extended by:
ActiveSupport::Concern
Included in:
Access
Defined in:
lib/hello/rails_active_record/access.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#active_token_or_destroyObject



29
30
31
32
33
34
35
# 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_apiObject



37
38
39
# 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_nameObject



25
26
27
# 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!Object

CUSTOM METHODS



21
22
23
# File 'lib/hello/rails_active_record/access.rb', line 21

def keep_alive!
  renew! if expiring?
end

#sudo_expire!Object



41
42
43
# File 'lib/hello/rails_active_record/access.rb', line 41

def sudo_expire!
  update! sudo_expires_at: 1.second.ago
end