Class: Manga::Tools::SessionStore
- Inherits:
-
Object
- Object
- Manga::Tools::SessionStore
- Defined in:
- lib/manga/tools/session_store.rb
Overview
A class on session retention.
Instance Attribute Summary collapse
-
#session_file_name ⇒ String
writeonly
The session file name string.
Instance Method Summary collapse
-
#exists? ⇒ Boolean
True if the session exists, otherwise returns false.
-
#initialize ⇒ SessionStore
constructor
A new instance of SessionStore.
-
#load ⇒ String?
Returns the session ID if the session is stored, otherwise it returns nil.
-
#session_file_path ⇒ String
The session file path.
-
#store(session_id) ⇒ Object
Store a session.
Constructor Details
#initialize ⇒ SessionStore
Returns a new instance of SessionStore.
12 13 14 15 |
# File 'lib/manga/tools/session_store.rb', line 12 def initialize create_session_dir_if_necessary @session_file_name = 'session.txt' end |
Instance Attribute Details
#session_file_name=(value) ⇒ String (writeonly)
Returns the session file name string.
10 11 12 |
# File 'lib/manga/tools/session_store.rb', line 10 def session_file_name=(value) @session_file_name = value end |
Instance Method Details
#exists? ⇒ Boolean
Returns true if the session exists, otherwise returns false.
34 35 36 |
# File 'lib/manga/tools/session_store.rb', line 34 def exists? File.exist?(session_file_path) end |
#load ⇒ String?
Returns the session ID if the session is stored, otherwise it returns nil
27 28 29 30 31 |
# File 'lib/manga/tools/session_store.rb', line 27 def load return nil unless exists? File.read(session_file_path) end |
#session_file_path ⇒ String
Returns the session file path.
39 40 41 |
# File 'lib/manga/tools/session_store.rb', line 39 def session_file_path "#{session_dir}/#{@session_file_name}" end |
#store(session_id) ⇒ Object
Store a session.
18 19 20 21 22 23 24 |
# File 'lib/manga/tools/session_store.rb', line 18 def store(session_id) return if exists? File.open(session_file_path, 'w') do |f| f.write(session_id) end end |