Class: Iodine::Http::SessionManager::FileSessionStorage::SessionObject

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

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ SessionObject

called by the Plezi framework to initiate a session with the id requested



14
15
16
17
# File 'lib/iodine/http/session.rb', line 14

def initialize id
	@filename = File.join Dir.tmpdir, "iodine_#{Iodine::Http.session_token}_#{id}"
	@data ||= {}
end

Instance Method Details

#[](key) ⇒ Object Also known as: fetch

Get a key from the session data store.

Due to different considirations, all keys will be converted to strings, so that ‘“name” == :name` and `1234 == “1234”`. If you store two keys that evaluate as the same string, they WILL override each other.



22
23
24
25
26
# File 'lib/iodine/http/session.rb', line 22

def [] key
	key = key.to_s
	load
	@data[key]
end

#[]=(key, value) ⇒ Object Also known as: store

Stores a key in the session’s data store.

Due to different considirations, all keys will be converted to strings, so that ‘“name” == :name` and `1234 == “1234”`. If you store two keys that evaluate as the same string, they WILL override each other.



33
34
35
36
37
38
39
# File 'lib/iodine/http/session.rb', line 33

def []= key, value
	key = key.to_s
	load
	@data[key] = value
	save
	value
end

#clearObject

Clears the session’s data.



57
58
59
60
61
# File 'lib/iodine/http/session.rb', line 57

def clear
	@data.clear
	save
	nil
end

#delete(key) ⇒ Object

Removes a key from the session’s data store.



49
50
51
52
53
54
# File 'lib/iodine/http/session.rb', line 49

def delete key
	load
	ret = @data.delete key
	save
	ret
end

#to_hHash

Returns a shallow copy of the current session data as a Hash.

Returns:

  • (Hash)

    returns a shallow copy of the current session data as a Hash.



43
44
45
46
# File 'lib/iodine/http/session.rb', line 43

def to_h
	load
	@data.dup
end