Class: Rage::Session
- Inherits:
-
Object
- Object
- Rage::Session
- Defined in:
- lib/rage/session.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns the value of the key stored in the session or
nil
if the given key is not found. -
#[]=(key, value) ⇒ Object
Writes the value to the session.
-
#clear ⇒ Object
Clears the session.
-
#delete(key) ⇒ Object
Deletes the given key from the session.
- #dig(*keys) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#fetch(key, default = nil, &block) ⇒ Object
Returns the value of the given key from the session, or raises
KeyError
if the given key is not found and no default value is set. -
#has_key?(key) ⇒ Boolean
(also: #key?, #include?)
Returns
true
if the given key is present in the session. - #inspect ⇒ Object
-
#to_hash ⇒ Object
(also: #to_h)
Returns the session as Hash.
Instance Method Details
#[](key) ⇒ Object
Returns the value of the key stored in the session or nil
if the given key is not found.
25 26 27 |
# File 'lib/rage/session.rb', line 25 def [](key) read_session[key] end |
#[]=(key, value) ⇒ Object
Writes the value to the session.
18 19 20 |
# File 'lib/rage/session.rb', line 18 def []=(key, value) write_session(add: { key => value }) end |
#clear ⇒ Object
Clears the session.
49 50 51 |
# File 'lib/rage/session.rb', line 49 def clear write_session(clear: true) end |
#delete(key) ⇒ Object
Deletes the given key from the session.
44 45 46 |
# File 'lib/rage/session.rb', line 44 def delete(key) write_session(remove: key) end |
#dig(*keys) ⇒ Object
76 77 78 |
# File 'lib/rage/session.rb', line 76 def dig(*keys) read_session.dig(*keys) end |
#each(&block) ⇒ Object
72 73 74 |
# File 'lib/rage/session.rb', line 72 def each(&block) read_session.each(&block) end |
#empty? ⇒ Boolean
60 61 62 |
# File 'lib/rage/session.rb', line 60 def empty? read_session.empty? end |
#fetch(key, default = nil, &block) ⇒ Object
Returns the value of the given key from the session, or raises KeyError
if the given key is not found and no default value is set. Returns the default value if specified.
33 34 35 36 37 38 39 |
# File 'lib/rage/session.rb', line 33 def fetch(key, default = nil, &block) if default.nil? read_session.fetch(key, &block) else read_session.fetch(key, default, &block) end end |
#has_key?(key) ⇒ Boolean Also known as: key?, include?
Returns true
if the given key is present in the session.
65 66 67 |
# File 'lib/rage/session.rb', line 65 def has_key?(key) read_session.has_key?(key) end |
#inspect ⇒ Object
80 81 82 |
# File 'lib/rage/session.rb', line 80 def inspect "#<#{self.class.name} @session=#{to_h.inspect}" end |
#to_hash ⇒ Object Also known as: to_h
Returns the session as Hash.
54 55 56 |
# File 'lib/rage/session.rb', line 54 def to_hash read_session end |