Class: Stealth::Session
- Inherits:
-
Object
- Object
- Stealth::Session
- Defined in:
- lib/stealth/session.rb
Constant Summary collapse
- SLUG_SEPARATOR =
'->'
Instance Attribute Summary collapse
-
#flow ⇒ Object
readonly
Returns the value of attribute flow.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #flow_string ⇒ Object
- #get ⇒ Object
-
#initialize(user_id:) ⇒ Session
constructor
A new instance of Session.
- #present? ⇒ Boolean
- #set(flow:, state:) ⇒ Object
- #state_string ⇒ Object
Constructor Details
#initialize(user_id:) ⇒ Session
Returns a new instance of Session.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/stealth/session.rb', line 11 def initialize(user_id:) @user_id = user_id unless defined?($redis) raise(Stealth::Errors::RedisNotConfigured, "Please make sure REDIS_URL is configured before using sessions.") end get self end |
Instance Attribute Details
#flow ⇒ Object (readonly)
Returns the value of attribute flow.
9 10 11 |
# File 'lib/stealth/session.rb', line 9 def flow @flow end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
9 10 11 |
# File 'lib/stealth/session.rb', line 9 def session @session end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
9 10 11 |
# File 'lib/stealth/session.rb', line 9 def state @state end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
9 10 11 |
# File 'lib/stealth/session.rb', line 9 def user_id @user_id end |
Class Method Details
.flow_and_state_from_session_slug(slug:) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/stealth/session.rb', line 22 def self.flow_and_state_from_session_slug(slug:) { flow: slug&.split(SLUG_SEPARATOR)&.first, state: slug&.split(SLUG_SEPARATOR)&.last } end |
Instance Method Details
#blank? ⇒ Boolean
63 64 65 |
# File 'lib/stealth/session.rb', line 63 def blank? !present? end |
#flow_string ⇒ Object
41 42 43 |
# File 'lib/stealth/session.rb', line 41 def flow_string session&.split(SLUG_SEPARATOR)&.first end |
#get ⇒ Object
49 50 51 |
# File 'lib/stealth/session.rb', line 49 def get @session ||= $redis.get(user_id) end |
#present? ⇒ Boolean
59 60 61 |
# File 'lib/stealth/session.rb', line 59 def present? session.present? end |
#set(flow:, state:) ⇒ Object
53 54 55 56 57 |
# File 'lib/stealth/session.rb', line 53 def set(flow:, state:) @session = canonical_session_slug(flow: flow, state: state) flow $redis.set(user_id, canonical_session_slug(flow: flow, state: state)) end |
#state_string ⇒ Object
45 46 47 |
# File 'lib/stealth/session.rb', line 45 def state_string session&.split(SLUG_SEPARATOR)&.last end |