Module: Waw::Kern::LivingState

Included in:
App
Defined in:
lib/waw/kern/living_state.rb,
lib/waw/kern/living_state.rb

Overview

Variables that are living during a web request.

Defined Under Namespace

Classes: Saved

Instance Method Summary collapse

Instance Method Details

#clean_living_stateObject

Cleans the living state when a request is done.



49
50
51
52
53
# File 'lib/waw/kern/living_state.rb', line 49

def clean_living_state
  if (stack = Thread.current[:waw_state])
    stack.pop
  end
end

#install_living_state(env) ⇒ Object

Handler called to install everything required for the living state to work properly, based on a Rack env variable.



41
42
43
44
45
46
# File 'lib/waw/kern/living_state.rb', line 41

def install_living_state(env)
  stack = (Thread.current[:waw_state] ||= [])
  state = Saved.new(env)
  stack.push(state)
  state
end

#paramsObject

Request parameters



77
78
79
# File 'lib/waw/kern/living_state.rb', line 77

def params
  request && request.params
end

#rack_envObject

Returns the current Rack env instance



62
63
64
# File 'lib/waw/kern/living_state.rb', line 62

def rack_env
  waw_state.rack_env
end

#real_sessionObject

Returns the current Rack session



82
83
84
# File 'lib/waw/kern/living_state.rb', line 82

def real_session
  waw_state.rack_session
end

#requestObject

Returns the current Rack request instance



67
68
69
# File 'lib/waw/kern/living_state.rb', line 67

def request
  waw_state.rack_request
end

#responseObject

Returns the current Rack request instance



72
73
74
# File 'lib/waw/kern/living_state.rb', line 72

def response
  waw_state.rack_response
end

#sessionObject

Returns the waw session decorator



87
88
89
# File 'lib/waw/kern/living_state.rb', line 87

def session
  waw_state.waw_session
end

#waw_stateObject

Returns the current waw_state object



56
57
58
59
# File 'lib/waw/kern/living_state.rb', line 56

def waw_state
  install_living_state({}) if Thread.current[:waw_state].nil?
  Thread.current[:waw_state].first
end