Class: Rack::MiniProfiler::ClientSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_profiler/client_settings.rb

Constant Summary collapse

"__profilin"
BACKTRACE_DEFAULT =
nil
BACKTRACE_FULL =
1
BACKTRACE_NONE =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

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.cookies[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_levelObject

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_profilingObject

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

Returns:

  • (Boolean)


56
57
58
# File 'lib/mini_profiler/client_settings.rb', line 56

def backtrace_default?
  @backtrace_level == BACKTRACE_DEFAULT
end

#backtrace_full?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/mini_profiler/client_settings.rb', line 52

def backtrace_full?
  @backtrace_level == BACKTRACE_FULL
end

#backtrace_none?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/mini_profiler/client_settings.rb', line 60

def backtrace_none?
  @backtrace_level == BACKTRACE_NONE
end

#disable_profiling?Boolean

Returns:

  • (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 discard_cookie!(headers)
  Rack::Utils.delete_cookie_header!(headers, COOKIE_NAME, :path => '/')
end

#has_cookie?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/mini_profiler/client_settings.rb', line 44

def has_cookie?
  !@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.set_cookie_header!(headers, COOKIE_NAME, :value => settings_string, :path => '/')
  end
end