Class: ActionController::Session::AbstractStore::SessionHash

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

Instance Method Summary collapse

Constructor Details

#initialize(by, env) ⇒ SessionHash

Returns a new instance of SessionHash.



42
43
44
45
46
47
# File 'lib/action_controller/session/abstract_store.rb', line 42

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

Instance Method Details

#[](key) ⇒ Object



56
57
58
59
# File 'lib/action_controller/session/abstract_store.rb', line 56

def [](key)
  load_for_read!
  super
end

#[]=(key, value) ⇒ Object



66
67
68
69
# File 'lib/action_controller/session/abstract_store.rb', line 66

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

#clearObject



71
72
73
74
# File 'lib/action_controller/session/abstract_store.rb', line 71

def clear
  load_for_write!
  super
end

#dataObject



93
94
95
96
97
98
# File 'lib/action_controller/session/abstract_store.rb', line 93

def data
 ActiveSupport::Deprecation.warn(
   "ActionController::Session::AbstractStore::SessionHash#data " +
   "has been deprecated. Please use #to_hash instead.", caller)
  to_hash
end

#delete(key) ⇒ Object



88
89
90
91
# File 'lib/action_controller/session/abstract_store.rb', line 88

def delete(key)
  load_for_write!
  super
end

#destroyObject



114
115
116
117
118
119
# File 'lib/action_controller/session/abstract_store.rb', line 114

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)


105
106
107
108
# File 'lib/action_controller/session/abstract_store.rb', line 105

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

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
# File 'lib/action_controller/session/abstract_store.rb', line 61

def has_key?(key)
  load_for_read!
  super
end

#inspectObject



100
101
102
103
# File 'lib/action_controller/session/abstract_store.rb', line 100

def inspect
  load_for_read!
  super
end

#loaded?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/action_controller/session/abstract_store.rb', line 110

def loaded?
  @loaded
end

#session_idObject



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

def session_id
  ActiveSupport::Deprecation.warn(
    "ActionController::Session::AbstractStore::SessionHash#session_id " +
    "has been deprecated. Please use request.session_options[:id] instead.", caller)
  @env[ENV_SESSION_OPTIONS_KEY][:id]
end

#to_hashObject



76
77
78
79
80
81
# File 'lib/action_controller/session/abstract_store.rb', line 76

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

#update(hash) ⇒ Object



83
84
85
86
# File 'lib/action_controller/session/abstract_store.rb', line 83

def update(hash)
  load_for_write!
  super
end