Class: PHPSession::StoreEngine::File

Inherits:
Object
  • Object
show all
Defined in:
lib/php_session/store_engine/file.rb

Instance Method Summary collapse

Constructor Details

#initialize(option) ⇒ File

Returns a new instance of File.



5
6
7
8
9
10
11
# File 'lib/php_session/store_engine/file.rb', line 5

def initialize(option)
  if ! option[:session_file_dir]
    raise PHPSession::Errors::ParameterError , "option[:session_dir] is required"
  end

  @option = option
end

Instance Method Details

#destroy(session_id) ⇒ Object



30
31
32
33
34
# File 'lib/php_session/store_engine/file.rb', line 30

def destroy(session_id)
  ::File.delete(file_path(session_id))
rescue Errno::ENOENT
  # file already deleted
end

#load(session_id) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/php_session/store_engine/file.rb', line 13

def load(session_id)
  serialized_session = with_lock(file_path(session_id)) do |f|
    # set internal_encoding to nil to avoid encoding conversion
    f.set_encoding(@option[:external_encoding], nil)
    f.read
  end

  serialized_session
end

#save(session_id, serialized_session) ⇒ Object



23
24
25
26
27
28
# File 'lib/php_session/store_engine/file.rb', line 23

def save(session_id, serialized_session)
  with_lock(file_path(session_id)) do |f|
    f.truncate(0)
    f.write(serialized_session)
  end
end