Class: Rack::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/passport/helpers/rack-context.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Context

Returns a new instance of Context.



3
4
5
# File 'lib/passport/helpers/rack-context.rb', line 3

def initialize(app)
  @app = app
end

Class Method Details

.delete_session_key(key) ⇒ Object



65
66
67
68
69
# File 'lib/passport/helpers/rack-context.rb', line 65

def delete_session_key(key)
  return if session.blank?
  keys = key.is_a?(Symbol) ? [key, key.to_s] : [key, key.to_sym]
  keys.each { |k| session.delete(k) }
end

.envObject



25
26
27
# File 'lib/passport/helpers/rack-context.rb', line 25

def env
  request.nil? ? nil : request.env
end

.find(key) ⇒ Object



29
30
31
# File 'lib/passport/helpers/rack-context.rb', line 29

def find(key)
  params_key(key) || session_key(key)
end

.find_pair(attribute) ⇒ Object



61
62
63
# File 'lib/passport/helpers/rack-context.rb', line 61

def find_pair(attribute)
  
end

.key?(key) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/passport/helpers/rack-context.rb', line 33

def key?(key)
  !find(key).blank?
end

.paramsObject



21
22
23
# File 'lib/passport/helpers/rack-context.rb', line 21

def params
  request.nil? ? nil : request.params
end

.params_key(key) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/passport/helpers/rack-context.rb', line 49

def params_key(key)
  return nil if params.blank?
  string = key.to_s
  symbol = key.to_sym
  return params[string] unless params[string].blank?
  return params[symbol] unless params[symbol].blank?
end

.params_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/passport/helpers/rack-context.rb', line 57

def params_key?(key)
  !params_key(key).blank?
end

.requestObject



13
14
15
# File 'lib/passport/helpers/rack-context.rb', line 13

def request
  Thread.current[:rack_context]
end

.sessionObject



17
18
19
# File 'lib/passport/helpers/rack-context.rb', line 17

def session
  request.nil? ? nil : request.session
end

.session_key(key) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/passport/helpers/rack-context.rb', line 37

def session_key(key)
  return nil if session.blank?
  string = key.to_s
  symbol = key.to_sym
  return session[string] unless session[string].blank?
  return session[symbol] unless session[symbol].blank?
end

.session_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/passport/helpers/rack-context.rb', line 45

def session_key?(key)
  !session_key(key).blank?
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
# File 'lib/passport/helpers/rack-context.rb', line 7

def call(env)
  Thread.current[:rack_context] = Rack::Request.new(env)
  @app.call(env)
end