Class: Rack::Context
- Inherits:
-
Object
- Object
- Rack::Context
- Defined in:
- lib/passport/helpers/rack-context.rb
Class Method Summary collapse
- .delete_session_key(key) ⇒ Object
- .env ⇒ Object
- .find(key) ⇒ Object
- .find_pair(attribute) ⇒ Object
- .key?(key) ⇒ Boolean
- .params ⇒ Object
- .params_key(key) ⇒ Object
- .params_key?(key) ⇒ Boolean
- .request ⇒ Object
- .session ⇒ Object
- .session_key(key) ⇒ Object
- .session_key?(key) ⇒ Boolean
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Context
constructor
A new instance of Context.
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 |
.env ⇒ Object
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
33 34 35 |
# File 'lib/passport/helpers/rack-context.rb', line 33 def key?(key) !find(key).blank? end |
.params ⇒ Object
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
57 58 59 |
# File 'lib/passport/helpers/rack-context.rb', line 57 def params_key?(key) !params_key(key).blank? end |
.request ⇒ Object
13 14 15 |
# File 'lib/passport/helpers/rack-context.rb', line 13 def request Thread.current[:rack_context] end |
.session ⇒ Object
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
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 |