Class: ActionDispatch::Session::AbstractStore::SessionHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/action_dispatch/middleware/session/abstract_store.rb

Direct Known Subclasses

ActionController::TestSession

Instance Method Summary collapse

Constructor Details

#initialize(by, env) ⇒ SessionHash

Returns a new instance of SessionHash.



45
46
47
48
49
50
# File 'lib/action_dispatch/middleware/session/abstract_store.rb', line 45

def initialize(by, env)
  super()
  @by = by
  @env = env
  @loaded = false
end

Instance Method Details

#[](key) ⇒ Object



52
53
54
55
# File 'lib/action_dispatch/middleware/session/abstract_store.rb', line 52

def [](key)
  load_for_read!
  super(key.to_s)
end

#[]=(key, value) ⇒ Object



62
63
64
65
# File 'lib/action_dispatch/middleware/session/abstract_store.rb', line 62

def []=(key, value)
  load_for_write!
  super(key.to_s, value)
end

#clearObject



67
68
69
70
# File 'lib/action_dispatch/middleware/session/abstract_store.rb', line 67

def clear
  load_for_write!
  super
end

#delete(key) ⇒ Object



84
85
86
87
# File 'lib/action_dispatch/middleware/session/abstract_store.rb', line 84

def delete(key)
  load_for_write!
  super(key.to_s)
end

#destroyObject



103
104
105
106
107
108
# File 'lib/action_dispatch/middleware/session/abstract_store.rb', line 103

def destroy
  clear
  @by.send(:destroy, @env) if @by
  @env[ENV_SESSION_OPTIONS_KEY][:id] = nil if @env && @env[ENV_SESSION_OPTIONS_KEY]
  @loaded = false
end

#exists?Boolean

Returns:

  • (Boolean)


94
95
96
97
# File 'lib/action_dispatch/middleware/session/abstract_store.rb', line 94

def exists?
  return @exists if instance_variable_defined?(:@exists)
  @exists = @by.send(:exists?, @env)
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
# File 'lib/action_dispatch/middleware/session/abstract_store.rb', line 57

def has_key?(key)
  load_for_read!
  super(key.to_s)
end

#inspectObject



89
90
91
92
# File 'lib/action_dispatch/middleware/session/abstract_store.rb', line 89

def inspect
  load_for_read!
  super
end

#loaded?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/action_dispatch/middleware/session/abstract_store.rb', line 99

def loaded?
  @loaded
end

#to_hashObject



72
73
74
75
76
77
# File 'lib/action_dispatch/middleware/session/abstract_store.rb', line 72

def to_hash
  load_for_read!
  h = {}.replace(self)
  h.delete_if { |k,v| v.nil? }
  h
end

#update(hash) ⇒ Object



79
80
81
82
# File 'lib/action_dispatch/middleware/session/abstract_store.rb', line 79

def update(hash)
  load_for_write!
  super(hash.stringify_keys)
end