Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
After much wrangling, simply hid the links to explain, profile, and s…
…elect when running under sqlite3
- Loading branch information
Showing
72 changed files
with
7,622 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage | ||
pkg | ||
TODO |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
46 changes: 46 additions & 0 deletions
46
vendor/plugins/rack-bug/lib/rack/bug/panels/active_record_panel.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
18 changes: 18 additions & 0 deletions
18
vendor/plugins/rack-bug/lib/rack/bug/panels/active_record_panel/activerecord_extensions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.