Permalink
Browse files

After much wrangling, simply hid the links to explain, profile, and s…

…elect when running under sqlite3
  • Loading branch information...
1 parent 6c03c88 commit 5d06867d1c7b9e3a11126be5d30953b9d6688753 @konklone konklone committed Jul 14, 2009
Showing with 7,622 additions and 1 deletion.
  1. +4 −1 config/environments/development.rb
  2. +3 −0 vendor/plugins/rack-bug/.gitignore
  3. 0 vendor/plugins/rack-bug/History.txt
  4. +19 −0 vendor/plugins/rack-bug/MIT-LICENSE.txt
  5. +19 −0 vendor/plugins/rack-bug/README.rdoc
  6. +49 −0 vendor/plugins/rack-bug/Rakefile
  7. +26 −0 vendor/plugins/rack-bug/lib/rack/bug.rb
  8. +90 −0 vendor/plugins/rack-bug/lib/rack/bug/options.rb
  9. +50 −0 vendor/plugins/rack-bug/lib/rack/bug/panel.rb
  10. +35 −0 vendor/plugins/rack-bug/lib/rack/bug/panel_app.rb
  11. +46 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/active_record_panel.rb
  12. +18 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/active_record_panel/activerecord_extensions.rb
  13. +51 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/cache_panel.rb
  14. +129 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/cache_panel/memcache_extension.rb
  15. +50 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/cache_panel/panel_app.rb
  16. +97 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/cache_panel/stats.rb
  17. +25 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/env_panel.rb
  18. +39 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/log_panel.rb
  19. +11 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/log_panel/rails_extension.rb
  20. +27 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/memory_panel.rb
  21. +23 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/rails_info_panel.rb
  22. +25 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/request_variables_panel.rb
  23. +55 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/sql_panel.rb
  24. +39 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/sql_panel/panel_app.rb
  25. +95 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/sql_panel/query.rb
  26. +11 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/sql_panel/sql_extension.rb
  27. +44 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/templates_panel.rb
  28. +12 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/templates_panel/actionview_extension.rb
  29. +67 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/templates_panel/rendering.rb
  30. +34 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/templates_panel/trace.rb
  31. +41 −0 vendor/plugins/rack-bug/lib/rack/bug/panels/timer_panel.rb
  32. +65 −0 vendor/plugins/rack-bug/lib/rack/bug/params_signature.rb
  33. +10 −0 vendor/plugins/rack-bug/lib/rack/bug/public/__rack_bug__/bookmarklet.html
  34. +215 −0 vendor/plugins/rack-bug/lib/rack/bug/public/__rack_bug__/bookmarklet.js
  35. +186 −0 vendor/plugins/rack-bug/lib/rack/bug/public/__rack_bug__/bug.css
  36. +69 −0 vendor/plugins/rack-bug/lib/rack/bug/public/__rack_bug__/bug.js
  37. +4,376 −0 vendor/plugins/rack-bug/lib/rack/bug/public/__rack_bug__/jquery-1.3.2.js
  38. BIN vendor/plugins/rack-bug/lib/rack/bug/public/__rack_bug__/spinner.gif
  39. +67 −0 vendor/plugins/rack-bug/lib/rack/bug/render.rb
  40. +145 −0 vendor/plugins/rack-bug/lib/rack/bug/toolbar.rb
  41. +16 −0 vendor/plugins/rack-bug/lib/rack/bug/views/error.html.erb
  42. +17 −0 vendor/plugins/rack-bug/lib/rack/bug/views/panels/active_record.html.erb
  43. +93 −0 vendor/plugins/rack-bug/lib/rack/bug/views/panels/cache.html.erb
  44. +19 −0 vendor/plugins/rack-bug/lib/rack/bug/views/panels/env.html.erb
  45. +32 −0 vendor/plugins/rack-bug/lib/rack/bug/views/panels/execute_sql.html.erb
  46. +32 −0 vendor/plugins/rack-bug/lib/rack/bug/views/panels/explain_sql.html.erb
  47. +23 −0 vendor/plugins/rack-bug/lib/rack/bug/views/panels/log.html.erb
  48. +32 −0 vendor/plugins/rack-bug/lib/rack/bug/views/panels/profile_sql.html.erb
  49. +19 −0 vendor/plugins/rack-bug/lib/rack/bug/views/panels/rails_info.html.erb
  50. +87 −0 vendor/plugins/rack-bug/lib/rack/bug/views/panels/request_variables.html.erb
  51. +43 −0 vendor/plugins/rack-bug/lib/rack/bug/views/panels/sql.html.erb
  52. +7 −0 vendor/plugins/rack-bug/lib/rack/bug/views/panels/templates.html.erb
  53. +19 −0 vendor/plugins/rack-bug/lib/rack/bug/views/panels/timer.html.erb
  54. +19 −0 vendor/plugins/rack-bug/lib/rack/bug/views/panels/view_cache.html.erb
  55. +16 −0 vendor/plugins/rack-bug/lib/rack/bug/views/redirect.html.erb
  56. +41 −0 vendor/plugins/rack-bug/lib/rack/bug/views/toolbar.html.erb
  57. +8 −0 vendor/plugins/rack-bug/spec/fixtures/config.ru
  58. +2 −0 vendor/plugins/rack-bug/spec/fixtures/dummy_panel.rb
  59. +29 −0 vendor/plugins/rack-bug/spec/fixtures/sample_app.rb
  60. +30 −0 vendor/plugins/rack-bug/spec/rack/bug/panels/active_record_panel_spec.rb
  61. +159 −0 vendor/plugins/rack-bug/spec/rack/bug/panels/cache_panel_spec.rb
  62. +24 −0 vendor/plugins/rack-bug/spec/rack/bug/panels/env_panel_spec.rb
  63. +25 −0 vendor/plugins/rack-bug/spec/rack/bug/panels/log_panel_spec.rb
  64. +21 −0 vendor/plugins/rack-bug/spec/rack/bug/panels/memory_panel_spec.rb
  65. +25 −0 vendor/plugins/rack-bug/spec/rack/bug/panels/rails_info_panel_spec.rb
  66. +136 −0 vendor/plugins/rack-bug/spec/rack/bug/panels/sql_panel_spec.rb
  67. +71 −0 vendor/plugins/rack-bug/spec/rack/bug/panels/templates_panel_spec.rb
  68. +38 −0 vendor/plugins/rack-bug/spec/rack/bug/panels/timer_panel_spec.rb
  69. +100 −0 vendor/plugins/rack-bug/spec/rack/toolbar_spec.rb
  70. +1 −0 vendor/plugins/rack-bug/spec/rcov.opts
  71. +1 −0 vendor/plugins/rack-bug/spec/spec.opts
  72. +70 −0 vendor/plugins/rack-bug/spec/spec_helper.rb
View
5 config/environments/development.rb
@@ -20,4 +20,7 @@
SITE_HOST = 'localhost:3000'
-config.middleware.use "Rack::Bug"
+require 'rack/bug'
+ActionController::Dispatcher.middleware.use ::Rack::Bug,
+ :ip_masks => [IPAddr.new("127.0.0.1")],
+ :secret_key => "secretkeeeeeeeeeyyyyyyyyyyyyyy"
View
3 vendor/plugins/rack-bug/.gitignore
@@ -0,0 +1,3 @@
+coverage
+pkg
+TODO
View
0 vendor/plugins/rack-bug/History.txt
No changes.
View
19 vendor/plugins/rack-bug/MIT-LICENSE.txt
@@ -0,0 +1,19 @@
+Copyright (c) 2009 Bryan Helmkamp
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
19 vendor/plugins/rack-bug/README.rdoc
@@ -0,0 +1,19 @@
+Usage:
+
+ script/plugin install git://github.com/brynary/rack-bug.git
+
+ # config/environments/development.rb
+ config.middleware.use "Rack::Bug"
+
+ # add bookmarklet to browser
+ open http://RAILS_APP/__rack_bug__/bookmarklet.html
+
+Thanks to:
+
+ Django debug toolbar
+ Rails footnotes
+ Rack's ShowException middleware
+ Oink
+ Rack::Cache
+
+
View
49 vendor/plugins/rack-bug/Rakefile
@@ -0,0 +1,49 @@
+require "rubygems"
+require "rake/gempackagetask"
+require "rake/clean"
+require "spec/rake/spectask"
+
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib'
+
+require "rack/bug"
+
+Spec::Rake::SpecTask.new do |t|
+ t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
+end
+
+desc "Run the specs"
+task :default => :spec
+
+desc "Run all specs in spec directory with RCov"
+Spec::Rake::SpecTask.new(:rcov) do |t|
+ t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
+ t.rcov = true
+ t.rcov_opts = lambda do
+ IO.readlines(File.dirname(__FILE__) + "/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
+ end
+end
+
+spec = Gem::Specification.new do |s|
+ s.name = "rack-bug"
+ s.version = Rack::Bug::VERSION
+ s.author = "Bryan Helmkamp"
+ s.email = "bryan" + "@" + "brynary.com"
+ s.homepage = "http://github.com/brynary/rack-bug"
+ s.summary = "Debugging toolbar for Rack applications implemented as middleware"
+ s.description = s.summary
+ s.files = %w[History.txt Rakefile README.rdoc] + Dir["lib/**/*"]
+
+ # rdoc
+ s.has_rdoc = true
+ s.extra_rdoc_files = %w(README.rdoc MIT-LICENSE.txt)
+end
+
+Rake::GemPackageTask.new(spec) do |package|
+ package.gem_spec = spec
+end
+
+desc 'Install the package as a gem.'
+task :install => [:clean, :package] do
+ gem = Dir['pkg/*.gem'].first
+ sh "sudo gem install --no-rdoc --no-ri --local #{gem}"
+end
View
26 vendor/plugins/rack-bug/lib/rack/bug.rb
@@ -0,0 +1,26 @@
+require "rack"
+
+module Rack::Bug
+ require "rack/bug/toolbar"
+
+ VERSION = "0.1.0"
+
+ class SecurityError < StandardError
+ end
+
+ def self.enable
+ Thread.current["rack-bug.enabled"] = true
+ end
+
+ def self.disable
+ Thread.current["rack-bug.enabled"] = false
+ end
+
+ def self.enabled?
+ Thread.current["rack-bug.enabled"] == true
+ end
+
+ def self.new(*args, &block)
+ Toolbar.new(*args, &block)
+ end
+end
View
90 vendor/plugins/rack-bug/lib/rack/bug/options.rb
@@ -0,0 +1,90 @@
+module Rack::Bug
+
+ module Options
+ class << self
+ private
+ def option_accessor(key)
+ define_method(key) { || read_option(key) }
+ define_method("#{key}=") { |value| write_option(key, value) }
+ define_method("#{key}?") { || !! read_option(key) }
+ end
+ end
+
+ option_accessor :secret_key
+ option_accessor :ip_masks
+ option_accessor :password
+ option_accessor :panel_classes
+ option_accessor :intercept_redirects
+
+ # The underlying options Hash. During initialization (or outside of a
+ # request), this is a default values Hash. During a request, this is the
+ # Rack environment Hash. The default values Hash is merged in underneath
+ # the Rack environment before each request is processed.
+ def options
+ @env || @default_options
+ end
+
+ # Set multiple options.
+ def options=(hash={})
+ hash.each { |key,value| write_option(key, value) }
+ end
+
+ # Set an option. When +option+ is a Symbol, it is set in the Rack
+ # Environment as "rack-cache.option". When +option+ is a String, it
+ # exactly as specified. The +option+ argument may also be a Hash in
+ # which case each key/value pair is merged into the environment as if
+ # the #set method were called on each.
+ def set(option, value=self, &block)
+ if block_given?
+ write_option option, block
+ elsif value == self
+ self.options = option.to_hash
+ else
+ write_option option, value
+ end
+ end
+
+ private
+
+ def read_option(key)
+ options[option_name(key)]
+ end
+
+ def write_option(key, value)
+ options[option_name(key)] = value
+ end
+
+ def option_name(key)
+ case key
+ when Symbol ; "rack-bug.#{key}"
+ when String ; key
+ else raise ArgumentError
+ end
+ end
+
+ def initialize_options(options={})
+ @default_options = {
+ 'rack-bug.ip_masks' => [IPAddr.new("127.0.0.1")],
+ 'rack-bug.password' => nil,
+ 'rack-bug.verbose' => nil,
+ 'rack-bug.secret_key' => nil,
+ 'rack-bug.intercept_redirects' => false,
+ 'rack-bug.panels' => [],
+ 'rack-bug.panel_classes' => [
+ RailsInfoPanel,
+ TimerPanel,
+ RequestVariablesPanel,
+ EnvPanel,
+ SQLPanel,
+ ActiveRecordPanel,
+ CachePanel,
+ TemplatesPanel,
+ LogPanel,
+ MemoryPanel
+ ]
+ }
+ self.options = options
+ end
+
+ end
+end
View
50 vendor/plugins/rack-bug/lib/rack/bug/panel.rb
@@ -0,0 +1,50 @@
+require "erb"
+
+module Rack
+ module Bug
+
+ # Panels are also Rack middleware
+ class Panel
+ include Render
+ include ERB::Util
+
+ attr_reader :request
+
+ def initialize(app)
+ if panel_app
+ @app = Rack::Cascade.new([panel_app, app])
+ else
+ @app = app
+ end
+ end
+
+ def call(env)
+ before(env)
+ status, headers, body = @app.call(env)
+ @request = Request.new(env)
+ after(env, status, headers, body)
+ env["rack-bug.panels"] << self
+ return [status, headers, body]
+ end
+
+ def panel_app
+ nil
+ end
+
+ def has_content?
+ true
+ end
+
+ def before(env)
+ end
+
+ def after(env, status, headers, body)
+ end
+
+ def render(template)
+ end
+
+ end
+
+ end
+end
View
35 vendor/plugins/rack-bug/lib/rack/bug/panel_app.rb
@@ -0,0 +1,35 @@
+require "rack/bug/params_signature"
+
+module Rack
+ module Bug
+
+ class PanelApp
+ include Rack::Bug::Render
+
+ attr_reader :request
+
+ def call(env)
+ @request = Rack::Request.new(env)
+ dispatch
+ end
+
+ def render_template(*args)
+ Rack::Response.new([super]).to_a
+ end
+
+ def params
+ @request.GET
+ end
+
+ def not_found
+ [404, {}, []]
+ end
+
+ def validate_params
+ ParamsSignature.new(request).validate!
+ end
+
+ end
+
+ end
+end
View
46 vendor/plugins/rack-bug/lib/rack/bug/panels/active_record_panel.rb
@@ -0,0 +1,46 @@
+require "rack/bug/panel"
+require "rack/bug/panels/active_record_panel/activerecord_extensions"
+
+module Rack
+ module Bug
+
+ class ActiveRecordPanel < Panel
+
+ def self.record(class_name)
+ return unless Rack::Bug.enabled?
+ records[class_name] += 1
+ end
+
+ def self.reset
+ Thread.current["rack.bug.active_records"] = Hash.new { 0 }
+ end
+
+ def self.records
+ Thread.current["rack.bug.active_records"] ||= Hash.new { 0 }
+ end
+
+ def self.total
+ records.inject(0) do |memo, (key, value)|
+ memo + value
+ end
+ end
+
+ def name
+ "active_record"
+ end
+
+ def heading
+ "#{self.class.total} AR Objects"
+ end
+
+ def content
+ records = self.class.records.to_a.sort_by { |key, value| value }.reverse
+ result = render_template "panels/active_record", :records => records
+ self.class.reset
+ result
+ end
+
+ end
+
+ end
+end
View
18 vendor/plugins/rack-bug/lib/rack/bug/panels/active_record_panel/activerecord_extensions.rb
@@ -0,0 +1,18 @@
+if defined?(ActiveRecord)
+ ActiveRecord::Base.class_eval do
+
+ if instance_methods.include?("after_initialize")
+ def after_initialize_with_rack_bug
+ Rack::Bug::ActiveRecordPanel.record(self.class.base_class.name)
+ after_initialize_without_rack_bug
+ end
+
+ alias_method_chain :after_initialize, :rack_bug
+ else
+ def after_initialize
+ Rack::Bug::ActiveRecordPanel.record(self.class.base_class.name)
+ end
+ end
+
+ end
+end
View
51 vendor/plugins/rack-bug/lib/rack/bug/panels/cache_panel.rb
@@ -0,0 +1,51 @@
+require "rack/bug/panels/cache_panel/memcache_extension"
+
+module Rack
+ module Bug
+
+ class CachePanel < Panel
+
+ require "rack/bug/panels/cache_panel/stats"
+ require "rack/bug/panels/cache_panel/panel_app"
+
+ def self.record(method, *keys, &block)
+ return block.call unless Rack::Bug.enabled?
+
+ start_time = Time.now
+ result = block.call
+ total_time = Time.now - start_time
+ hit = result.nil? ? false : true
+ stats.record_call(method, total_time * 1_000, hit, *keys)
+ return result
+ end
+
+ def self.reset
+ Thread.current["rack.bug.cache"] = Stats.new
+ end
+
+ def self.stats
+ Thread.current["rack.bug.cache"] ||= Stats.new
+ end
+
+ def panel_app
+ PanelApp.new
+ end
+
+ def name
+ "cache"
+ end
+
+ def heading
+ "Cache: %.2fms (#{self.class.stats.queries.size} calls)" % self.class.stats.time
+ end
+
+ def content
+ result = render_template "panels/cache", :stats => self.class.stats
+ self.class.reset
+ return result
+ end
+
+ end
+
+ end
+end
View
129 vendor/plugins/rack-bug/lib/rack/bug/panels/cache_panel/memcache_extension.rb
@@ -0,0 +1,129 @@
+if defined?(Memcached)
+ Memcached.class_eval do
+
+ def set_with_rack_bug(key, value, timeout=0, marshal=true)
+ Rack::Bug::CachePanel.record(:set, key) do
+ set_without_rack_bug(key, value, timeout, marshal)
+ end
+ end
+
+ def add_with_rack_bug(key, value, timeout=0, marshal=true)
+ Rack::Bug::CachePanel.record(:add, key) do
+ add_without_rack_bug(key, value, timeout, marshal)
+ end
+ end
+
+ def increment_with_rack_bug(key, offset=1)
+ Rack::Bug::CachePanel.record(:incr, key) do
+ increment_without_rack_bug(key, offset)
+ end
+ end
+
+ def decrement_with_rack_bug(key, offset=1)
+ Rack::Bug::CachePanel.record(:decr, key) do
+ decrement_without_rack_bug(key, offset)
+ end
+ end
+
+ def replace_with_rack_bug(key, value, timeout=0, marshal=true)
+ Rack::Bug::CachePanel.record(:replace, key) do
+ replace_without_rack_bug(key, value, timeout, marshal)
+ end
+ end
+
+ def append_with_rack_bug(key, value)
+ Rack::Bug::CachePanel.record(:append, key) do
+ append_without_rack_bug(key, value)
+ end
+ end
+
+ def prepend_with_rack_bug(key, value)
+ Rack::Bug::CachePanel.record(:prepend, key) do
+ prepend_without_rack_bug(key, value)
+ end
+ end
+
+ def delete_with_rack_bug(key)
+ Rack::Bug::CachePanel.record(:delete, key) do
+ delete_without_rack_bug(key)
+ end
+ end
+
+ def get_with_rack_bug(keys, marshal=true)
+ if keys.is_a? Array
+ Rack::Bug::CachePanel.record(:get_multi, *keys) do
+ get_without_rack_bug(keys, marshal)
+ end
+ else
+ Rack::Bug::CachePanel.record(:get, keys) do
+ get_without_rack_bug(keys, marshal)
+ end
+ end
+ end
+
+ alias_method_chain :decrement, :rack_bug
+ alias_method_chain :get, :rack_bug
+ alias_method_chain :increment, :rack_bug
+ alias_method_chain :set, :rack_bug
+ alias_method_chain :add, :rack_bug
+ alias_method_chain :replace, :rack_bug
+ alias_method_chain :delete, :rack_bug
+ alias_method_chain :prepend, :rack_bug
+ alias_method_chain :append, :rack_bug
+ end
+end
+
+if defined?(MemCache)
+ MemCache.class_eval do
+
+ def decr_with_rack_bug(key, amount = 1)
+ Rack::Bug::CachePanel.record(:decr, key) do
+ decr_without_rack_bug(key, amount)
+ end
+ end
+
+ def get_with_rack_bug(key, raw = false)
+ Rack::Bug::CachePanel.record(:get, key) do
+ get_without_rack_bug(key, raw)
+ end
+ end
+
+ def get_multi_with_rack_bug(*keys)
+ Rack::Bug::CachePanel.record(:get_multi, *keys) do
+ get_multi_without_rack_bug(*keys)
+ end
+ end
+
+ def incr_with_rack_bug(key, amount = 1)
+ Rack::Bug::CachePanel.record(:incr, key) do
+ incr_without_rack_bug(key, amount)
+ end
+ end
+
+ def set_with_rack_bug(key, value, expiry = 0, raw = false)
+ Rack::Bug::CachePanel.record(:set, key) do
+ set_without_rack_bug(key, value, expiry, raw)
+ end
+ end
+
+ def add_with_rack_bug(key, value, expiry = 0, raw = false)
+ Rack::Bug::CachePanel.record(:add, key) do
+ add_without_rack_bug(key, value, expiry, raw)
+ end
+ end
+
+ def delete_with_rack_bug(key, expiry = 0)
+ Rack::Bug::CachePanel.record(:delete, key) do
+ delete_without_rack_bug(key, expiry)
+ end
+ end
+
+ alias_method_chain :decr, :rack_bug
+ alias_method_chain :get, :rack_bug
+ alias_method_chain :get_multi, :rack_bug
+ alias_method_chain :incr, :rack_bug
+ alias_method_chain :set, :rack_bug
+ alias_method_chain :add, :rack_bug
+ alias_method_chain :delete, :rack_bug
+ end
+end
View
50 vendor/plugins/rack-bug/lib/rack/bug/panels/cache_panel/panel_app.rb
@@ -0,0 +1,50 @@
+require "rack/bug/panel_app"
+
+module Rack
+ module Bug
+ class CachePanel
+
+ class PanelApp < ::Rack::Bug::PanelApp
+
+ def dispatch
+ case request.path_info
+ when "/__rack_bug__/view_cache" then view_cache
+ when "/__rack_bug__/delete_cache" then delete_cache
+ when "/__rack_bug__/delete_cache_list" then delete_cache_list
+ else not_found
+ end
+ end
+
+ def ok
+ Rack::Response.new(["OK"]).to_a
+ end
+
+ def view_cache
+ validate_params
+ render_template "panels/view_cache", :key => params["key"], :value => Rails.cache.read(params["key"])
+ end
+
+ def delete_cache
+ validate_params
+ raise "Rails not found... can't delete key" unless defined?(Rails)
+ Rails.cache.delete(params["key"])
+ ok
+ end
+
+ def delete_cache_list
+ validate_params
+ raise "Rails not found... can't delete key" unless defined?(Rails)
+
+ params.each do |key, value|
+ next unless key =~ /^keys_/
+ Rails.cache.delete(value)
+ end
+
+ ok
+ end
+
+ end
+
+ end
+ end
+end
View
97 vendor/plugins/rack-bug/lib/rack/bug/panels/cache_panel/stats.rb
@@ -0,0 +1,97 @@
+module Rack
+ module Bug
+ class CachePanel
+
+ class Stats
+ class Query
+ attr_reader :method, :time, :hit, :keys
+
+ def initialize(method, time, hit, keys)
+ @method = method
+ @time = time
+ @hit = hit
+ @keys = keys
+ end
+
+ def display_time
+ "%.2fms" % time
+ end
+
+ def display_keys
+ if keys.size == 1
+ keys.first
+ else
+ keys.join(", ")
+ end
+ end
+ end
+
+ attr_reader :calls
+ attr_reader :keys
+ attr_reader :queries
+
+ def initialize
+ @queries = []
+ @misses =
+ @calls = 0
+ @time = 0.0
+ @keys = []
+ end
+
+ def record_call(method, time, hit, *keys)
+ @queries << Query.new(method, time, hit, keys)
+ @calls += 1
+ @time += time
+ @keys += keys
+ end
+
+ def display_time
+ "%.2fms" % time
+ end
+
+ def time
+ @queries.inject(0) do |memo, query|
+ memo + query.time
+ end
+ end
+
+ def gets
+ count_queries(:get)
+ end
+
+ def sets
+ count_queries(:set)
+ end
+
+ def deletes
+ count_queries(:delete)
+ end
+
+ def get_multis
+ count_queries(:get_multi)
+ end
+
+ def hits
+ @queries.select { |q| [:get, :get_multi].include?(q.method) && q.hit }.size
+ end
+
+ def misses
+ @queries.select { |q| [:get, :get_multi].include?(q.method) && !q.hit }.size
+ end
+
+ def count_queries(method)
+ @queries.select { |q| q.method == method }.size
+ end
+
+ def queries_to_param
+ params = {}
+ @queries.each_with_index do |query, index|
+ params["keys_#{index}"] = query.keys.first
+ end
+ params
+ end
+ end
+
+ end
+ end
+end
View
25 vendor/plugins/rack-bug/lib/rack/bug/panels/env_panel.rb
@@ -0,0 +1,25 @@
+module Rack
+ module Bug
+
+ class EnvPanel < Panel
+
+ def name
+ "env"
+ end
+
+ def before(env)
+ @env = env
+ end
+
+ def heading
+ "Rack Env"
+ end
+
+ def content
+ render_template "panels/env", :env => @env
+ end
+
+ end
+
+ end
+end
View
39 vendor/plugins/rack-bug/lib/rack/bug/panels/log_panel.rb
@@ -0,0 +1,39 @@
+require "rack/bug/panels/log_panel/rails_extension"
+
+module Rack
+ module Bug
+
+ class LogPanel < Panel
+
+ def self.record(message)
+ return unless Rack::Bug.enabled?
+ return unless message
+ logs << message.to_s
+ end
+
+ def self.reset
+ Thread.current["rack.bug.logs"] = []
+ end
+
+ def self.logs
+ Thread.current["rack.bug.logs"] ||= []
+ end
+
+ def name
+ "log"
+ end
+
+ def heading
+ "Log"
+ end
+
+ def content
+ result = render_template "panels/log", :logs => self.class.logs
+ self.class.reset
+ return result
+ end
+
+ end
+
+ end
+end
View
11 vendor/plugins/rack-bug/lib/rack/bug/panels/log_panel/rails_extension.rb
@@ -0,0 +1,11 @@
+if defined?(Rails) && Rails.logger
+ module LoggingExtensions
+ def add(*args, &block)
+ logged_message = super
+ Rack::Bug::LogPanel.record(logged_message)
+ return logged_message
+ end
+ end
+
+ Rails.logger.extend LoggingExtensions
+end
View
27 vendor/plugins/rack-bug/lib/rack/bug/panels/memory_panel.rb
@@ -0,0 +1,27 @@
+#
+module Rack
+ module Bug
+
+ class MemoryPanel < Panel
+
+ def before(env)
+ @original_memory = `ps -o rss= -p #{$$}`.to_i
+ end
+
+ def after(env, status, headers, body)
+ @total_memory = `ps -o rss= -p #{$$}`.to_i
+ @memory_increase = @total_memory - @original_memory
+ end
+
+ def heading
+ "#{@memory_increase} KB &#916;, #{@total_memory} KB total"
+ end
+
+ def has_content?
+ false
+ end
+
+ end
+
+ end
+end
View
23 vendor/plugins/rack-bug/lib/rack/bug/panels/rails_info_panel.rb
@@ -0,0 +1,23 @@
+module Rack
+ module Bug
+
+ class RailsInfoPanel < Panel
+
+ def name
+ "rails_info"
+ end
+
+ def heading
+ return unless defined?(Rails)
+ "Rails #{Rails.version}"
+ end
+
+ def content
+ return unless defined?(Rails)
+ render_template "panels/rails_info"
+ end
+
+ end
+
+ end
+end
View
25 vendor/plugins/rack-bug/lib/rack/bug/panels/request_variables_panel.rb
@@ -0,0 +1,25 @@
+module Rack
+ module Bug
+
+ class RequestVariablesPanel < Panel
+
+ def name
+ "request_variables"
+ end
+
+ def before(env)
+ @env = env
+ end
+
+ def heading
+ "Request Vars"
+ end
+
+ def content
+ render_template "panels/request_variables", :request => @request
+ end
+
+ end
+
+ end
+end
View
55 vendor/plugins/rack-bug/lib/rack/bug/panels/sql_panel.rb
@@ -0,0 +1,55 @@
+require "digest"
+
+module Rack
+ module Bug
+
+ class SQLPanel < Panel
+
+ require "rack/bug/panels/sql_panel/sql_extension"
+ require "rack/bug/panels/sql_panel/query"
+ require "rack/bug/panels/sql_panel/panel_app"
+
+ def panel_app
+ PanelApp.new
+ end
+
+ def self.record(sql, backtrace = [], &block)
+ return block.call unless Rack::Bug.enabled?
+
+ start_time = Time.now
+ result = block.call
+ queries << Query.new(sql, Time.now - start_time, backtrace)
+
+ return result
+ end
+
+ def self.reset
+ Thread.current["rack.test.queries"] = []
+ end
+
+ def self.queries
+ Thread.current["rack.test.queries"] ||= []
+ end
+
+ def self.total_time
+ (queries.inject(0) { |memo, query| memo + query.time}) * 1_000
+ end
+
+ def name
+ "sql"
+ end
+
+ def heading
+ "#{self.class.queries.size} Queries (%.2fms)" % self.class.total_time
+ end
+
+ def content
+ result = render_template "panels/sql", :queries => self.class.queries
+ self.class.reset
+ return result
+ end
+
+ end
+
+ end
+end
View
39 vendor/plugins/rack-bug/lib/rack/bug/panels/sql_panel/panel_app.rb
@@ -0,0 +1,39 @@
+require "rack/bug/panel_app"
+
+module Rack
+ module Bug
+ class SQLPanel
+
+ class PanelApp < ::Rack::Bug::PanelApp
+
+ def dispatch
+ case request.path_info
+ when "/__rack_bug__/explain_sql" then explain_sql
+ when "/__rack_bug__/profile_sql" then profile_sql
+ when "/__rack_bug__/execute_sql" then execute_sql
+ else not_found
+ end
+ end
+
+ def explain_sql
+ validate_params
+ query = Query.new(params["query"], params["time"].to_f)
+ render_template "panels/explain_sql", :result => query.explain, :query => query.sql, :time => query.time
+ end
+
+ def profile_sql
+ validate_params
+ query = Query.new(params["query"], params["time"].to_f)
+ render_template "panels/profile_sql", :result => query.profile, :query => query.sql, :time => query.time
+ end
+
+ def execute_sql
+ validate_params
+ query = Query.new(params["query"], params["time"].to_f)
+ render_template "panels/execute_sql", :result => query.execute, :query => query.sql, :time => query.time
+ end
+
+ end
+ end
+ end
+end
View
95 vendor/plugins/rack-bug/lib/rack/bug/panels/sql_panel/query.rb
@@ -0,0 +1,95 @@
+module Rack
+ module Bug
+ class SQLPanel
+
+ class Query
+ attr_reader :sql
+ attr_reader :time
+ attr_reader :backtrace
+
+ def initialize(sql, time, backtrace = [])
+ @sql = sql
+ @time = time
+ @backtrace = backtrace
+ end
+
+ def human_time
+ "%.2fms" % (@time * 1_000)
+ end
+
+ def inspectable?
+ sql.strip =~ /^SELECT /i
+ end
+
+ def with_profiling
+ self.class.execute("SET PROFILING=1")
+ result = yield
+ self.class.execute("SET PROFILING=0")
+ return result
+ end
+
+ def explain
+ self.class.execute "EXPLAIN #{@sql}"
+ end
+
+ def profile
+ with_profiling do
+ execute
+ self.class.execute <<-SQL
+ SELECT *
+ FROM information_schema.profiling
+ WHERE query_id = (SELECT query_id FROM information_schema.profiling ORDER BY query_id DESC LIMIT 1)
+ SQL
+ end
+ end
+
+ def execute
+ self.class.execute(@sql)
+ end
+
+ def valid_hash?(secret_key, possible_hash)
+ hash = Digest::SHA1.hexdigest [secret_key, @sql].join(":")
+ possible_hash == hash
+ end
+
+ def self.execute(sql)
+ ActiveRecord::Base.connection.execute(sql)
+ end
+
+ def self.adapter
+ klass = ActiveRecord::Base.connection.class.to_s
+ parts = klass.split '::'
+ if parts and parts.any?
+ adapter = parts.last.gsub('Adapter', '').downcase.to_sym
+ else
+ :unknown
+ end
+ end
+
+ def adapter
+ self.class.adapter
+ end
+
+ def self.mysql?
+ adapter == :mysql
+ end
+
+ def mysql?
+ self.class.mysql?
+ end
+
+ def has_backtrace?
+ filtered_backtrace.any?
+ end
+
+ def filtered_backtrace
+ @filtered_backtrace ||= @backtrace.map { |l| l.to_s.strip }.select do |line|
+ line.starts_with?(Rails.root) &&
+ !line.starts_with?(Rails.root.join("vendor"))
+ end
+ end
+ end
+
+ end
+ end
+end
View
11 vendor/plugins/rack-bug/lib/rack/bug/panels/sql_panel/sql_extension.rb
@@ -0,0 +1,11 @@
+if defined?(ActiveRecord)
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do
+ def log_with_rack_bug(sql, name, &block)
+ Rack::Bug::SQLPanel.record(sql, Kernel.caller) do
+ log_without_rack_bug(sql, name, &block)
+ end
+ end
+
+ alias_method_chain :log, :rack_bug
+ end
+end
View
44 vendor/plugins/rack-bug/lib/rack/bug/panels/templates_panel.rb
@@ -0,0 +1,44 @@
+module Rack
+ module Bug
+
+ class TemplatesPanel < Panel
+
+ require "rack/bug/panels/templates_panel/actionview_extension"
+ require "rack/bug/panels/templates_panel/trace"
+ require "rack/bug/panels/templates_panel/rendering"
+
+ def self.record(template, &block)
+ return block.call unless Rack::Bug.enabled?
+
+ template_trace.start(template)
+ result = block.call
+ template_trace.finished(template)
+ return result
+ end
+
+ def self.reset
+ Thread.current["rack.bug.template_trace"] = Trace.new
+ end
+
+ def self.template_trace
+ Thread.current["rack.bug.template_trace"] ||= Trace.new
+ end
+
+ def name
+ "templates"
+ end
+
+ def heading
+ "Templates: %.2fms" % (self.class.template_trace.total_time * 1_000)
+ end
+
+ def content
+ result = render_template "panels/templates", :template_trace => self.class.template_trace
+ self.class.reset
+ return result
+ end
+
+ end
+
+ end
+end
View
12 vendor/plugins/rack-bug/lib/rack/bug/panels/templates_panel/actionview_extension.rb
@@ -0,0 +1,12 @@
+if defined?(ActionView) && defined?(ActionView::Template)
+ ActionView::Template.class_eval do
+
+ def render_template_with_rack_bug(*args, &block)
+ Rack::Bug::TemplatesPanel.record(path_without_format_and_extension) do
+ render_template_without_rack_bug(*args, &block)
+ end
+ end
+
+ alias_method_chain :render_template, :rack_bug
+ end
+end
View
67 vendor/plugins/rack-bug/lib/rack/bug/panels/templates_panel/rendering.rb
@@ -0,0 +1,67 @@
+module Rack
+ module Bug
+ class TemplatesPanel
+
+ class Rendering
+ attr_accessor :name
+ attr_accessor :start_time
+ attr_accessor :end_time
+ attr_accessor :parent
+ attr_reader :children
+
+
+ def initialize(name)
+ @name = name
+ @children = []
+ end
+
+ def add(rendering)
+ @children << rendering
+ rendering.parent = self
+ end
+
+ def time
+ @end_time - @start_time
+ end
+
+ def exclusive_time
+ time - child_time
+ end
+
+ def child_time
+ children.inject(0.0) { |memo, c| memo + c.time }
+ end
+
+ def time_summary
+ if children.any?
+ "%.2fms, %.2f exclusive" % [time * 1_000, exclusive_time * 1_000]
+ else
+ "%.2fms" % (time * 1_000)
+ end
+ end
+ def html
+ <<-HTML
+ <li>
+ <p>#{name} (#{time_summary})</p>
+
+ #{children_html}
+ </li>
+ HTML
+ end
+
+ def children_html
+ return "" unless children.any?
+
+ <<-HTML
+ <ul>#{joined_children_html}</ul>
+ HTML
+ end
+
+ def joined_children_html
+ children.map { |c| c.html }.join
+ end
+ end
+
+ end
+ end
+end
View
34 vendor/plugins/rack-bug/lib/rack/bug/panels/templates_panel/trace.rb
@@ -0,0 +1,34 @@
+module Rack
+ module Bug
+ class TemplatesPanel
+
+ class Trace
+
+ def start(template_name)
+ rendering = Rendering.new(template_name)
+ rendering.start_time = Time.now
+ @current.add(rendering)
+ @current = rendering
+ end
+
+ def finished(template_name)
+ @current.end_time = Time.now
+ @current = @current.parent
+ end
+
+ def initialize
+ @current = root
+ end
+
+ def total_time
+ root.child_time
+ end
+
+ def root
+ @root ||= Rendering.new("root")
+ end
+ end
+
+ end
+ end
+end
View
41 vendor/plugins/rack-bug/lib/rack/bug/panels/timer_panel.rb
@@ -0,0 +1,41 @@
+require "rack/bug/panel"
+require "benchmark"
+
+module Rack
+ module Bug
+
+ class TimerPanel < Panel
+
+ def name
+ "timer"
+ end
+
+ def call(env)
+ status, headers, body = nil
+ @times = Benchmark.measure do
+ status, headers, body = @app.call(env)
+ end
+
+ @measurements = [
+ ["User CPU time", "%.2fms" % (@times.utime * 1_000)],
+ ["System CPU time", "%.2fms" % (@times.stime * 1_000)],
+ ["Total CPU time", "%.2fms" % (@times.total * 1_000)],
+ ["Elapsed time", "%.2fms" % (@times.real * 1_000)]
+ ]
+
+ env["rack-bug.panels"] << self
+ return [status, headers, body]
+ end
+
+ def heading
+ "%.2fms" % (@times.real * 1_000)
+ end
+
+ def content
+ render_template "panels/timer", :measurements => @measurements
+ end
+
+ end
+
+ end
+end
View
65 vendor/plugins/rack-bug/lib/rack/bug/params_signature.rb
@@ -0,0 +1,65 @@
+require "digest"
+
+module Rack
+ module Bug
+
+ class ParamsSignature
+ extend ERB::Util
+
+ def self.sign(request, hash)
+ parts = []
+
+ hash.keys.sort.each do |key|
+ parts << "#{key}=#{u(hash[key])}"
+ end
+
+ signature = new(request).signature(hash)
+ parts << "hash=#{u(signature)}"
+
+ parts.join("&amp;")
+ end
+
+ attr_reader :request
+
+ def initialize(request)
+ @request = request
+ end
+
+ def secret_key
+ @request.env['rack-bug.secret_key']
+ end
+
+ def secret_key_blank?
+ secret_key.nil? || secret_key == ""
+ end
+
+ def validate!
+ if secret_key_blank?
+ raise SecurityError.new("Missing secret key")
+ end
+
+ if secret_key_blank? || request.params["hash"] != signature(request.params)
+ raise SecurityError.new("Invalid query hash.")
+ end
+ end
+
+ def signature(params)
+ Digest::SHA1.hexdigest(signature_base(params))
+ end
+
+ def signature_base(params)
+ signature = []
+ signature << secret_key
+
+ params.keys.sort.each do |key|
+ next if key == "hash"
+ signature << params[key].to_s
+ end
+
+ signature.join(":")
+ end
+
+ end
+
+ end
+end
View
10 vendor/plugins/rack-bug/lib/rack/bug/public/__rack_bug__/bookmarklet.html
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ </head>
+ <body>
+ <br/><br/><br/>
+ <a href="javascript: (function(){var script=document.createElement('script'); script.src='/__rack_bug__/bookmarklet.js'; document.getElementsByTagName('head')[0].appendChild(script);})()">
+ Toggle Rack::Bug
+ </a>
+ </body>
+</html>
View
215 vendor/plugins/rack-bug/lib/rack/bug/public/__rack_bug__/bookmarklet.js
@@ -0,0 +1,215 @@
+/**
+*
+* Secure Hash Algorithm (SHA1)
+* http://www.webtoolkit.info/
+*
+**/
+
+document.SHA1 = function(msg) {
+ function rotate_left(n,s) {
+ var t4 = ( n<<s ) | (n>>>(32-s));
+ return t4;
+ };
+
+ function lsb_hex(val) {
+ var str="";
+ var i;
+ var vh;
+ var vl;
+
+ for( i=0; i<=6; i+=2 ) {
+ vh = (val>>>(i*4+4))&0x0f;
+ vl = (val>>>(i*4))&0x0f;
+ str += vh.toString(16) + vl.toString(16);
+ }
+ return str;
+ };
+
+ function cvt_hex(val) {
+ var str="";
+ var i;
+ var v;
+
+ for( i=7; i>=0; i-- ) {
+ v = (val>>>(i*4))&0x0f;
+ str += v.toString(16);
+ }
+ return str;
+ };
+
+
+ function Utf8Encode(string) {
+ string = string.replace(/\r\n/g,"\n");
+ var utftext = "";
+
+ for (var n = 0; n < string.length; n++) {
+
+ var c = string.charCodeAt(n);
+
+ if (c < 128) {
+ utftext += String.fromCharCode(c);
+ }
+ else if((c > 127) && (c < 2048)) {
+ utftext += String.fromCharCode((c >> 6) | 192);
+ utftext += String.fromCharCode((c & 63) | 128);
+ }
+ else {
+ utftext += String.fromCharCode((c >> 12) | 224);
+ utftext += String.fromCharCode(((c >> 6) & 63) | 128);
+ utftext += String.fromCharCode((c & 63) | 128);
+ }
+
+ }
+
+ return utftext;
+ };
+
+ var blockstart;
+ var i, j;
+ var W = new Array(80);
+ var H0 = 0x67452301;
+ var H1 = 0xEFCDAB89;
+ var H2 = 0x98BADCFE;
+ var H3 = 0x10325476;
+ var H4 = 0xC3D2E1F0;
+ var A, B, C, D, E;
+ var temp;
+
+ msg = Utf8Encode(msg);
+
+ var msg_len = msg.length;
+
+ var word_array = new Array();
+ for( i=0; i<msg_len-3; i+=4 ) {
+ j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
+ msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
+ word_array.push( j );
+ }
+
+ switch( msg_len % 4 ) {
+ case 0:
+ i = 0x080000000;
+ break;
+ case 1:
+ i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
+ break;
+
+ case 2:
+ i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
+ break;
+
+ case 3:
+ i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8 | 0x80;
+ break;
+ }
+
+ word_array.push( i );
+
+ while( (word_array.length % 16) != 14 ) word_array.push( 0 );
+
+ word_array.push( msg_len>>>29 );
+ word_array.push( (msg_len<<3)&0x0ffffffff );
+
+
+ for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
+
+ for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
+ for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
+
+ A = H0;
+ B = H1;
+ C = H2;
+ D = H3;
+ E = H4;
+
+ for( i= 0; i<=19; i++ ) {
+ temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
+ E = D;
+ D = C;
+ C = rotate_left(B,30);
+ B = A;
+ A = temp;
+ }
+
+ for( i=20; i<=39; i++ ) {
+ temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
+ E = D;
+ D = C;
+ C = rotate_left(B,30);
+ B = A;
+ A = temp;
+ }
+
+ for( i=40; i<=59; i++ ) {
+ temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
+ E = D;
+ D = C;
+ C = rotate_left(B,30);
+ B = A;
+ A = temp;
+ }
+
+ for( i=60; i<=79; i++ ) {
+ temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
+ E = D;
+ D = C;
+ C = rotate_left(B,30);
+ B = A;
+ A = temp;
+ }
+
+ H0 = (H0 + A) & 0x0ffffffff;
+ H1 = (H1 + B) & 0x0ffffffff;
+ H2 = (H2 + C) & 0x0ffffffff;
+ H3 = (H3 + D) & 0x0ffffffff;
+ H4 = (H4 + E) & 0x0ffffffff;
+
+ }
+
+ var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
+
+ return temp.toLowerCase();
+}
+
+document.createCookie = function(name,value,days) {
+ if (days) {
+ var date = new Date();
+ date.setTime(date.getTime()+(days*24*60*60*1000));
+ var expires = "; expires="+date.toGMTString();
+ }
+ else
+ var expires = "";
+ document.cookie = name+"="+value+expires+"; path=/";
+}
+
+document.readCookie = function(name) {
+ var nameEQ = name + "=";
+ var ca = document.cookie.split(';');
+ for(var i=0;i < ca.length;i++) {
+ var c = ca[i];
+ while (c.charAt(0)==' ')
+ c = c.substring(1,c.length);
+ if (c.indexOf(nameEQ) == 0)
+ return c.substring(nameEQ.length,c.length);
+ }
+ return null;
+}
+
+document.eraseCookie = function(name) {
+ document.createCookie(name,"",-1);
+}
+
+document.rackBugBookmarklet = function() {
+ if (document.readCookie('rack_bug_password')) {
+ document.eraseCookie('rack_bug_password');
+ document.eraseCookie('rack_bug_enabled');
+ alert('Rack::Bug Disabled');
+ } else {
+ var password = prompt("Rack::Bug password:", "")
+ document.createCookie('rack_bug_password', document.SHA1('rack_bug:'+password));
+ document.createCookie('rack_bug_enabled', "1");
+ alert('Rack::Bug Enabled');
+ }
+}
+
+document.rackBugBookmarklet();
View
186 vendor/plugins/rack-bug/lib/rack/bug/public/__rack_bug__/bug.css
@@ -0,0 +1,186 @@
+#rack_bug {
+ color: #000;
+ float: none;
+ margin: 0;
+ padding: 0;
+ position: static;
+}
+
+#rack_bug a {
+ color: #f7c757;
+}
+#rack_bug a:hover {
+ color: #aaa;
+}
+
+#rack_bug_toolbar {
+ background: #326342;
+ height: 30px;
+ z-index: 100000000;
+ border-bottom: 2px solid #234f32;
+ position:absolute;
+ top:0;
+ left:0;
+ right:0;
+}
+
+.rack_bug_error #rack_bug_toolbar {
+ background: #ff0000;
+ color: #fff;
+ border: none;
+}
+
+.rack_bug_error #rack_bug_toolbar p {
+ margin-top: 6px;
+ margin-left: 15px;
+ font-weight: bold;
+ color: #fff;
+}
+
+#rack_bug_toolbar ul {
+ margin: 0;
+ padding: 0;
+ list-style: none;
+}
+
+#rack_bug_toolbar li {
+ color: #fff;
+ display: inline;
+ font-size: 11px;
+ font-weight: bold;
+ float: none;
+ height: 20px;
+ margin: 0;
+ padding: 0;
+ line-height: 30px;
+ position: relative;
+ width: auto;
+}
+#rack_bug_toolbar li a {
+ border-left: 1px solid #487858;
+ padding: 8px 9px 9px;
+}
+
+#rack_bug_toolbar li a:hover {
+ background: #487858;
+ color: #fff;
+}
+
+#rack_bug_toolbar li:last-child {
+ border-right: 1px solid #487858;
+}
+
+#rack_bug_toolbar #rb_debug_button {
+ color: #92ef3f;
+ padding-left: 20px;
+}
+
+#rack_bug .panel_content {
+ background: #2a5738;
+ border-bottom: 2px solid #234f32;
+ border-top: 2px solid #487858;
+ display: none;
+ position: absolute;
+ margin: 0;
+ padding: 10px;
+ top: 32px;
+ width: auto;
+ left: 0px;
+ right: 0px;
+ bottom: 5px;
+ color: black;
+ z-index: 1000000;
+ overflow: auto;
+}
+
+#rack_bug .panel_content p a,
+#rack_bug .panel_content dl a {
+ color: #40684c;
+}
+
+#rack_bug .panel_content p a:hover,
+#rack_bug .panel_content dl a:hover {
+ color: #92EF3F;
+}
+
+#rack_bug .panel_content h3 {
+ border-bottom: 1px solid #40684c;
+ color: #92ef3f;
+ padding: 0 0 5px;
+}
+
+#rack_bug .panel_content p {
+ padding: 0 5px;
+}
+
+#rack_bug .panel_content p,
+#rack_bug .panel_content table,
+#rack_bug .panel_content ol,
+#rack_bug .panel_content dl {
+ margin: 5px 0 15px;
+ background-color: #fff;
+}
+
+#rack_bug .panel_content ul {
+ padding: 10px 30px 10px 30px;
+ background-color: #fff;
+}
+
+#rack_bug .panel_content ul ul {
+ padding: 0;
+}
+
+#rack_bug .panel_content table {
+ width: 100%;
+ clear: both;
+}
+
+#rack_bug .panel_content table a {
+ color: #40684C;
+}
+
+#rack_bug .panel_content table th {
+ background-color: #9dcc49;
+ font-weight: bold;
+ color: #000;
+ font-size: 11px;
+ padding: 3px 7px 3px;
+ text-align: left;
+ cursor: pointer;
+ border-right: 1px solid #b9d977;
+}
+
+#rack_bug .panel_content table td {
+ padding: 5px 10px;
+ font-size: 11px;
+ background: #fff;
+ color: #000;
+ vertical-align: top;
+}
+#rack_bug .panel_content table tr.odd td {
+ background: #eee;
+}
+
+#rack_bug .panel_content .rack_bug_close {
+ float: right;
+ font-weight: bold;
+}
+
+#rack_bug .panel_content dt, #rack_bug .panel_content dd {
+ display: block;
+}
+
+#rack_bug .panel_content dd {
+ margin-left: 10px;
+}
+
+#rack_bug .panel_content table tr.odd td.rack_bug_spinner,
+#rack_bug .panel_content table tr.even td.rack_bug_spinner,
+#rack_bug .panel_content table td.rack_bug_spinner,
+#rack_bug .rack_bug_spinner {
+ background-image: url(/__rack_bug__/spinner.gif);
+ background-repeat: no-repeat;
+ background-position: center center;
+ text-indent: -3000px;
+ color: transparent;
+}
View
69 vendor/plugins/rack-bug/lib/rack/bug/public/__rack_bug__/bug.js
@@ -0,0 +1,69 @@
+var _$ = window.$;
+jQuery.noConflict();
+jQuery(function($) {
+ $.rackBug = function(data, klass) {
+ $.rackBug.init();
+ }
+ $.extend($.rackBug, {
+ init: function() {
+ var current = null;
+ $('#rack_bug ul.panels li a').click(function() {
+ current = $('#rack_bug #' + this.className);
+
+ if (current.is(':visible')) {
+ $(document).trigger('close.rackBug');
+ } else {
+ $('#rack_bug .panel_content').hide();
+ current.show();
+ $.rackBug.open();
+ }
+ return false;
+ });
+ $('#rack_bug a.remote_call').click(function() {
+ $('#rack_bug_debug_window').load(this.href, null, function() {
+ $('#rack_bug_debug_window a.back').click(function() {
+ $(this).parent().hide();
+ return false;
+ });
+ });
+ $('#rack_bug_debug_window').show();
+ return false;
+ });
+ $('#rack_bug a.reveal_backtrace').click(function() {
+ $(this).parents("tr").next().toggle();
+ return false;
+ });
+ $('#rack_bug a.rack_bug_close').click(function() {
+ $(document).trigger('close.rackBug');
+ return false;
+ });
+ },
+ open: function() {
+ $(document).bind('keydown.rackBug', function(e) {
+ if (e.keyCode == 27) {
+ $.rackBug.close();
+ }
+ });
+ },
+ toggle_content: function(elem) {
+ if (elem.is(':visible')) {
+ elem.hide();
+ } else {
+ elem.show();
+ }
+ },
+ close: function() {
+ $(document).trigger('close.rackBug');
+ return false;
+ }
+ });
+ $(document).bind('close.rackBug', function() {
+ $(document).unbind('keydown.rackBug');
+ $('.panel_content').hide();
+ });
+});
+
+jQuery(function() {
+ jQuery.rackBug();
+});
+$ = _$;
View
4,376 vendor/plugins/rack-bug/lib/rack/bug/public/__rack_bug__/jquery-1.3.2.js
4,376 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
BIN vendor/plugins/rack-bug/lib/rack/bug/public/__rack_bug__/spinner.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
67 vendor/plugins/rack-bug/lib/rack/bug/render.rb
@@ -0,0 +1,67 @@
+require "erb"
+
+module Rack
+ module Bug
+
+ module Render
+ include ERB::Util
+
+ def signed_params(hash)
+ # require "rubygems"; require "ruby-debug"; Debugger.start; debugger
+ ParamsSignature.sign(request, hash)
+ end
+
+ module CompiledTemplates
+ end
+ include CompiledTemplates
+
+ def render_template(filename, local_assigns = {})
+ compile(filename, local_assigns)
+ render_symbol = method_name(filename, local_assigns)
+ send(render_symbol, local_assigns)
+ end
+
+ def compile(filename, local_assigns)
+ render_symbol = method_name(filename, local_assigns)
+
+ if !CompiledTemplates.instance_methods.include?(render_symbol.to_s)
+ compile!(filename, local_assigns)
+ end
+ end
+
+ def compile!(filename, local_assigns)
+ render_symbol = method_name(filename, local_assigns)
+ locals_code = local_assigns.keys.map { |key| "#{key} = local_assigns[:#{key}];" }.join
+
+ source = <<-end_src
+ def #{render_symbol}(local_assigns)
+ #{locals_code}
+ #{compiled_source(filename)}
+ end
+ end_src
+
+ CompiledTemplates.module_eval(source, filename, 0)
+ end
+
+ def compiled_source(filename)
+ ::ERB.new(::File.read(::File.dirname(__FILE__) + "/../bug/views/#{filename}.html.erb"), nil, "-").src
+ end
+
+ def method_name(filename, local_assigns)
+ if local_assigns && local_assigns.any?
+ method_name = method_name_without_locals(filename).dup
+ method_name << "_locals_#{local_assigns.keys.map { |k| k.to_s }.sort.join('_')}"
+ else
+ method_name = method_name_without_locals(filename)
+ end
+ method_name.to_sym
+ end
+
+ def method_name_without_locals(filename)
+ filename.split("/").join("_")
+ end
+
+ end
+
+ end
+end
View
145 vendor/plugins/rack-bug/lib/rack/bug/toolbar.rb
@@ -0,0 +1,145 @@
+require "ipaddr"
+require "digest"
+
+require "rack/bug/options"
+require "rack/bug/render"
+
+Dir[File.dirname(__FILE__) + "/panels/*.rb"].each do |panel_name|
+ require "rack/bug/panels/" + File.basename(panel_name)
+end
+
+module Rack
+ module Bug
+
+ class RackStaticBugAvoider
+ def initialize(app, static_app)
+ @app = app
+ @static_app = static_app
+ end
+
+ def call(env)
+ if env["PATH_INFO"]
+ @static_app.call(env)
+ else
+ @app.call(env)
+ end
+ end
+ end
+
+ class Toolbar
+ include Options
+ include Render
+
+ MIME_TYPES = ["text/html", "application/xhtml+xml"]
+
+ def initialize(app, options = {})
+ @app = asset_server(app)
+ initialize_options options
+ instance_eval(&block) if block_given?
+ end
+
+ def asset_server(app)
+ RackStaticBugAvoider.new(app, Rack::Static.new(app, :urls => ["/__rack_bug__"], :root => public_path))
+ end
+
+ def public_path
+ ::File.expand_path(::File.dirname(__FILE__) + "/../bug/public")
+ end
+
+ def call(env)
+ env.replace @default_options.merge(env)
+ @env = env
+ @original_request = Request.new(@env)
+
+ if toolbar_requested? && ip_authorized? && password_authorized?
+ dispatch
+ else
+ pass
+ end
+ end
+
+ def pass
+ @app.call(@env)
+ end
+
+ def dispatch
+ @env["rack-bug.panels"] = []
+
+ Rack::Bug.enable
+ status, headers, body = builder.call(@env)
+ Rack::Bug.disable
+
+ @response = Rack::Response.new(body, status, headers)
+
+ if @response.redirect? && options["rack-bug.intercept_redirects"]
+ intercept_redirect
+ elsif modify?
+ inject_toolbar
+ end
+
+ return @response.to_a
+ end
+
+ def intercept_redirect
+ redirect_to = @response.location
+ new_body = render_template("redirect", :redirect_to => @response.location)
+ new_response = Rack::Response.new(new_body, 200, { "Content-Type" => "text/html" })
+ new_response["Content-Length"] = new_body.size.to_s
+ @response = new_response
+ end
+
+ def toolbar_requested?
+ @original_request.cookies["rack_bug_enabled"]
+ end
+
+ def ip_authorized?
+ return true unless options["rack-bug.ip_masks"]
+
+ options["rack-bug.ip_masks"].any? do |ip_mask|
+ ip_mask.include?(IPAddr.new(@original_request.ip))
+ end
+ end
+
+ def password_authorized?
+ return true unless options["rack-bug.password"]
+
+ expected_sha = Digest::SHA1.hexdigest ["rack_bug", options["rack-bug.password"]].join(":")
+ actual_sha = @original_request.cookies["rack_bug_password"]
+
+ actual_sha == expected_sha
+ end
+
+ def modify?
+ @response.ok? &&
+ @env["X-Requested-With"] != "XMLHttpRequest" &&
+ MIME_TYPES.include?(@response.content_type.split(";").first)
+ end
+
+ def builder
+ builder = Rack::Builder.new
+
+ options["rack-bug.panel_classes"].each do |panel_class|
+ builder.use panel_class
+ end
+
+ builder.run @app
+
+ return builder
+ end
+
+ def inject_toolbar
+ full_body = @response.body.join
+ full_body.sub! /<\/body>/, render + "</body>"
+
+ @response["Content-Length"] = full_body.size.to_s
+ @response.body = [full_body]
+ end
+
+ def render
+ render_template("toolbar", :panels => @env["rack-bug.panels"].reverse)
+ end
+
+ end
+
+ end
+end
View
16 vendor/plugins/rack-bug/lib/rack/bug/views/error.html.erb
@@ -0,0 +1,16 @@
+<script type="text/javascript" charset="utf-8">
+ if (typeof jQuery == 'undefined') {
+ var jquery_url = '/__rack_bug__/jquery-1.3.2.js';
+ document.write(unescape('%3Cscript src="' + jquery_url + '" type="text/javascript"%3E%3C/script%3E'));
+ }
+</script>
+<script type="text/javascript" src="/__rack_bug__/bug.js"></script>
+<style type="text/css" media="screen">
+ @import url(/__rack_bug__/bug.css);
+</style>
+
+<div id="rack_bug" class="rack_bug_error">
+ <div id="rack_bug_toolbar">
+ <p>There was an error within Rack::Bug!</p>
+ </div>
+</div>
View
17 vendor/plugins/rack-bug/lib/rack/bug/views/panels/active_record.html.erb
@@ -0,0 +1,17 @@
+<h3>ActiveRecord Objects</h3>
+<table>
+ <thead>
+ <tr>
+ <th>Count</th>
+ <th>Class</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% records.each do |class_name, count| %>
+ <tr>
+ <td><%= count %></td>
+ <td><%= class_name %></td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
View
93 vendor/plugins/rack-bug/lib/rack/bug/views/panels/cache.html.erb
@@ -0,0 +1,93 @@
+<h3>Cache Usage</h3>
+<table id="cache_usage">
+ <colgroup>
+ <col width="12%"/>
+ <col width="12%"/>
+ <col width="12%"/>
+ <col width="12%"/>
+ <col width="12%"/>
+ <col width="12%"/>
+ <col width="12%"/>
+ <col width="12%"/>
+ </colgroup>
+ <tr>
+ <th>Total Calls</th>
+ <td><%= stats.calls %></td>
+
+ <th>Total Time</th>
+ <td><%= stats.display_time %></td>
+
+ <th>Hits</th>
+ <td><%= stats.hits %></td>
+
+ <th>Misses</th>
+ <td><%= stats.misses %></td>
+ </tr>
+ <tr>
+ <th>gets</th>
+ <td><%= stats.gets %></td>
+
+ <th>sets</th>
+ <td><%= stats.sets %></td>
+
+ <th>deletes</th>
+ <td><%= stats.deletes %></td>
+
+ <th>get_multis</th>
+ <td><%= stats.get_multis %></td>
+ </tr>
+</table>
+
+<% if stats.queries.any? %>
+ <h3>Breakdown</h3>
+ <table id="cache_breakdown">
+ <thead>
+ <tr>
+ <th>Time&nbsp;(ms)</th>
+ <th>Type</th>
+ <th>Parameters</th>
+ <th>Function</th>
+ <th>
+ <a href="/__rack_bug__/delete_cache_list?<%= signed_params(stats.queries_to_param) %>" class="rb_delete_cache">
+ Delete All
+ </a>
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ <% i = 1 %>
+