Class: StandardId::DeviceSession

Inherits:
Session show all
Defined in:
app/models/standard_id/device_session.rb

Instance Attribute Summary

Attributes inherited from Session

#token

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Session

#active?, #expired?, #revoke!, #revoked?

Class Method Details

.expiryObject



6
7
8
# File 'app/models/standard_id/device_session.rb', line 6

def self.expiry
  StandardId.config.session.device_session_lifetime.seconds.from_now
end

Instance Method Details

#device_infoObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/standard_id/device_session.rb', line 10

def device_info
  return {} if device_agent.blank?

  # Simple device agent parsing
  case device_agent
  when /iOS/i
    { platform: "iOS", type: "mobile" }
  when /Android/i
    { platform: "Android", type: "mobile" }
  when /Windows/i
    { platform: "Windows", type: "desktop" }
  when /Mac/i
    { platform: "macOS", type: "desktop" }
  when /Linux/i
    { platform: "Linux", type: "desktop" }
  else
    { platform: "Unknown", type: "unknown" }
  end
end

#display_nameObject



30
31
32
# File 'app/models/standard_id/device_session.rb', line 30

def display_name
  "#{device_info[:platform]} Device Session"
end

#refresh!Object



34
35
36
# File 'app/models/standard_id/device_session.rb', line 34

def refresh!
  update!(last_refreshed_at: Time.current)
end

#stale?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/standard_id/device_session.rb', line 38

def stale?
  last_refreshed_at.nil? || last_refreshed_at < 1.hour.ago
end