Class: DecisionAgent::Auth::Session
- Inherits:
-
Object
- Object
- DecisionAgent::Auth::Session
- Defined in:
- lib/decision_agent/auth/session.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(user_id:, expires_in: 3600) ⇒ Session
constructor
A new instance of Session.
- #to_h ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(user_id:, expires_in: 3600) ⇒ Session
Returns a new instance of Session.
10 11 12 13 14 15 |
# File 'lib/decision_agent/auth/session.rb', line 10 def initialize(user_id:, expires_in: 3600) @token = SecureRandom.hex(32) @user_id = user_id @created_at = Time.now.utc @expires_at = @created_at + expires_in end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
8 9 10 |
# File 'lib/decision_agent/auth/session.rb', line 8 def created_at @created_at end |
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
8 9 10 |
# File 'lib/decision_agent/auth/session.rb', line 8 def expires_at @expires_at end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
8 9 10 |
# File 'lib/decision_agent/auth/session.rb', line 8 def token @token end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
8 9 10 |
# File 'lib/decision_agent/auth/session.rb', line 8 def user_id @user_id end |
Instance Method Details
#expired? ⇒ Boolean
17 18 19 |
# File 'lib/decision_agent/auth/session.rb', line 17 def expired? Time.now.utc > @expires_at end |
#to_h ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/decision_agent/auth/session.rb', line 25 def to_h { token: @token, user_id: @user_id, created_at: @created_at.iso8601, expires_at: @expires_at.iso8601 } end |
#valid? ⇒ Boolean
21 22 23 |
# File 'lib/decision_agent/auth/session.rb', line 21 def valid? !expired? end |