Class: Rage::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/session.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

Returns the value of the key stored in the session or nil if the given key is not found.

Parameters:

  • key (Symbol)


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.

Parameters:

  • key (Symbol)
  • value (String)


18
19
20
# File 'lib/rage/session.rb', line 18

def []=(key, value)
  write_session(add: { key => value })
end

#clearObject

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.

Parameters:

  • key (Symbol)


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

Returns:

  • (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.

Parameters:

  • key (Symbol)


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.

Returns:

  • (Boolean)


65
66
67
# File 'lib/rage/session.rb', line 65

def has_key?(key)
  read_session.has_key?(key)
end

#inspectObject



80
81
82
# File 'lib/rage/session.rb', line 80

def inspect
  "#<#{self.class.name} @session=#{to_h.inspect}"
end

#to_hashObject 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