Class: Rack::MiniProfiler::ClientSettings
- Inherits:
-
Object
- Object
- Rack::MiniProfiler::ClientSettings
- Defined in:
- lib/mini_profiler/client_settings.rb
Constant Summary collapse
- COOKIE_NAME =
"__profilin"
- BACKTRACE_DEFAULT =
nil
- BACKTRACE_FULL =
1
- BACKTRACE_NONE =
2
Instance Attribute Summary collapse
-
#backtrace_level ⇒ Object
Returns the value of attribute backtrace_level.
-
#disable_profiling ⇒ Object
Returns the value of attribute disable_profiling.
Instance Method Summary collapse
- #backtrace_default? ⇒ Boolean
- #backtrace_full? ⇒ Boolean
- #backtrace_none? ⇒ Boolean
- #disable_profiling? ⇒ Boolean
- #discard_cookie!(headers) ⇒ Object
- #has_cookie? ⇒ Boolean
-
#initialize(env) ⇒ ClientSettings
constructor
A new instance of ClientSettings.
- #write!(headers) ⇒ Object
Constructor Details
#initialize(env) ⇒ ClientSettings
Returns a new instance of ClientSettings.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mini_profiler/client_settings.rb', line 15 def initialize(env) request = ::Rack::Request.new(env) @cookie = request.[COOKIE_NAME] if @cookie @cookie.split(",").map{|pair| pair.split("=")}.each do |k,v| @orig_disable_profiling = @disable_profiling = (v=='t') if k == "dp" @backtrace_level = v.to_i if k == "bt" end end @backtrace_level = nil if !@backtrace_level.nil? && (@backtrace_level == 0 || @backtrace_level > BACKTRACE_NONE) @orig_backtrace_level = @backtrace_level end |
Instance Attribute Details
#backtrace_level ⇒ Object
Returns the value of attribute backtrace_level.
12 13 14 |
# File 'lib/mini_profiler/client_settings.rb', line 12 def backtrace_level @backtrace_level end |
#disable_profiling ⇒ Object
Returns the value of attribute disable_profiling.
11 12 13 |
# File 'lib/mini_profiler/client_settings.rb', line 11 def disable_profiling @disable_profiling end |
Instance Method Details
#backtrace_default? ⇒ Boolean
56 57 58 |
# File 'lib/mini_profiler/client_settings.rb', line 56 def backtrace_default? @backtrace_level == BACKTRACE_DEFAULT end |
#backtrace_full? ⇒ Boolean
52 53 54 |
# File 'lib/mini_profiler/client_settings.rb', line 52 def backtrace_full? @backtrace_level == BACKTRACE_FULL end |
#backtrace_none? ⇒ Boolean
60 61 62 |
# File 'lib/mini_profiler/client_settings.rb', line 60 def backtrace_none? @backtrace_level == BACKTRACE_NONE end |
#disable_profiling? ⇒ Boolean
48 49 50 |
# File 'lib/mini_profiler/client_settings.rb', line 48 def disable_profiling? @disable_profiling end |
#discard_cookie!(headers) ⇒ Object
40 41 42 |
# File 'lib/mini_profiler/client_settings.rb', line 40 def (headers) Rack::Utils.(headers, COOKIE_NAME, :path => '/') end |
#has_cookie? ⇒ Boolean
44 45 46 |
# File 'lib/mini_profiler/client_settings.rb', line 44 def !@cookie.nil? end |
#write!(headers) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/mini_profiler/client_settings.rb', line 30 def write!(headers) if @orig_disable_profiling != @disable_profiling || @orig_backtrace_level != @backtrace_level || @cookie.nil? settings = {"p" => "t" } settings["dp"] = "t" if @disable_profiling settings["bt"] = @backtrace_level if @backtrace_level settings_string = settings.map{|k,v| "#{k}=#{v}"}.join(",") Rack::Utils.(headers, COOKIE_NAME, :value => settings_string, :path => '/') end end |