diff --git a/History.txt b/CHANGELOG similarity index 67% rename from History.txt rename to CHANGELOG index 3262cba..837c854 100644 --- a/History.txt +++ b/CHANGELOG @@ -1,4 +1,17 @@ -== HEAD +== 0.5.0 / 2012-08-29 - transition to rack_insight + + * Compatibility + + * Restructure gem so Insight is inside a namespace, because I have classes named Insight that are obscured by + logical_insight gem when loaded. Logical also seemed like it may be a class name somewhere, hence going back to + the Rack namespace a la rack-bug. Keeping the (now nested) Insight namespace as well, because - genetics. + + *Other + + * Fix spelling of retreive => retrieve (Peter Boling) + * Remove redundant time method from cache_panel/stats.rb + +== 0.4.X - last of logical_insight * New features @@ -21,7 +34,7 @@ * Refactoring and code cleanup (Tim Connor) * Testing cleanup - better isolation of Rails vs. non-Rails in tests (Tim Connor) - + == 0.3.0 / 2010-05-28 * New features diff --git a/Gemfile.lock b/Gemfile.lock index a8af349..3bfddde 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,46 +1,19 @@ PATH remote: . specs: - logical-insight (0.4.7) - sqlite3 (~> 1.3.3) - uuid (~> 2.3.1) + rack-insight (0.5.0) + rack + sqlite3 (>= 1.3.3) + uuidtools (>= 2.1.2) GEM remote: http://gemcutter.org/ specs: archive-tar-minitar (0.5.2) - chunky_png (1.2.5) columnize (0.3.4) - compass (0.12.1) - chunky_png (~> 1.2) - fssm (>= 0.2.7) - sass (~> 3.1) - corundum (0.0.17) - bundler (~> 1.1.0) - compass (>= 0.12.1) - mailfactory (~> 1.4.0) - mattock (>= 0.2.11) - nokogiri - rake-rubygems (>= 0.2.0) - rdoc - rspec (>= 2.0) - sass (>= 3.1) - simplecov (>= 0.5.4) - yard diff-lcs (1.1.3) - fssm (0.2.9) - json (1.7.3) linecache19 (0.5.12) ruby_core_source (>= 0.1.4) - macaddr (1.6.0) - systemu (~> 2.2.0) - mailfactory (1.4.0) - mime-types (>= 1.13.1) - mattock (0.2.12) - tilt (> 0) - valise (>= 0.6) - mime-types (1.18) - multi_json (1.3.5) nokogiri (1.5.2) rack (1.3.5) rack-protection (1.1.4) @@ -48,11 +21,16 @@ GEM rack-test (0.6.1) rack (>= 1.0) rake (0.9.2.2) - rake-rubygems (0.2.0) - rake (>= 0.8.7) - rdoc (3.12) - json (~> 1.4) redcarpet (2.1.1) + reek (1.2.12) + ripper_ruby_parser (~> 0.0.7) + ruby2ruby (~> 1.2.5) + ruby_parser (~> 2.0) + sexp_processor (~> 3.0) + ripper_ruby_parser (0.0.8) + sexp_processor (~> 3.0) + roodi (2.1.0) + ruby_parser rspec (2.10.0) rspec-core (~> 2.10.0) rspec-expectations (~> 2.10.0) @@ -69,36 +47,35 @@ GEM columnize (>= 0.3.1) linecache19 (>= 0.5.11) ruby-debug-base19 (>= 0.11.19) + ruby2ruby (1.2.5) + ruby_parser (~> 2.0) + sexp_processor (~> 3.0) ruby_core_source (0.1.5) archive-tar-minitar (>= 0.5.2) - sass (3.1.18) - simplecov (0.6.4) - multi_json (~> 1.0) - simplecov-html (~> 0.5.3) - simplecov-html (0.5.3) + ruby_parser (2.3.1) + sexp_processor (~> 3.0) + sexp_processor (3.2.0) sinatra (1.3.1) rack (~> 1.3, >= 1.3.4) rack-protection (~> 1.1, >= 1.1.2) tilt (~> 1.3, >= 1.3.3) sqlite3 (1.3.6) - systemu (2.2.0) tilt (1.3.3) - uuid (2.3.5) - macaddr (~> 1.0) - valise (0.6) + uuidtools (2.1.3) webrat (0.7.3) nokogiri (>= 1.2.0) rack (>= 1.0) rack-test (>= 0.5.3) - yard (0.8.1) PLATFORMS ruby DEPENDENCIES - corundum (~> 0.0.13) - logical-insight! + rack-insight! + rake redcarpet + reek (>= 1.2.8) + roodi (>= 2.1.0) rspec ruby-debug19 sinatra diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..831196f --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +Copyright (c) 2012 Peter H. Boling as rack-insight +Copyright (c) 2011-12 LR Design as logical-insight +Copyright (c) 2009 Bryan Helmkamp as rack-bug + +MIT License + +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. diff --git a/MIT-LICENSE.txt b/MIT-LICENSE.txt deleted file mode 100644 index e2463e6..0000000 --- a/MIT-LICENSE.txt +++ /dev/null @@ -1,19 +0,0 @@ -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. diff --git a/README.md b/README.md index 4d62c6c..64edfb9 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,26 @@ -Insight +Rack::Insight ========= -Insight began life as an LRDesign fork of Rack::Bug by brynary. We started a -fork because, at the time, the main project wasn't making progress on Rails 3 -support. Since then we've rewritten a lot of the code to make it more modular, -easier to extend, and to store information about multiple requests so you can -use it to inspect your AJAX requests (or any past request), not just previous -page loads. +Rack::Insight began life as an fork of Logical::Insight by LRDesign. I started a +fork because LogicalInsight was namespaced as "Insight", which is causing namespace +collisions everywhere I have an Insight model. I had to re-namespace all the code. +I also needed to build a few extension gems with additional panels, and added the +Config class to allow for custom panel load paths, and other future extensions +that don't work in the *use Middleware* declaration. It should be *even* easier +to extend than LogicalInsight was, because extension gems can access the Config class +and truly bolt-on cleanly. -Having made really significant architectural changes, we'll be keeping Insight +Having made really significant architectural changes, I'll be keeping Rack::Insight a separate project for the forseeable future. -* Forked From: [rack-bug](http://github.com/brynary/rack-bug) - -* [Full documentation](http://lrdesign.github.com/logical-insight/) +* Forked From: [logical-insight](http://github.com/LRDesign/logical-insight), [documentation](http://lrdesign.github.com/rack-insight/) +* Which Was Forked From: [rack-bug](http://github.com/brynary/rack-bug) Description ----------- -Insight adds a diagnostics toolbar to Rack apps. When enabled, it injects a floating div -allowing exploration of logging, database queries, template rendering times, etc. Insight +Rack::Insight adds a diagnostics toolbar to Rack apps. When enabled, it injects a floating div +allowing exploration of logging, database queries, template rendering times, etc. Rack::Insight stores debugging info over many requests, incuding AJAX requests. Features @@ -27,7 +28,7 @@ Features * Password-based security * IP-based security -* Insight instrumentation/reporting is broken up into panels. +* Rack::Insight instrumentation/reporting is broken up into panels. * Panels in default configuration: * Rails Info * Timer @@ -54,22 +55,22 @@ Rails quick start --------------------------- Add this to your Gemfile - gem "logical-insight" + gem "rack-insight" In config/environments/development.rb, add: - config.middleware.use "Insight::App", + config.middleware.use "Rack::Insight::App", :secret_key => "someverylongandveryhardtoguesspreferablyrandomstring" -Any environment with Insight loaded will have a link to "Insight" added to as +Any environment with Rack::Insight loaded will have a link to "Rack::Insight" added to as the last child of BODY to normal responses. Clicking that link will load the -toolbar. It's set with an id of "logical-insight-enabler", so it can be styled +toolbar. It's set with an id of "rack-insight-enabler", so it can be styled to go somewhere more noticeable. E.g. "position: absolute; top: 0; left: 0" Using with non-Rails Rack apps ------------------------------ -Just 'use Insight' as any other middleware. See the SampleApp in the +Just 'use Rack::Insight' as any other middleware. See the SampleApp in the spec/fixtures folder for an example Sinatra app. If you wish to use the logger panel define the LOGGER constant that is a ruby @@ -80,9 +81,9 @@ Configuring custom panels Specify the set of panels you want, in the order you want them to appear: - require "logical-insight" + require "rack-insight" - ActionController::Dispatcher.middleware.use "Insight::App", + ActionController::Dispatcher.middleware.use "Rack::Insight::App", :secret_key => "someverylongandveryhardtoguesspreferablyrandomstring", :panel_files => %w[ timer_panel @@ -93,14 +94,30 @@ Specify the set of panels you want, in the order you want them to appear: memory_panel ] -Files are looked up by prepending "insight/panels/" and requiring them. -Subclasses of Insight::Panel are loaded and added to the toolbar. This makes -it easier to work with the configuration and extend Insight with plugin gems. +By default panel files are looked up by prepending "rack/insight/panels/" and requiring them. +Subclasses of Rack::Insight::Panel are loaded and added to the toolbar. This makes +it easier to work with the configuration and extend Rack::Insight with plugin gems. + +If you need to customize the load paths where Rack::Insight will look for panels you can configure the load paths in an +initializer. Example config/initializers/rack_insight.rb: + + Rack::Insight::Config.configure do |config| + + # Note: The parent directory of the 'special' directory must already be in Ruby's load path. + config[:panel_load_paths] = File.join('special','path') + + # Example 1: Do not load any of the regular Rack::Insight panels: + config[:panel_load_paths] = File.join('my','custom','panel','directory') + + # Example 2: Add your custom path to the existing load paths, to have your panels join the party! + config[:panel_load_paths] << 'custom/panels' + + end -Running Insight in staging or production +Running Rack::Insight in staging or production ------------------------------------------ -We have have found that Insight is fast enough to run in production for specific troubleshooting efforts. +We have have found that Rack::Insight is fast enough to run in production for specific troubleshooting efforts. ### Configuration #### @@ -113,23 +130,23 @@ Restrict access to particular IP addresses: require "ipaddr" - ActionController::Dispatcher.middleware.use "Insight::App" + ActionController::Dispatcher.middleware.use "Rack::Insight::App" :secret_key => "someverylongandveryhardtoguesspreferablyrandomstring", :ip_masks => [IPAddr.new("2.2.2.2/0")] Restrict access using a password: - ActionController::Dispatcher.middleware.use "Insight::App", + ActionController::Dispatcher.middleware.use "Rack::Insight::App", :secret_key => "someverylongandveryhardtoguesspreferablyrandomstring", :password => "yourpassword" #### custom file path for the logging database #### -Logical Insight uses SQLite to store data from requests, and outputs a database +Logical Rack::Insight uses SQLite to store data from requests, and outputs a database file in the root directory. If you need the file to be created at another location (i.e. Heroku), you can pass a custom file path. - ActionController::Dispatcher.middleware.use "Insight::App" + ActionController::Dispatcher.middleware.use "Rack::Insight::App" :secret_key => "someverylongandveryhardtoguesspreferablyrandomstring", :database_path => "tmp/my_insight_db.sqlite" @@ -142,15 +159,31 @@ Authors Thanks ------ -Insight owes a lot to Rack::Bug, as the basis project. There's a lot of smart -in there. Many thanks to Bryan for building it. +Rack::Insight owes a lot to both LogicalInsight and Rack::Bug, as the basis projects. There's a lot of smart +in there. Many thanks to Evan, Judson, and Bryan for building them. Inspiration for Rack::Bug is primarily from the Django debug toolbar. Additional ideas from Rails footnotes, Rack's ShowException middleware, Oink, and Rack::Cache - License ------- -See MIT-LICENSE.txt in this directory. +See LICENSE.txt in this directory. + +Notes +----- + +Legacy files: would like to re-include them, but they need work + + lib/insight/views/panels/mongo.html.erb + lib/insight/panels/mongo_panel/mongo_extension.rb + lib/insight/panels/mongo_panel/stats.rb + lib/insight/panels/mongo_panel.rb + + lib/insight/views/panels/sphinx.html.erb + lib/insight/panels/sphinx_panel/stats.rb + lib/insight/panels/sphinx_panel.rb + +This one is mostly just a curiosity + lib/insight/panels/speedtracer_panel/profiling.rb diff --git a/Rakefile b/Rakefile index b36960a..ca57272 100644 --- a/Rakefile +++ b/Rakefile @@ -1,31 +1,27 @@ -require 'yaml' -require 'corundum' -require 'corundum/tasklibs' +#!/usr/bin/env rake +require "bundler/gem_tasks" -module Corundum - tk = Toolkit.new do |tk| - end +require 'rake' - tk.in_namespace do - sanity = GemspecSanity.new(tk) - rspec = RSpec.new(tk) - cov = SimpleCov.new(tk, rspec) do |cov| - cov.threshold = 90 - end - gem = GemBuilding.new(tk) - cutter = GemCutter.new(tk,gem) - email = Email.new(tk) - vc = Git.new(tk) do |vc| - vc.branch = "master" - end - task tk.finished_files.build => vc["is_checked_in"] - yd = YARDoc.new(tk) do |yd| - yd.options = %w[--exclude lib/insight/views --exclude lib/insight/public] - end - all_docs = DocumentationAssembly.new(tk, yd, rspec, cov) do |da| - da.external_docs["The Wiki"] = "https://github.com/LRDesign/logical-insight/wiki" - da.external_docs["Github page"] = "https://github.com/LRDesign/logical-insight/" - end - pages = GithubPages.new(all_docs) - end +require 'rspec/core' +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new(:spec) do |spec| + spec.pattern = FileList['spec/**/*_spec.rb'] end + +require 'reek/rake/task' +Reek::Rake::Task.new do |t| + t.fail_on_error = true + t.verbose = false + t.source_files = 'lib/**/*.rb' +end + +require 'roodi' +require 'roodi_task' +RoodiTask.new do |t| + t.verbose = false +end + +task :default => :spec + +Bundler::GemHelper.install_tasks diff --git a/Thorfile b/Thorfile deleted file mode 100644 index 350a83c..0000000 --- a/Thorfile +++ /dev/null @@ -1,113 +0,0 @@ -module GemHelpers - - def generate_gemspec - $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), "lib"))) - require "rack/bug" - - 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 = "TODO" - s.rubyforge_project = "rack-bug" - - require "git" - repo = Git.open(".") - - s.files = normalize_files(repo.ls_files.keys - repo.lib.ignored_files) - s.test_files = normalize_files(Dir['spec/**/*.rb'] - repo.lib.ignored_files) - - s.has_rdoc = true - s.extra_rdoc_files = %w[README.md MIT-LICENSE.txt] - - s.add_dependency "rack", ">= 1.0" - s.add_development_dependency "webrat" - s.add_development_dependency "rspec" - s.add_development_dependency "sinatra" - s.add_development_dependency "git" - end - end - - def normalize_files(array) - # only keep files, no directories, and sort - array.select do |path| - File.file?(path) - end.sort - end - - # Adds extra space when outputting an array. This helps create better version - # control diffs, because otherwise it is all on the same line. - def prettyify_array(gemspec_ruby, array_name) - gemspec_ruby.gsub(/s\.#{array_name.to_s} = \[.+?\]/) do |match| - leadin, files = match[0..-2].split("[") - leadin + "[\n #{files.split(",").join(",\n ")}\n ]" - end - end - - def read_gemspec - @read_gemspec ||= eval(File.read("rack-bug.gemspec")) - end - - def sh(command) - puts command - system command - end -end - -class Default < Thor - include GemHelpers - - desc "gemspec", "Regenerate rack-bug.gemspec" - def gemspec - File.open("rack-bug.gemspec", "w") do |file| - gemspec_ruby = generate_gemspec.to_ruby - gemspec_ruby = prettyify_array(gemspec_ruby, :files) - gemspec_ruby = prettyify_array(gemspec_ruby, :test_files) - gemspec_ruby = prettyify_array(gemspec_ruby, :extra_rdoc_files) - - file.write gemspec_ruby - end - - puts "Wrote gemspec to rack-bug.gemspec" - read_gemspec.validate - end - - desc "build", "Build a rack-bug gem" - def build - sh "gem build rack-bug.gemspec" - FileUtils.mkdir_p "pkg" - FileUtils.mv read_gemspec.file_name, "pkg" - end - - desc "install", "Install the latest built gem" - def install - sh "gem install --local pkg/#{read_gemspec.file_name}" - end - - desc "release", "Release the current branch to GitHub and Gemcutter" - def release - gemspec - build - Release.new.tag - Release.new.gem - end -end - -class Release < Thor - include GemHelpers - - desc "tag", "Tag the gem on the origin server" - def tag - release_tag = "v#{read_gemspec.version}" - sh "git tag -a #{release_tag} -m 'Tagging #{release_tag}'" - sh "git push origin #{release_tag}" - end - - desc "gem", "Push the gem to Gemcutter" - def gem - sh "gem push pkg/#{read_gemspec.file_name}" - end -end diff --git a/lib/insight.rb b/lib/insight.rb deleted file mode 100644 index a9d095c..0000000 --- a/lib/insight.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Insight - class << self - def enable - Thread.current["insight.enabled"] = true - end - - def disable - Thread.current["insight.enabled"] = false - end - - def enabled? - Thread.current["insight.enabled"] == true - end - end -end - -require 'insight/app' diff --git a/lib/insight/instrumentation.rb b/lib/insight/instrumentation.rb deleted file mode 100644 index 05b30ea..0000000 --- a/lib/insight/instrumentation.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Insight - module Instrumentation; end -end -require 'insight/instrumentation/instrument' -require 'insight/instrumentation/probe' -require 'insight/instrumentation/client' -require 'insight/instrumentation/setup' -require 'insight/instrumentation/package-definition' -require 'insight/instrumentation/probe-definition' diff --git a/lib/logical-insight.rb b/lib/logical-insight.rb deleted file mode 100644 index df38de0..0000000 --- a/lib/logical-insight.rb +++ /dev/null @@ -1 +0,0 @@ -require 'insight' diff --git a/lib/rack-insight.rb b/lib/rack-insight.rb new file mode 100644 index 0000000..06a2be5 --- /dev/null +++ b/lib/rack-insight.rb @@ -0,0 +1 @@ +require 'rack/insight' diff --git a/lib/rack/insight.rb b/lib/rack/insight.rb new file mode 100644 index 0000000..85ec9b4 --- /dev/null +++ b/lib/rack/insight.rb @@ -0,0 +1,19 @@ +require 'rack/insight/app' + +module Rack + module Insight + class << self + def enable + Thread.current["rack-insight.enabled"] = true + end + + def disable + Thread.current["rack-insight.enabled"] = false + end + + def enabled? + Thread.current["rack-insight.enabled"] == true + end + end + end +end diff --git a/lib/insight/app.rb b/lib/rack/insight/app.rb similarity index 71% rename from lib/insight/app.rb rename to lib/rack/insight/app.rb index fdf1e33..6db733c 100644 --- a/lib/insight/app.rb +++ b/lib/rack/insight/app.rb @@ -1,24 +1,24 @@ -require "rack" +require 'rack' require "digest/sha1" -require "insight/filtered_backtrace" -require "insight/options" -require "insight/logger" -require "insight/panel" -require "insight/panel_app" -require "insight/params_signature" -require "insight/rack_static_bug_avoider" -require "insight/redirect_interceptor" -require "insight/render" -require "insight/toolbar" -require "insight/enable-button" -require "insight/path-filter" -require 'insight/logger' -require 'insight/request-recorder' -require 'insight/instrumentation/setup' -require 'insight/panels-content' -require 'insight/panels-header' - -module Insight +require "rack/insight/config" +require "rack/insight/logger" +require "rack/insight/filtered_backtrace" +require "rack/insight/options" +require "rack/insight/panel" +require "rack/insight/panel_app" +require "rack/insight/params_signature" +require "rack/insight/rack_static_bug_avoider" +require "rack/insight/redirect_interceptor" +require "rack/insight/render" +require "rack/insight/toolbar" +require "rack/insight/enable-button" +require "rack/insight/path-filter" +require 'rack/insight/request-recorder' +require 'rack/insight/instrumentation/setup' +require 'rack/insight/panels-content' +require 'rack/insight/panels-header' + +module Rack::Insight class App include Options INSIGHT_ROOT = "/__insight__" @@ -36,7 +36,7 @@ def initialize(app, options = {}, &block) instance_eval(&block) if block_given? @logger = Logger.new(read_option(:log_level), read_option(:log_path)) - Thread.current['insight.logger'] = @logger + Thread.current['rack-insight.logger'] = @logger build_normal_stack build_debug_stack if options[:on_initialize] @@ -52,11 +52,11 @@ def call(env) @env = env self.options = @default_options - env['insight.logger'] = @logger - Thread.current['insight.logger'] = @logger + env['rack-insight.logger'] = @logger + Thread.current['rack-insight.logger'] = @logger - Insight.enable - env["insight.panels"] = [] + Rack::Insight.enable + env["rack-insight.panels"] = [] @debug_stack.call(env) else @normal_stack.call(env) @@ -68,13 +68,13 @@ def reset(new_options=nil) @env = nil initialize_options(new_options) - Insight::Instrumentation::ClassProbe::all_probes.each do |probe| + Rack::Insight::Instrumentation::ClassProbe::all_probes.each do |probe| probe.clear_collectors end - Insight::Instrumentation::InstanceProbe::all_probes.each do |probe| + Rack::Insight::Instrumentation::InstanceProbe::all_probes.each do |probe| probe.clear_collectors end - Insight::Instrumentation::PackageDefinition.clear_collectors + Rack::Insight::Instrumentation::PackageDefinition.clear_collectors build_debug_stack end @@ -162,16 +162,16 @@ def public_path end def toolbar_requested? - @original_request.cookies["insight_enabled"] + @original_request.cookies["rack-insight_enabled"] end def ip_authorized? - return true unless options["insight.ip_masks"] + return true unless options["rack-insight.ip_masks"] logger.debug{ "Checking #{@original_request.ip} against ip_masks" } ip = IPAddr.new(@original_request.ip) - mask = options["insight.ip_masks"].find do |ip_mask| + mask = options["rack-insight.ip_masks"].find do |ip_mask| ip_mask.include?(ip) end if mask @@ -184,12 +184,12 @@ def ip_authorized? end def password_authorized? - return true unless options["insight.password"] + return true unless options["rack-insight.password"] logger.debug{"Checking password"} - expected_sha = Digest::SHA1.hexdigest ["insight", options["insight.password"]].join(":") - actual_sha = @original_request.cookies["insight_password"] + expected_sha = Digest::SHA1.hexdigest ["rack-insight", options["rack-insight.password"]].join(":") + actual_sha = @original_request.cookies["rack-insight_password"] logger.debug{"Password result: #{actual_sha == expected_sha}"} actual_sha == expected_sha diff --git a/lib/rack/insight/config.rb b/lib/rack/insight/config.rb new file mode 100644 index 0000000..b3febef --- /dev/null +++ b/lib/rack/insight/config.rb @@ -0,0 +1,30 @@ +module Rack::Insight + class Config + class << self + attr_accessor :config + end + + DEFAULTS = { + # You can augment or replace the default set of panel load paths. + # These are the paths where rack-insight will look for panels. + # A rack-insight extension gem could place panels in: + # lib/foo/bar/ + # Since gems' lib/ is automatically shifted onto Ruby load path, this will make the custom panels discoverable: + # Rack::Insight::Config.configure do |config| + # config[:panel_load_paths] << File::join('foo', 'bar') + # end + :panel_load_paths => [File::join('rack', 'insight', 'panels')] + } + + #cattr_reader :config + #cattr_writer :config + + @config ||= DEFAULTS + def self.configure &block + yield @config + unless config[:panel_load_paths].kind_of?(Array) + raise "Rack::Insight::Config.config[:panel_load_paths] is invalid: Expected kind of Array but got #{config[:panel_load_paths].class}" + end + end + end +end diff --git a/lib/insight/database.rb b/lib/rack/insight/database.rb similarity index 94% rename from lib/insight/database.rb rename to lib/rack/insight/database.rb index 5718c75..f688677 100644 --- a/lib/insight/database.rb +++ b/lib/rack/insight/database.rb @@ -1,8 +1,8 @@ -require 'insight' +#require 'rack-insight' require 'sqlite3' require 'base64' -module Insight +module Rack::Insight class Database module RequestDataClient def key_sql_template(sql) @@ -18,7 +18,7 @@ def table_setup(name, *keys) def store(env, *keys_and_value) return if env.nil? - request_id = env["insight.request-id"] + request_id = env["rack-insight.request-id"] return if request_id.nil? value = keys_and_value[-1] @@ -41,7 +41,7 @@ class << self include Logging def database_path=(value) - @database_path = value || "insight.sqlite" + @database_path = value || "rack-insight.sqlite" end def database_path @@ -69,7 +69,7 @@ def open_database if defined?(PhusionPassenger) PhusionPassenger.on_event(:starting_worker_process) do |forked| - Insight::Database::open_database if forked + Rack::Insight::Database::open_database if forked end end end @@ -78,7 +78,7 @@ class Table include Logging def db - Insight::Database.db + Rack::Insight::Database.db end def create_keys_clause diff --git a/lib/insight/enable-button.rb b/lib/rack/insight/enable-button.rb similarity index 97% rename from lib/insight/enable-button.rb rename to lib/rack/insight/enable-button.rb index 6b8fd1f..b787c85 100644 --- a/lib/insight/enable-button.rb +++ b/lib/rack/insight/enable-button.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class EnableButton include Render diff --git a/lib/insight/filtered_backtrace.rb b/lib/rack/insight/filtered_backtrace.rb similarity index 98% rename from lib/insight/filtered_backtrace.rb rename to lib/rack/insight/filtered_backtrace.rb index 9b10095..4a60188 100644 --- a/lib/insight/filtered_backtrace.rb +++ b/lib/rack/insight/filtered_backtrace.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight module FilteredBacktrace def backtrace diff --git a/lib/rack/insight/instrumentation.rb b/lib/rack/insight/instrumentation.rb new file mode 100644 index 0000000..1d4b506 --- /dev/null +++ b/lib/rack/insight/instrumentation.rb @@ -0,0 +1,9 @@ +module Rack::Insight + module Instrumentation; end +end +require 'rack/insight/instrumentation/instrument' +require 'rack/insight/instrumentation/probe' +require 'rack/insight/instrumentation/client' +require 'rack/insight/instrumentation/setup' +require 'rack/insight/instrumentation/package-definition' +require 'rack/insight/instrumentation/probe-definition' diff --git a/lib/insight/instrumentation/backstage.rb b/lib/rack/insight/instrumentation/backstage.rb similarity index 83% rename from lib/insight/instrumentation/backstage.rb rename to lib/rack/insight/instrumentation/backstage.rb index 3711740..ec59085 100644 --- a/lib/insight/instrumentation/backstage.rb +++ b/lib/rack/insight/instrumentation/backstage.rb @@ -1,4 +1,4 @@ -module Insight::Instrumentation +module Rack::Insight::Instrumentation module Backstage def backstage Thread.current["instrumented_backstage"] = true diff --git a/lib/insight/instrumentation/client.rb b/lib/rack/insight/instrumentation/client.rb similarity index 62% rename from lib/insight/instrumentation/client.rb rename to lib/rack/insight/instrumentation/client.rb index 79420f1..d6c2085 100644 --- a/lib/insight/instrumentation/client.rb +++ b/lib/rack/insight/instrumentation/client.rb @@ -1,8 +1,8 @@ -require 'insight/instrumentation/package-definition' -module Insight::Instrumentation +require 'rack/insight/instrumentation/package-definition' +module Rack::Insight::Instrumentation module Client def probe(collector, &block) - ::Insight::Instrumentation::PackageDefinition::probe(collector, &block) + ::Rack::Insight::Instrumentation::PackageDefinition::probe(collector, &block) end def request_start(env, start) diff --git a/lib/insight/instrumentation/instrument.rb b/lib/rack/insight/instrumentation/instrument.rb similarity index 97% rename from lib/insight/instrumentation/instrument.rb rename to lib/rack/insight/instrumentation/instrument.rb index 45722c1..1bee7a3 100644 --- a/lib/insight/instrumentation/instrument.rb +++ b/lib/rack/insight/instrumentation/instrument.rb @@ -1,7 +1,7 @@ -require 'insight/instrumentation/backstage' -require 'insight/logger' +require 'rack/insight/instrumentation/backstage' +require 'rack/insight/logger' -module Insight +module Rack::Insight module Instrumentation class Instrument MethodCall = Struct.new(:call_number, :backtrace, :file, :line, :object, :context, :kind, :method, :thread) diff --git a/lib/insight/instrumentation/package-definition.rb b/lib/rack/insight/instrumentation/package-definition.rb similarity index 96% rename from lib/insight/instrumentation/package-definition.rb rename to lib/rack/insight/instrumentation/package-definition.rb index 3163d31..a70e1b4 100644 --- a/lib/insight/instrumentation/package-definition.rb +++ b/lib/rack/insight/instrumentation/package-definition.rb @@ -1,4 +1,4 @@ -module Insight::Instrumentation +module Rack::Insight::Instrumentation class PackageDefinition class << self def start diff --git a/lib/insight/instrumentation/probe-definition.rb b/lib/rack/insight/instrumentation/probe-definition.rb similarity index 92% rename from lib/insight/instrumentation/probe-definition.rb rename to lib/rack/insight/instrumentation/probe-definition.rb index f8e6d53..6e83e4d 100644 --- a/lib/insight/instrumentation/probe-definition.rb +++ b/lib/rack/insight/instrumentation/probe-definition.rb @@ -1,4 +1,4 @@ -module Insight::Instrumentation +module Rack::Insight::Instrumentation class ProbeDefinition def initialize(package, target_name) @package = package diff --git a/lib/insight/instrumentation/probe.rb b/lib/rack/insight/instrumentation/probe.rb similarity index 98% rename from lib/insight/instrumentation/probe.rb rename to lib/rack/insight/instrumentation/probe.rb index 792fd89..f76e7c2 100644 --- a/lib/insight/instrumentation/probe.rb +++ b/lib/rack/insight/instrumentation/probe.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight module Instrumentation class Probe module Interpose @@ -16,7 +16,7 @@ def probe_run(object, context = "::", kind=:instance, args=[], called_at=caller[ ##{method_name}" unless method_name.to_sym == :add return yield end - instrument = Thread.current['insight.instrument'] + instrument = Thread.current['rack-insight.instrument'] result = nil if instrument.nil? backstage do diff --git a/lib/insight/instrumentation/setup.rb b/lib/rack/insight/instrumentation/setup.rb similarity index 57% rename from lib/insight/instrumentation/setup.rb rename to lib/rack/insight/instrumentation/setup.rb index 082bec3..882d924 100644 --- a/lib/insight/instrumentation/setup.rb +++ b/lib/rack/insight/instrumentation/setup.rb @@ -1,4 +1,4 @@ -module Insight::Instrumentation +module Rack::Insight::Instrumentation class Setup def initialize(app) @app = app @@ -10,16 +10,16 @@ def setup(env) PackageDefinition.start instrument.start(env) - env["insight.instrument"] = instrument - Thread::current["insight.instrument"] = instrument + env["rack-insight.instrument"] = instrument + Thread::current["rack-insight.instrument"] = instrument end def teardown(env, status, headers, body) - instrument, env["insight.instrument"] = env["insight.instrument"], nil + instrument, env["rack-insight.instrument"] = env["rack-insight.instrument"], nil instrument.finish(env, status, headers, body) - Thread::current["insight.instrument"] = nil + Thread::current["rack-insight.instrument"] = nil - env["insight.duration"] = instrument.duration + env["rack-insight.duration"] = instrument.duration end def call(env) diff --git a/lib/insight/logger.rb b/lib/rack/insight/logger.rb similarity index 78% rename from lib/insight/logger.rb rename to lib/rack/insight/logger.rb index f0d69e6..faa146c 100644 --- a/lib/insight/logger.rb +++ b/lib/rack/insight/logger.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class Logger def initialize(level, path) @level = level @@ -20,7 +20,7 @@ def log(severity, message) return unless severity >= @level if defined? Rails and Rails.respond_to?(:logger) and not Rails.logger.nil? - Rails.logger.add(severity, "[Insight]: " + message) + Rails.logger.add(severity, "[Rack::Insight]: " + message) end logfile.puts(message) @@ -43,9 +43,9 @@ def unknown; log(UNKNOWN, yield) end module Logging def logger(env = nil) if env.nil? - Thread.current['insight.logger'] ||= Logger.new(Logger::DEBUG, "") + Thread.current['rack-insight.logger'] ||= Rack::Insight::Logger.new(Logger::DEBUG, "") else - env["insight.logger"] + env["rack-insight.logger"] ||= Rack::Insight::Logger.new(Logger::DEBUG, "") end end module_function :logger diff --git a/lib/insight/options.rb b/lib/rack/insight/options.rb similarity index 69% rename from lib/insight/options.rb rename to lib/rack/insight/options.rb index 8c9f824..97a106a 100644 --- a/lib/insight/options.rb +++ b/lib/rack/insight/options.rb @@ -1,6 +1,6 @@ require 'ipaddr' -module Insight +module Rack::Insight module Options class << self private @@ -66,37 +66,37 @@ def write_option(key, value) def option_name(key) case key - when Symbol ; "insight.#{key}" + when Symbol ; "rack-insight.#{key}" when String ; key else raise ArgumentError end end def process_options - if(file_list = read_option('insight.panel_files')) - class_list = read_option('insight.panel_classes') || [] + if(file_list = read_option('rack-insight.panel_files')) + class_list = read_option('rack-insight.panel_classes') || [] file_list.each do |file| - class_list |= Insight::Panel.from_file(file) + class_list |= Rack::Insight::Panel.from_file(file) end - write_option('insight.panel_classes', class_list) + write_option('rack-insight.panel_classes', class_list) end - Insight::Database.database_path = read_option('insight.database_path') + Rack::Insight::Database.database_path = read_option('rack-insight.database_path') end def initialize_options(options=nil) @default_options = { - 'insight.ip_masks' => [IPAddr.new("127.0.0.1")], - 'insight.password' => nil, - 'insight.verbose' => nil, - 'insight.secret_key' => nil, - 'insight.intercept_redirects' => false, - 'insight.panels' => [], - 'insight.path_filters' => %w{/assets/}, - 'insight.log_level' => Logger::INFO, - 'insight.log_path' => "log/insight.log", - 'insight.database_path' => "insight.sqlite", - 'insight.panel_files' => %w{ + 'rack-insight.ip_masks' => [IPAddr.new("127.0.0.1")], + 'rack-insight.password' => nil, + 'rack-insight.verbose' => nil, + 'rack-insight.secret_key' => nil, + 'rack-insight.intercept_redirects' => false, + 'rack-insight.panels' => [], + 'rack-insight.path_filters' => %w{/assets/}, + 'rack-insight.log_level' => Logger::INFO, + 'rack-insight.log_path' => "log/rack-insight.log", + 'rack-insight.database_path' => "rack-insight.sqlite", + 'rack-insight.panel_files' => %w{ rails_info_panel timer_panel request_variables_panel diff --git a/lib/insight/panel.rb b/lib/rack/insight/panel.rb similarity index 52% rename from lib/insight/panel.rb rename to lib/rack/insight/panel.rb index 41a4ab7..930b10e 100644 --- a/lib/insight/panel.rb +++ b/lib/rack/insight/panel.rb @@ -1,17 +1,18 @@ require "erb" -require 'insight/database' -require 'insight/instrumentation' -require 'insight/render' +require "rack/insight/logger" +require 'rack/insight/database' +require 'rack/insight/instrumentation' +require 'rack/insight/render' -module Insight +module Rack::Insight # Panels are also Rack middleware class Panel - include Render include ERB::Util - include Database::RequestDataClient - include Logging - include Instrumentation::Client + include Rack::Insight::Logging + include Rack::Insight::Render + include Rack::Insight::Database::RequestDataClient + include Rack::Insight::Instrumentation::Client attr_reader :request @@ -27,22 +28,35 @@ def panel_exclusion end def from_file(rel_path) - old_rel, Thread::current['panel_file'] = Thread::current['panel_file'], rel_path - require File::join('insight', 'panels', rel_path) + old_rel, Thread::current['rack-panel_file'] = Thread::current['rack-panel_file'], rel_path + Rack::Insight::Config.config[:panel_load_paths].each do |load_path| + begin + require File::join(load_path, rel_path) + rescue LoadError => e + end + end return (file_index[rel_path] - panel_exclusion) ensure - Thread::current['panel_file'] = old_rel + Thread::current['rack-panel_file'] = old_rel end def current_panel_file - return Thread::current['panel_file'] || + return Thread::current['rack-panel_file'] || begin file_name = nil + matched_line = nil caller.each do |line| - md = %r{^[^:]*insight/panels/([^:]*)\.rb:}.match line - unless md.nil? - file_name = md[1] + # First make sure we are not matching rack-insight's own panel class, which will be in the caller stack, + # and which may match some custom load path added (try adding 'rack' as a custom load path!) + next if line =~ /rack-insight.*\/lib\/rack\/insight\/panel.rb:/ + Rack::Insight::Config.config[:panel_load_paths].each do |load_path| + regex = %r{^[^:]*#{load_path}/([^:]*)\.rb:} + md = regex.match line + file_name = md[1] unless md.nil? + matched_line = line unless file_name.nil? + break unless file_name.nil? end + break unless file_name.nil? end file_name end @@ -52,7 +66,7 @@ def inherited(sub) if filename = current_panel_file Panel::file_index[current_panel_file] << sub else - warn "Insight::Panel inherited by #{sub.name} outside of an insight/panels/* file. Discarded" + warn "Rack::Insight::Panel inherited by #{sub.name} outside rack-insight's :panel_load_paths. Discarded. Configured panel load paths are: #{Rack::Insight::Config.config[:panel_load_paths].inspect}" end end @@ -79,7 +93,7 @@ def call(env) @request = Rack::Request.new(env) logger.debug{ "After call: #{self.name}" } after(env, status, headers, body) - env["insight.panels"] << self + env["rack-insight.panels"] << self return [status, headers, body] end diff --git a/lib/insight/panel_app.rb b/lib/rack/insight/panel_app.rb similarity index 88% rename from lib/insight/panel_app.rb rename to lib/rack/insight/panel_app.rb index 19d988c..582c9ca 100644 --- a/lib/insight/panel_app.rb +++ b/lib/rack/insight/panel_app.rb @@ -1,7 +1,7 @@ -module Insight +module Rack::Insight class PanelApp - include Insight::Render + include Rack::Insight::Render attr_reader :request diff --git a/lib/insight/panels-content.rb b/lib/rack/insight/panels-content.rb similarity index 97% rename from lib/insight/panels-content.rb rename to lib/rack/insight/panels-content.rb index 07f55ac..e07eba0 100644 --- a/lib/insight/panels-content.rb +++ b/lib/rack/insight/panels-content.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class PanelsContent < PanelApp def initialize(insight_app) @insight_app = insight_app diff --git a/lib/insight/panels-header.rb b/lib/rack/insight/panels-header.rb similarity index 96% rename from lib/insight/panels-header.rb rename to lib/rack/insight/panels-header.rb index 371b9a0..d8867e0 100644 --- a/lib/insight/panels-header.rb +++ b/lib/rack/insight/panels-header.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class PanelsHeader < PanelApp def initialize(insight_app) @insight_app = insight_app diff --git a/lib/insight/panels/active_record_panel.rb b/lib/rack/insight/panels/active_record_panel.rb similarity index 91% rename from lib/insight/panels/active_record_panel.rb rename to lib/rack/insight/panels/active_record_panel.rb index 547f3fd..4cf99fb 100644 --- a/lib/insight/panels/active_record_panel.rb +++ b/lib/rack/insight/panels/active_record_panel.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class ActiveRecordPanel < Panel def initialize(app) super @@ -37,7 +37,7 @@ def heading_for_request(number) end def content_for_request(number) - records = retreive(number).first.to_a.sort_by { |key, value| value }.reverse + records = retrieve(number).first.to_a.sort_by { |key, value| value }.reverse render_template "panels/active_record", :records => records end diff --git a/lib/insight/panels/active_resource_panel.rb b/lib/rack/insight/panels/active_resource_panel.rb similarity index 85% rename from lib/insight/panels/active_resource_panel.rb rename to lib/rack/insight/panels/active_resource_panel.rb index f07a186..4f550f4 100644 --- a/lib/insight/panels/active_resource_panel.rb +++ b/lib/rack/insight/panels/active_resource_panel.rb @@ -1,10 +1,10 @@ require "digest" -module Insight +module Rack::Insight class ActiveResourcePanel < Panel - require 'insight/panels/active_resource_panel/query' - #require "insight/panels/sql_panel/panel_app" - #require "insight/panels/sql_panel/query" + require 'rack/insight/panels/active_resource_panel/query' + #require "rack/insight/panels/sql_panel/panel_app" + #require "rack/insight/panels/sql_panel/query" def initialize(app) super diff --git a/lib/insight/panels/active_resource_panel/query.rb b/lib/rack/insight/panels/active_resource_panel/query.rb similarity index 89% rename from lib/insight/panels/active_resource_panel/query.rb rename to lib/rack/insight/panels/active_resource_panel/query.rb index 11e4e11..509e70f 100644 --- a/lib/insight/panels/active_resource_panel/query.rb +++ b/lib/rack/insight/panels/active_resource_panel/query.rb @@ -1,7 +1,7 @@ -module Insight +module Rack::Insight class ActiveResourcePanel class RequestResult - include Insight::FilteredBacktrace + include Rack::Insight::FilteredBacktrace attr_reader :path, :args, :result, :time alias results result diff --git a/lib/insight/panels/cache_panel.rb b/lib/rack/insight/panels/cache_panel.rb similarity index 85% rename from lib/insight/panels/cache_panel.rb rename to lib/rack/insight/panels/cache_panel.rb index 9cb6c0b..765e6f9 100644 --- a/lib/insight/panels/cache_panel.rb +++ b/lib/rack/insight/panels/cache_panel.rb @@ -1,9 +1,9 @@ -module Insight +module Rack::Insight class CachePanel < Panel - require "insight/panels/cache_panel/panel_app" - require "insight/panels/cache_panel/stats" + require "rack/insight/panels/cache_panel/panel_app" + require "rack/insight/panels/cache_panel/stats" def initialize(app) super @@ -31,7 +31,6 @@ def request_start(env, start) end def request_finish(env, st, hd, bd, timing) - logger(env).debug{ "Stats: #@stats" } store(env, @stats) end @@ -53,14 +52,14 @@ def name end def heading_for_request(number) - stats = retreive(number).first + stats = retrieve(number).first "Cache: %.2fms (#{stats.queries.size} calls)" % stats.time end def content_for_request(number) logger.debug{{ :req_num => number }} - stats = retreive(number).first + stats = retrieve(number).first render_template "panels/cache", :stats => stats end diff --git a/lib/insight/panels/cache_panel/panel_app.rb b/lib/rack/insight/panels/cache_panel/panel_app.rb similarity index 93% rename from lib/insight/panels/cache_panel/panel_app.rb rename to lib/rack/insight/panels/cache_panel/panel_app.rb index 844b737..4a1032d 100644 --- a/lib/insight/panels/cache_panel/panel_app.rb +++ b/lib/rack/insight/panels/cache_panel/panel_app.rb @@ -1,7 +1,7 @@ -module Insight +module Rack::Insight class CachePanel - class PanelApp < ::Insight::PanelApp + class PanelApp < ::Rack::Insight::PanelApp def dispatch case request.path_info diff --git a/lib/insight/panels/cache_panel/stats.rb b/lib/rack/insight/panels/cache_panel/stats.rb similarity index 89% rename from lib/insight/panels/cache_panel/stats.rb rename to lib/rack/insight/panels/cache_panel/stats.rb index a596e8f..5667bf0 100644 --- a/lib/insight/panels/cache_panel/stats.rb +++ b/lib/rack/insight/panels/cache_panel/stats.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class CachePanel class Stats @@ -25,9 +25,7 @@ def display_keys end end - attr_reader :calls - attr_reader :keys - attr_reader :queries + attr_reader :calls, :keys, :queries, :time def initialize @queries = [] @@ -52,12 +50,6 @@ 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 diff --git a/lib/insight/panels/log_panel.rb b/lib/rack/insight/panels/log_panel.rb similarity index 98% rename from lib/insight/panels/log_panel.rb rename to lib/rack/insight/panels/log_panel.rb index d300a67..e1e42ed 100644 --- a/lib/insight/panels/log_panel.rb +++ b/lib/rack/insight/panels/log_panel.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class LogPanel < Panel class LogEntry attr_reader :level, :time, :message diff --git a/lib/insight/panels/memory_panel.rb b/lib/rack/insight/panels/memory_panel.rb similarity index 97% rename from lib/insight/panels/memory_panel.rb rename to lib/rack/insight/panels/memory_panel.rb index 376180b..a6513fe 100644 --- a/lib/insight/panels/memory_panel.rb +++ b/lib/rack/insight/panels/memory_panel.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class MemoryPanel < Panel def initialize(app) diff --git a/lib/insight/panels/mongo_panel.rb b/lib/rack/insight/panels/mongo_panel.rb similarity index 66% rename from lib/insight/panels/mongo_panel.rb rename to lib/rack/insight/panels/mongo_panel.rb index 80239c8..8756dbf 100644 --- a/lib/insight/panels/mongo_panel.rb +++ b/lib/rack/insight/panels/mongo_panel.rb @@ -1,11 +1,11 @@ -module Insight +module Rack::Insight class MongoPanel < Panel - require "insight/panels/mongo_panel/mongo_extension" - require "insight/panels/mongo_panel/stats" + require "rack/insight/panels/mongo_panel/mongo_extension" + require "rack/insight/panels/mongo_panel/stats" def self.record(command, &block) - return block.call unless Insight.enabled? + return block.call unless Rack::Insight.enabled? start_time = Time.now result = block.call @@ -15,11 +15,11 @@ def self.record(command, &block) end def self.reset - Thread.current["insight.mongo"] = Stats.new + Thread.current["rack-insight.mongo"] = Stats.new end def self.stats - Thread.current["insight.mongo"] ||= Stats.new + Thread.current["rack-insight.mongo"] ||= Stats.new end def name diff --git a/lib/insight/panels/mongo_panel/mongo_extension.rb b/lib/rack/insight/panels/mongo_panel/mongo_extension.rb similarity index 84% rename from lib/insight/panels/mongo_panel/mongo_extension.rb rename to lib/rack/insight/panels/mongo_panel/mongo_extension.rb index 1b83a4d..00b5b73 100644 --- a/lib/insight/panels/mongo_panel/mongo_extension.rb +++ b/lib/rack/insight/panels/mongo_panel/mongo_extension.rb @@ -3,14 +3,14 @@ Mongo::Connection.class_eval do def send_message_with_insight(operation, message, log_message=nil) - Insight::MongoPanel.record(log_message || message) do + Rack::Insight::MongoPanel.record(log_message || message) do send_message_without_insight(operation, message, log_message) end end alias_method_chain :send_message, :insight def send_message_with_safe_check_with_insight(operation, message, db_name, log_message=nil, last_error_params=false) - Insight::MongoPanel.record(log_message || message) do + Rack::Insight::MongoPanel.record(log_message || message) do send_message_with_safe_check_without_insight(operation, message, db_name, log_message, last_error_params) end end diff --git a/lib/insight/panels/mongo_panel/stats.rb b/lib/rack/insight/panels/mongo_panel/stats.rb similarity index 97% rename from lib/insight/panels/mongo_panel/stats.rb rename to lib/rack/insight/panels/mongo_panel/stats.rb index 466efe0..7912a5e 100644 --- a/lib/insight/panels/mongo_panel/stats.rb +++ b/lib/rack/insight/panels/mongo_panel/stats.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class MongoPanel class Stats diff --git a/lib/insight/panels/rails_info_panel.rb b/lib/rack/insight/panels/rails_info_panel.rb similarity index 94% rename from lib/insight/panels/rails_info_panel.rb rename to lib/rack/insight/panels/rails_info_panel.rb index 6f46f47..ea166ff 100644 --- a/lib/insight/panels/rails_info_panel.rb +++ b/lib/rack/insight/panels/rails_info_panel.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class RailsInfoPanel < Panel def name diff --git a/lib/insight/panels/redis_panel.rb b/lib/rack/insight/panels/redis_panel.rb similarity index 68% rename from lib/insight/panels/redis_panel.rb rename to lib/rack/insight/panels/redis_panel.rb index 174de8f..2847833 100644 --- a/lib/insight/panels/redis_panel.rb +++ b/lib/rack/insight/panels/redis_panel.rb @@ -1,12 +1,12 @@ -module Insight +module Rack::Insight class RedisPanel < Panel - require "insight/panels/redis_panel/redis_extension" + require "rack/insight/panels/redis_panel/redis_extension" - require "insight/panels/redis_panel/stats" + require "rack/insight/panels/redis_panel/stats" def self.record(redis_command_args, backtrace, &block) - return block.call unless Insight.enabled? + return block.call unless Rack::Insight.enabled? start_time = Time.now result = block.call @@ -16,11 +16,11 @@ def self.record(redis_command_args, backtrace, &block) end def self.reset - Thread.current["insight.redis"] = Stats.new + Thread.current["rack-insight.redis"] = Stats.new end def self.stats - Thread.current["insight.redis"] ||= Stats.new + Thread.current["rack-insight.redis"] ||= Stats.new end def name diff --git a/lib/insight/panels/redis_panel/redis_extension.rb b/lib/rack/insight/panels/redis_panel/redis_extension.rb similarity index 88% rename from lib/insight/panels/redis_panel/redis_extension.rb rename to lib/rack/insight/panels/redis_panel/redis_extension.rb index afe6cb6..5247abb 100644 --- a/lib/insight/panels/redis_panel/redis_extension.rb +++ b/lib/rack/insight/panels/redis_panel/redis_extension.rb @@ -2,7 +2,7 @@ Redis.class_eval do if Redis.methods.include?('call_command') # older versions of redis-rb def call_command_with_insight(*argv) - Insight::RedisPanel.record(argv, Kernel.caller) do + Rack::Insight::RedisPanel.record(argv, Kernel.caller) do call_command_without_insight(*argv) end end diff --git a/lib/insight/panels/redis_panel/stats.rb b/lib/rack/insight/panels/redis_panel/stats.rb similarity index 92% rename from lib/insight/panels/redis_panel/stats.rb rename to lib/rack/insight/panels/redis_panel/stats.rb index af70576..ea175ea 100644 --- a/lib/insight/panels/redis_panel/stats.rb +++ b/lib/rack/insight/panels/redis_panel/stats.rb @@ -1,9 +1,9 @@ -module Insight +module Rack::Insight class RedisPanel class Stats class Query - include Insight::FilteredBacktrace + include Rack::Insight::FilteredBacktrace attr_reader :time attr_reader :command diff --git a/lib/insight/panels/request_variables_panel.rb b/lib/rack/insight/panels/request_variables_panel.rb similarity index 94% rename from lib/insight/panels/request_variables_panel.rb rename to lib/rack/insight/panels/request_variables_panel.rb index 8bb9fcd..386aff2 100644 --- a/lib/insight/panels/request_variables_panel.rb +++ b/lib/rack/insight/panels/request_variables_panel.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class RequestVariablesPanel < Panel def initialize(app) super @@ -57,7 +57,7 @@ def split_and_filter_env(env) env.each do |k,v| if k.index("rack.") == 0 rack[k] = v - elsif k.index("insight") == 0 or k.index("insight") == 0 + elsif k.index("rack-insight") == 0 or k.index("rack-insight") == 0 #don't output the insight variables - especially secret_key else server[k] = v diff --git a/lib/insight/panels/speedtracer_panel.rb b/lib/rack/insight/panels/speedtracer_panel.rb similarity index 82% rename from lib/insight/panels/speedtracer_panel.rb rename to lib/rack/insight/panels/speedtracer_panel.rb index 730b2a8..46431e7 100644 --- a/lib/insight/panels/speedtracer_panel.rb +++ b/lib/rack/insight/panels/speedtracer_panel.rb @@ -3,17 +3,17 @@ rescue LoadError #Means no Chrome Speedtracer... end -require 'uuid' -require 'insight/panels/speedtracer_panel/trace-app' -require 'insight/panels/speedtracer_panel/tracer' +require 'uuidtools' +require 'rack/insight/panels/speedtracer_panel/trace-app' +require 'rack/insight/panels/speedtracer_panel/tracer' -module Insight +module Rack::Insight module SpeedTracer - class Panel < ::Insight::Panel + class Panel < ::Rack::Insight::Panel def initialize(app) @app = app - @uuid = UUID.new + @uuid = UUIDTools::UUID.random_create.to_s table_setup("speedtracer", "uuid") key_sql_template("'%s'") @@ -54,12 +54,12 @@ def initialize(app) def call(env) - env['insight.speedtracer-id'] = @uuid.generate + env['rack-insight.speedtracer-id'] = @uuid status, headers, body = @app.call(env) - store(env, env['insight.speedtracer-id'], env['insight.speedtracer-record']) - headers['X-TraceUrl'] = '__insight__/speedtracer?id=' + env['insight.speedtracer-id'] + store(env, env['rack-insight.speedtracer-id'], env['rack-insight.speedtracer-record']) + headers['X-TraceUrl'] = '__insight__/speedtracer?id=' + env['rack-insight.speedtracer-id'] return [status, headers, body] end diff --git a/lib/insight/panels/speedtracer_panel/profiling.rb b/lib/rack/insight/panels/speedtracer_panel/profiling.rb similarity index 97% rename from lib/insight/panels/speedtracer_panel/profiling.rb rename to lib/rack/insight/panels/speedtracer_panel/profiling.rb index 2b8fe31..6bb1d90 100644 --- a/lib/insight/panels/speedtracer_panel/profiling.rb +++ b/lib/rack/insight/panels/speedtracer_panel/profiling.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight #Variant of the Speed Tracer Panel that performs a nearly complete profile of diff --git a/lib/insight/panels/speedtracer_panel/trace-app.rb b/lib/rack/insight/panels/speedtracer_panel/trace-app.rb similarity index 98% rename from lib/insight/panels/speedtracer_panel/trace-app.rb rename to lib/rack/insight/panels/speedtracer_panel/trace-app.rb index 3534602..832bd72 100644 --- a/lib/insight/panels/speedtracer_panel/trace-app.rb +++ b/lib/rack/insight/panels/speedtracer_panel/trace-app.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight module SpeedTracer class TraceApp include Database::RequestDataClient diff --git a/lib/insight/panels/speedtracer_panel/tracer.rb b/lib/rack/insight/panels/speedtracer_panel/tracer.rb similarity index 96% rename from lib/insight/panels/speedtracer_panel/tracer.rb rename to lib/rack/insight/panels/speedtracer_panel/tracer.rb index 35f7d8c..e710a2f 100644 --- a/lib/insight/panels/speedtracer_panel/tracer.rb +++ b/lib/rack/insight/panels/speedtracer_panel/tracer.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight module SpeedTracer class Tracer def initialize(table) @@ -8,12 +8,12 @@ def initialize(table) end def request_start(env, start) - id, method, uri = env.values_at("insight.speedtracer-id", "REQUEST_METHOD", "PATH_INFO") + id, method, uri = env.values_at("rack-insight.speedtracer-id", "REQUEST_METHOD", "PATH_INFO") @pstack.push RequestRecord.new(id, method, uri) end def request_finish(env, status, headers, body, timing) - env["insight.speedtracer-record"] = @pstack.pop + env["rack-insight.speedtracer-record"] = @pstack.pop end def before_detect(method_call, arguments) diff --git a/lib/insight/panels/sphinx_panel.rb b/lib/rack/insight/panels/sphinx_panel.rb similarity index 67% rename from lib/insight/panels/sphinx_panel.rb rename to lib/rack/insight/panels/sphinx_panel.rb index 684a22c..28c3d07 100644 --- a/lib/insight/panels/sphinx_panel.rb +++ b/lib/rack/insight/panels/sphinx_panel.rb @@ -1,11 +1,11 @@ -module Insight +module Rack::Insight class SphinxPanel < Panel - require "insight/panels/sphinx_panel/sphinx_extension" - require "insight/panels/sphinx_panel/stats" + require "rack/insight/panels/sphinx_panel/sphinx_extension" + require "rack/insight/panels/sphinx_panel/stats" def self.record(*sphinx_command_args, &block) - return block.call unless Insight.enabled? + return block.call unless Rack::Insight.enabled? start_time = Time.now result = block.call @@ -15,11 +15,11 @@ def self.record(*sphinx_command_args, &block) end def self.reset - Thread.current["insight.sphinx"] = Stats.new + Thread.current["rack-insight.sphinx"] = Stats.new end def self.stats - Thread.current["insight.sphinx"] ||= Stats.new + Thread.current["rack-insight.sphinx"] ||= Stats.new end def name diff --git a/lib/insight/panels/sphinx_panel/stats.rb b/lib/rack/insight/panels/sphinx_panel/stats.rb similarity index 99% rename from lib/insight/panels/sphinx_panel/stats.rb rename to lib/rack/insight/panels/sphinx_panel/stats.rb index 06cf27c..1d64c4c 100644 --- a/lib/insight/panels/sphinx_panel/stats.rb +++ b/lib/rack/insight/panels/sphinx_panel/stats.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class SphinxPanel class Stats diff --git a/lib/insight/panels/sql_panel.rb b/lib/rack/insight/panels/sql_panel.rb similarity index 89% rename from lib/insight/panels/sql_panel.rb rename to lib/rack/insight/panels/sql_panel.rb index 144621f..204873d 100644 --- a/lib/insight/panels/sql_panel.rb +++ b/lib/rack/insight/panels/sql_panel.rb @@ -1,11 +1,11 @@ require "digest" -module Insight +module Rack::Insight class SQLPanel < Panel - require "insight/panels/sql_panel/panel_app" - require "insight/panels/sql_panel/query" + require "rack/insight/panels/sql_panel/panel_app" + require "rack/insight/panels/sql_panel/query" def initialize(app) super diff --git a/lib/insight/panels/sql_panel/panel_app.rb b/lib/rack/insight/panels/sql_panel/panel_app.rb similarity index 87% rename from lib/insight/panels/sql_panel/panel_app.rb rename to lib/rack/insight/panels/sql_panel/panel_app.rb index 119c232..a684f48 100644 --- a/lib/insight/panels/sql_panel/panel_app.rb +++ b/lib/rack/insight/panels/sql_panel/panel_app.rb @@ -1,9 +1,9 @@ -require 'insight/panels/sql_panel/query' +require 'rack/insight/panels/sql_panel/query' -module Insight +module Rack::Insight class SQLPanel - class PanelApp < ::Insight::PanelApp + class PanelApp < ::Rack::Insight::PanelApp def dispatch case request.path_info diff --git a/lib/insight/panels/sql_panel/query.rb b/lib/rack/insight/panels/sql_panel/query.rb similarity index 96% rename from lib/insight/panels/sql_panel/query.rb rename to lib/rack/insight/panels/sql_panel/query.rb index 85f3433..9f20850 100644 --- a/lib/insight/panels/sql_panel/query.rb +++ b/lib/rack/insight/panels/sql_panel/query.rb @@ -1,8 +1,8 @@ -module Insight +module Rack::Insight class SQLPanel class QueryResult - include Insight::FilteredBacktrace + include Rack::Insight::FilteredBacktrace attr_reader :sql attr_reader :time diff --git a/lib/insight/panels/templates_panel.rb b/lib/rack/insight/panels/templates_panel.rb similarity index 93% rename from lib/insight/panels/templates_panel.rb rename to lib/rack/insight/panels/templates_panel.rb index c2c05c2..ebcae21 100644 --- a/lib/insight/panels/templates_panel.rb +++ b/lib/rack/insight/panels/templates_panel.rb @@ -1,7 +1,7 @@ -module Insight +module Rack::Insight class TemplatesPanel < Panel - require "insight/panels/templates_panel/rendering" + require "rack/insight/panels/templates_panel/rendering" def initialize(app) super diff --git a/lib/insight/panels/templates_panel/rendering.rb b/lib/rack/insight/panels/templates_panel/rendering.rb similarity index 98% rename from lib/insight/panels/templates_panel/rendering.rb rename to lib/rack/insight/panels/templates_panel/rendering.rb index b518268..ccb4d23 100644 --- a/lib/insight/panels/templates_panel/rendering.rb +++ b/lib/rack/insight/panels/templates_panel/rendering.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class TemplatesPanel class Rendering diff --git a/lib/insight/panels/timer_panel.rb b/lib/rack/insight/panels/timer_panel.rb similarity index 92% rename from lib/insight/panels/timer_panel.rb rename to lib/rack/insight/panels/timer_panel.rb index f74c9b5..b29df5a 100644 --- a/lib/insight/panels/timer_panel.rb +++ b/lib/rack/insight/panels/timer_panel.rb @@ -1,6 +1,6 @@ require 'benchmark' -module Insight +module Rack::Insight class TimerPanel < Panel def initialize(app) super @@ -28,7 +28,7 @@ def call(env) end def heading_for_request(number) - measurements = retreive(number).first + measurements = retrieve(number).first measurements.last.last end diff --git a/lib/insight/params_signature.rb b/lib/rack/insight/params_signature.rb similarity index 94% rename from lib/insight/params_signature.rb rename to lib/rack/insight/params_signature.rb index 11a8026..c9c0b05 100644 --- a/lib/insight/params_signature.rb +++ b/lib/rack/insight/params_signature.rb @@ -1,6 +1,6 @@ require "digest" -module Insight +module Rack::Insight class ParamsSignature extend ERB::Util @@ -25,7 +25,7 @@ def initialize(request) end def secret_key - @request.env['insight.secret_key'] + @request.env['rack-insight.secret_key'] end def secret_key_blank? diff --git a/lib/insight/path-filter.rb b/lib/rack/insight/path-filter.rb similarity index 76% rename from lib/insight/path-filter.rb rename to lib/rack/insight/path-filter.rb index 4f4eb15..1e52311 100644 --- a/lib/insight/path-filter.rb +++ b/lib/rack/insight/path-filter.rb @@ -1,6 +1,6 @@ -require 'insight/logger' +require 'rack/insight/logger' -module Insight +module Rack::Insight class PathFilter include Logging def initialize(app) @@ -8,7 +8,7 @@ def initialize(app) end def call(env) - filters = env['insight.path_filters'].map do |string| + filters = env['rack-insight.path_filters'].map do |string| %r{^#{string}} end diff --git a/lib/insight/public/__insight__/bookmarklet.html b/lib/rack/insight/public/__insight__/bookmarklet.html similarity index 91% rename from lib/insight/public/__insight__/bookmarklet.html rename to lib/rack/insight/public/__insight__/bookmarklet.html index 9ed8b4a..c8d2a98 100644 --- a/lib/insight/public/__insight__/bookmarklet.html +++ b/lib/rack/insight/public/__insight__/bookmarklet.html @@ -4,7 +4,7 @@


- Toggle Insight + Toggle Rack::Insight diff --git a/lib/insight/public/__insight__/bookmarklet.js b/lib/rack/insight/public/__insight__/bookmarklet.js similarity index 92% rename from lib/insight/public/__insight__/bookmarklet.js rename to lib/rack/insight/public/__insight__/bookmarklet.js index 030fa72..1e9bf21 100644 --- a/lib/insight/public/__insight__/bookmarklet.js +++ b/lib/rack/insight/public/__insight__/bookmarklet.js @@ -200,22 +200,22 @@ document.eraseCookie = function(name) { } document.insightEnable = function() { - var password = prompt("Insight password:", ""); + var password = prompt("Rack::Insight password:", ""); if (password != null) { - document.createCookie('insight_password', document.SHA1('insight:'+password)); - document.createCookie('insight_enabled', "1"); + document.createCookie('rack-insight_password', document.SHA1('rack-insight:'+password)); + document.createCookie('rack-insight_enabled', "1"); window.location.reload(); } } document.insightDisable = function() { - document.eraseCookie('insight_password'); - document.eraseCookie('insight_enabled'); + document.eraseCookie('rack-insight_password'); + document.eraseCookie('rack-insight_enabled'); window.location.reload(); } document.insightBookmarklet = function() { - if (document.readCookie('insight_password')) { + if (document.readCookie('rack-insight_password')) { document.insightDisable() } else { document.insightEnable() diff --git a/lib/insight/public/__insight__/insight.css b/lib/rack/insight/public/__insight__/insight.css similarity index 54% rename from lib/insight/public/__insight__/insight.css rename to lib/rack/insight/public/__insight__/insight.css index ebd1084..1e37ba9 100644 --- a/lib/insight/public/__insight__/insight.css +++ b/lib/rack/insight/public/__insight__/insight.css @@ -1,4 +1,4 @@ -#insight { +#rack-insight { color: #000; float: none; margin: 0; @@ -6,14 +6,14 @@ position: static; } -#insight a { +#rack-insight a { color: #f7c757; } -#insight a:hover { +#rack-insight a:hover { color: #aaa; } -#insight_toolbar { +#rack-insight_toolbar { background: #326342; height: 30px; z-index: 1000000000; @@ -22,35 +22,35 @@ right:0; cursor: pointer; } -.insight_bottom #insight_toolbar { +.insight_bottom #rack-insight_toolbar { bottom:0; border-top: 2px solid #234f32; } -.insight_top #insight_toolbar { +.insight_top #rack-insight_toolbar { top:0; border-bottom: 2px solid #234f32; } -.insight_error #insight_toolbar { +.insight_error #rack-insight_toolbar { background: #ff0000; color: #fff; border: none; } -.insight_error #insight_toolbar p { +.insight_error #rack-insight_toolbar p { margin-top: 6px; margin-left: 15px; font-weight: bold; color: #fff; } -#insight_toolbar ul { +#rack-insight_toolbar ul { margin: 0; padding: 0; list-style: none; } -#insight_toolbar li { +#rack-insight_toolbar li { color: #fff; display: inline; font-size: 11px; @@ -63,32 +63,32 @@ position: relative; width: auto; } -#insight_toolbar li a { +#rack-insight_toolbar li a { border-left: 1px solid #487858; padding: 8px 9px 9px; } -#insight_toolbar li a:hover { +#rack-insight_toolbar li a:hover { background: #487858; color: #fff; } -#insight_toolbar li:last-child { +#rack-insight_toolbar li:last-child { border-right: 1px solid #487858; } -#insight_toolbar #insight_disable_button { +#rack-insight_toolbar #rack-insight_disable_button { color: red; font-weight: bold; padding-left: 5px; } -#insight_toolbar #insight_debug_button { +#rack-insight_toolbar #rack-insight_debug_button { color: #92ef3f; padding-left: 5px; } -#insight .panel_content { +#rack-insight .panel_content { background: #2a5738; border-bottom: 2px solid #234f32; border-top: 2px solid #487858; @@ -104,65 +104,65 @@ overflow: auto; } -#insight.insight_top .panel_content { +#rack-insight.insight_top .panel_content { top: 32px; } -#insight.insight_bottom .panel_content { +#rack-insight.insight_bottom .panel_content { bottom: 32px; } -#insight .panel_content p a, -#insight .panel_content dl a { +#rack-insight .panel_content p a, +#rack-insight .panel_content dl a { color: #40684c; } -#insight .panel_content p a:hover, -#insight .panel_content dl a:hover { +#rack-insight .panel_content p a:hover, +#rack-insight .panel_content dl a:hover { color: #92EF3F; } -#insight .panel_content h3 { +#rack-insight .panel_content h3 { border-bottom: 1px solid #40684c; color: #92ef3f; padding: 0 0 5px; } -#insight .panel_content p { +#rack-insight .panel_content p { padding: 0 5px; } -#insight .panel_content p, -#insight .panel_content table, -#insight .panel_content ol, -#insight .panel_content dl { +#rack-insight .panel_content p, +#rack-insight .panel_content table, +#rack-insight .panel_content ol, +#rack-insight .panel_content dl { margin: 5px 0 15px; background-color: #fff; } -#insight .panel_content ul { +#rack-insight .panel_content ul { padding: 10px 30px 10px 30px; background-color: #fff; } -#insight .panel_content ul ul { +#rack-insight .panel_content ul ul { padding: 0; } -#insight #speedtracer.panel_content ul ul { +#rack-insight #speedtracer.panel_content ul ul { padding: 0 0 0 8px; } -#insight .panel_content table { +#rack-insight .panel_content table { width: 100%; clear: both; } -#insight .panel_content table a { +#rack-insight .panel_content table a { color: #40684C; } -#insight .panel_content table th { +#rack-insight .panel_content table th { background-color: #9dcc49; font-weight: bold; color: #000; @@ -173,39 +173,39 @@ border-right: 1px solid #b9d977; } -#insight .panel_content table td { +#rack-insight .panel_content table td { padding: 5px 10px; font-size: 11px; background: #fff; color: #000; vertical-align: top; } -#insight .panel_content table tr.odd td { +#rack-insight .panel_content table tr.odd td { background: #eee; } -#insight .panel_content .panel_controls { +#rack-insight .panel_content .panel_controls { float: right; font-weight: bold; } -#insight .panel_content .panel_controls form { +#rack-insight .panel_content .panel_controls form { display: inline; } -#insight .panel_content dt, #insight .panel_content dd { +#rack-insight .panel_content dt, #rack-insight .panel_content dd { display: block; } -#insight .panel_content dd { +#rack-insight .panel_content dd { margin-left: 10px; } -#insight .panel_content table tr.odd td.insight_spinner, -#insight .panel_content table tr.even td.insight_spinner, -#insight .panel_content table td.insight_spinner, -#insight .insight_spinner { +#rack-insight .panel_content table tr.odd td.insight_spinner, +#rack-insight .panel_content table tr.even td.insight_spinner, +#rack-insight .panel_content table td.insight_spinner, +#rack-insight .insight_spinner { background-image: url(/__insight__/spinner.gif); background-repeat: no-repeat; background-position: center center; @@ -213,23 +213,23 @@ color: transparent; } -#insight #sql.panel_content th.time { +#rack-insight #sql.panel_content th.time { width: 80px; } -#insight #sql.panel_content th.backtrace { +#rack-insight #sql.panel_content th.backtrace { width: 100px; } -#insight #sql.panel_content th.actions { +#rack-insight #sql.panel_content th.actions { width: 150px; } -#insight #request_variables td.code > div { +#rack-insight #request_variables td.code > div { max-height:200px; max-width: 800px; overflow:auto; } -#insight #templates ul { +#rack-insight #templates ul { padding-left:20px; } diff --git a/lib/insight/public/__insight__/insight.js b/lib/rack/insight/public/__insight__/insight.js similarity index 76% rename from lib/insight/public/__insight__/insight.js rename to lib/rack/insight/public/__insight__/insight.js index ee6c0bf..23513e9 100644 --- a/lib/insight/public/__insight__/insight.js +++ b/lib/rack/insight/public/__insight__/insight.js @@ -10,12 +10,12 @@ jQuery(function($) { Insight.prototype = { switchCurrentPanel: function() { if(this.request_id && this.panel_id) { - this.current = $('#insight #request_' + this.request_id + ' #' + this.panel_id) + this.current = $('#rack-insight #request_' + this.request_id + ' #' + this.panel_id) } }, getPanelContent: function() { $.get("__insight__/panels_content?request_id=" + this.request_id, function(data) { - $('#insight').append(data) + $('#rack-insight').append(data) $.insight.switchCurrentPanel() $.insight.openCurrent() }) @@ -43,7 +43,7 @@ jQuery(function($) { }) }, openCurrent: function() { - $('#insight .panel_content').hide(); + $('#rack-insight .panel_content').hide(); this.current.show(); this.open(); }, @@ -74,42 +74,42 @@ jQuery(function($) { $(document).unbind('keydown.insight'); $('.panel_content').hide(); }); - $('#insight ul.panels li a').live('click', function() { + $('#rack-insight ul.panels li a').live('click', function() { $.insight.panel_id = this.className $.insight.switchCurrentPanel() $.insight.toggleCurrent() return false; }); - $('#insight_debug_window a.back').live('click',function() { + $('#rack-insight_debug_window a.back').live('click',function() { $(this).parent().hide(); return false; }); - $('#insight a.remote_call').live('click',function() { - $('#insight_debug_window').load(this.href, null, function() { - $('#insight_debug_window').show(); + $('#rack-insight a.remote_call').live('click',function() { + $('#rack-insight_debug_window').load(this.href, null, function() { + $('#rack-insight_debug_window').show(); }) return false; }); - $('#insight a.reveal_backtrace').live('click',function() { + $('#rack-insight a.reveal_backtrace').live('click',function() { $(this).parents("tr").next().toggle(); return false; }); - $('#insight a.reveal_response').live('click',function() { + $('#rack-insight a.reveal_response').live('click',function() { $(this).parents("tr").next().next().toggle(); return false; }); - $('#insight a.insight_close').live('click',function() { + $('#rack-insight a.insight_close').live('click',function() { $(document).trigger('close.insight'); return false; }); $('#request_id_menu').live('change', function(){ $.insight.changeRequest($(this).val()) }); - $('#insight_debug_button').live('click',function(){ - $('#insight').toggleClass('insight_top').toggleClass('insight_bottom'); + $('#rack-insight_debug_button').live('click',function(){ + $('#rack-insight').toggleClass('rack-insight_top').toggleClass('rack-insight_bottom'); return false; }); - $('#insight_disable_button').live('click',function(){ + $('#rack-insight_disable_button').live('click',function(){ document.insightDisable(); return false; }); diff --git a/lib/insight/public/__insight__/jquery-1.3.2.js b/lib/rack/insight/public/__insight__/jquery-1.3.2.js similarity index 99% rename from lib/insight/public/__insight__/jquery-1.3.2.js rename to lib/rack/insight/public/__insight__/jquery-1.3.2.js index c9483f6..3354d97 100644 --- a/lib/insight/public/__insight__/jquery-1.3.2.js +++ b/lib/rack/insight/public/__insight__/jquery-1.3.2.js @@ -1266,150 +1266,150 @@ jQuery.each({ function num(elem, prop) { return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0; } -var expando = "jQuery" + now(), uuid = 0, windowData = {}; - -jQuery.extend({ - cache: {}, - - data: function( elem, name, data ) { - elem = elem == window ? - windowData : - elem; - - var id = elem[ expando ]; - - // Compute a unique ID for the element - if ( !id ) - id = elem[ expando ] = ++uuid; - - // Only generate the data cache if we're - // trying to access or manipulate it - if ( name && !jQuery.cache[ id ] ) - jQuery.cache[ id ] = {}; - - // Prevent overriding the named cache with undefined values - if ( data !== undefined ) - jQuery.cache[ id ][ name ] = data; - - // Return the named cache data, or the ID for the element - return name ? - jQuery.cache[ id ][ name ] : - id; - }, - - removeData: function( elem, name ) { - elem = elem == window ? - windowData : - elem; - - var id = elem[ expando ]; - - // If we want to remove a specific section of the element's data - if ( name ) { - if ( jQuery.cache[ id ] ) { - // Remove the section of cache data - delete jQuery.cache[ id ][ name ]; - - // If we've removed all the data, remove the element's cache - name = ""; - - for ( name in jQuery.cache[ id ] ) - break; - - if ( !name ) - jQuery.removeData( elem ); - } - - // Otherwise, we want to remove all of the element's data - } else { - // Clean up the element expando - try { - delete elem[ expando ]; - } catch(e){ - // IE has trouble directly removing the expando - // but it's ok with using removeAttribute - if ( elem.removeAttribute ) - elem.removeAttribute( expando ); - } - - // Completely remove the data cache - delete jQuery.cache[ id ]; - } - }, - queue: function( elem, type, data ) { - if ( elem ){ - - type = (type || "fx") + "queue"; - - var q = jQuery.data( elem, type ); - - if ( !q || jQuery.isArray(data) ) - q = jQuery.data( elem, type, jQuery.makeArray(data) ); - else if( data ) - q.push( data ); - - } - return q; - }, - - dequeue: function( elem, type ){ - var queue = jQuery.queue( elem, type ), - fn = queue.shift(); - - if( !type || type === "fx" ) - fn = queue[0]; - - if( fn !== undefined ) - fn.call(elem); - } -}); - -jQuery.fn.extend({ - data: function( key, value ){ - var parts = key.split("."); - parts[1] = parts[1] ? "." + parts[1] : ""; - - if ( value === undefined ) { - var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]); - - if ( data === undefined && this.length ) - data = jQuery.data( this[0], key ); - - return data === undefined && parts[1] ? - this.data( parts[0] ) : - data; - } else - return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){ - jQuery.data( this, key, value ); - }); - }, - - removeData: function( key ){ - return this.each(function(){ - jQuery.removeData( this, key ); - }); - }, - queue: function(type, data){ - if ( typeof type !== "string" ) { - data = type; - type = "fx"; - } - - if ( data === undefined ) - return jQuery.queue( this[0], type ); - - return this.each(function(){ - var queue = jQuery.queue( this, type, data ); - - if( type == "fx" && queue.length == 1 ) - queue[0].call(this); - }); - }, - dequeue: function(type){ - return this.each(function(){ - jQuery.dequeue( this, type ); - }); - } +var expando = "jQuery" + now(), uuid = 0, windowData = {}; + +jQuery.extend({ + cache: {}, + + data: function( elem, name, data ) { + elem = elem == window ? + windowData : + elem; + + var id = elem[ expando ]; + + // Compute a unique ID for the element + if ( !id ) + id = elem[ expando ] = ++uuid; + + // Only generate the data cache if we're + // trying to access or manipulate it + if ( name && !jQuery.cache[ id ] ) + jQuery.cache[ id ] = {}; + + // Prevent overriding the named cache with undefined values + if ( data !== undefined ) + jQuery.cache[ id ][ name ] = data; + + // Return the named cache data, or the ID for the element + return name ? + jQuery.cache[ id ][ name ] : + id; + }, + + removeData: function( elem, name ) { + elem = elem == window ? + windowData : + elem; + + var id = elem[ expando ]; + + // If we want to remove a specific section of the element's data + if ( name ) { + if ( jQuery.cache[ id ] ) { + // Remove the section of cache data + delete jQuery.cache[ id ][ name ]; + + // If we've removed all the data, remove the element's cache + name = ""; + + for ( name in jQuery.cache[ id ] ) + break; + + if ( !name ) + jQuery.removeData( elem ); + } + + // Otherwise, we want to remove all of the element's data + } else { + // Clean up the element expando + try { + delete elem[ expando ]; + } catch(e){ + // IE has trouble directly removing the expando + // but it's ok with using removeAttribute + if ( elem.removeAttribute ) + elem.removeAttribute( expando ); + } + + // Completely remove the data cache + delete jQuery.cache[ id ]; + } + }, + queue: function( elem, type, data ) { + if ( elem ){ + + type = (type || "fx") + "queue"; + + var q = jQuery.data( elem, type ); + + if ( !q || jQuery.isArray(data) ) + q = jQuery.data( elem, type, jQuery.makeArray(data) ); + else if( data ) + q.push( data ); + + } + return q; + }, + + dequeue: function( elem, type ){ + var queue = jQuery.queue( elem, type ), + fn = queue.shift(); + + if( !type || type === "fx" ) + fn = queue[0]; + + if( fn !== undefined ) + fn.call(elem); + } +}); + +jQuery.fn.extend({ + data: function( key, value ){ + var parts = key.split("."); + parts[1] = parts[1] ? "." + parts[1] : ""; + + if ( value === undefined ) { + var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]); + + if ( data === undefined && this.length ) + data = jQuery.data( this[0], key ); + + return data === undefined && parts[1] ? + this.data( parts[0] ) : + data; + } else + return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){ + jQuery.data( this, key, value ); + }); + }, + + removeData: function( key ){ + return this.each(function(){ + jQuery.removeData( this, key ); + }); + }, + queue: function(type, data){ + if ( typeof type !== "string" ) { + data = type; + type = "fx"; + } + + if ( data === undefined ) + return jQuery.queue( this[0], type ); + + return this.each(function(){ + var queue = jQuery.queue( this, type, data ); + + if( type == "fx" && queue.length == 1 ) + queue[0].call(this); + }); + }, + dequeue: function(type){ + return this.each(function(){ + jQuery.dequeue( this, type ); + }); + } });/*! * Sizzle CSS Selector Engine - v0.9.3 * Copyright 2009, The Dojo Foundation diff --git a/lib/insight/public/__insight__/jquery.tablesorter.min.js b/lib/rack/insight/public/__insight__/jquery.tablesorter.min.js similarity index 100% rename from lib/insight/public/__insight__/jquery.tablesorter.min.js rename to lib/rack/insight/public/__insight__/jquery.tablesorter.min.js diff --git a/lib/insight/public/__insight__/spinner.gif b/lib/rack/insight/public/__insight__/spinner.gif similarity index 100% rename from lib/insight/public/__insight__/spinner.gif rename to lib/rack/insight/public/__insight__/spinner.gif diff --git a/lib/insight/rack_static_bug_avoider.rb b/lib/rack/insight/rack_static_bug_avoider.rb similarity index 92% rename from lib/insight/rack_static_bug_avoider.rb rename to lib/rack/insight/rack_static_bug_avoider.rb index 8a44283..21270f7 100644 --- a/lib/insight/rack_static_bug_avoider.rb +++ b/lib/rack/insight/rack_static_bug_avoider.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class RackStaticBugAvoider def initialize(app, static_app) @app = app diff --git a/lib/insight/redirect_interceptor.rb b/lib/rack/insight/redirect_interceptor.rb similarity index 86% rename from lib/insight/redirect_interceptor.rb rename to lib/rack/insight/redirect_interceptor.rb index efe88c1..87cfd07 100644 --- a/lib/insight/redirect_interceptor.rb +++ b/lib/rack/insight/redirect_interceptor.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class RedirectInterceptor include Render @@ -9,7 +9,7 @@ def initialize(app) def call(env) status, headers, body = @app.call(env) @response = Rack::Response.new(body, status, headers) - if @response.redirect? && env["insight.intercept_redirects"] + if @response.redirect? && env["rack-insight.intercept_redirects"] intercept_redirect end @response.to_a diff --git a/lib/insight/render.rb b/lib/rack/insight/render.rb similarity index 98% rename from lib/insight/render.rb rename to lib/rack/insight/render.rb index b74568c..46ed645 100644 --- a/lib/insight/render.rb +++ b/lib/rack/insight/render.rb @@ -1,6 +1,6 @@ require 'erb' -module Insight +module Rack::Insight module Render include ERB::Util include Logging diff --git a/lib/insight/request-recorder.rb b/lib/rack/insight/request-recorder.rb similarity index 78% rename from lib/insight/request-recorder.rb rename to lib/rack/insight/request-recorder.rb index fcd2820..9b13ff8 100644 --- a/lib/insight/request-recorder.rb +++ b/lib/rack/insight/request-recorder.rb @@ -1,7 +1,6 @@ -require 'insight' -require 'insight/database' +require 'rack/insight/database' -module Insight +module Rack::Insight class RequestRecorder def initialize(app) @app = app @@ -9,7 +8,7 @@ def initialize(app) end def call(env) - env["insight.request-id"] = + env["rack-insight.request-id"] = @request_table.store(env["REQUEST_METHOD"], env["PATH_INFO"]) diff --git a/lib/rack/insight/rspec_matchers.rb b/lib/rack/insight/rspec_matchers.rb new file mode 100644 index 0000000..35521bd --- /dev/null +++ b/lib/rack/insight/rspec_matchers.rb @@ -0,0 +1,33 @@ +module Rack::Insight + module RspecMatchers + + RSpec::Matchers.define :have_row do |container, key, value| + match do |response| + if value + response.should have_selector("#{container} tr", :content => key) do |row| + row.should contain(value) + end + else + response.should have_selector("#{container} tr", :content => key) + end + end + + failure_message_for_should do |response| + "Expected: \n#{response.body}\nto have a row matching #{key}" + end + end + + RSpec::Matchers.define :have_heading do |text| + match do |response| + response.should have_selector("#rack-insight_toolbar li") do |heading| + heading.should contain(text) + end + end + + failure_message_for_should do |response| + "Expected: \n#{response.body}\nto have heading #{text}" + end + end + + end +end diff --git a/lib/insight/toolbar.rb b/lib/rack/insight/toolbar.rb similarity index 94% rename from lib/insight/toolbar.rb rename to lib/rack/insight/toolbar.rb index eef6407..d807591 100644 --- a/lib/insight/toolbar.rb +++ b/lib/rack/insight/toolbar.rb @@ -1,4 +1,4 @@ -module Insight +module Rack::Insight class Toolbar include Render include Logging @@ -45,7 +45,7 @@ def inject_toolbar(response) end def render - req_id = (@env['insight.request-id'] || @request_table.last_request_id).to_i + req_id = (@env['rack-insight.request-id'] || @request_table.last_request_id).to_i requests = @request_table.to_a.map do |row| { :id => row[0], :method => row[1], :path => row[2] } end diff --git a/lib/rack/insight/version.rb b/lib/rack/insight/version.rb new file mode 100644 index 0000000..24ba913 --- /dev/null +++ b/lib/rack/insight/version.rb @@ -0,0 +1,7 @@ +module Rack + module Insight + + VERSION = '0.5.0' + + end +end diff --git a/lib/insight/views/enable-button.html.erb b/lib/rack/insight/views/enable-button.html.erb similarity index 65% rename from lib/insight/views/enable-button.html.erb rename to lib/rack/insight/views/enable-button.html.erb index 784cfad..fef57c5 100644 --- a/lib/insight/views/enable-button.html.erb +++ b/lib/rack/insight/views/enable-button.html.erb @@ -1,6 +1,6 @@ -Insight +Rack::Insight diff --git a/lib/insight/views/error.html.erb b/lib/rack/insight/views/error.html.erb similarity index 76% rename from lib/insight/views/error.html.erb rename to lib/rack/insight/views/error.html.erb index 657f5bb..74529f6 100644 --- a/lib/insight/views/error.html.erb +++ b/lib/rack/insight/views/error.html.erb @@ -9,9 +9,9 @@ @import url(/__insight__/insight.css); -
-
+
+
-

There was an error within Insight!

+

There was an error within Rack::Insight!

diff --git a/lib/insight/views/headers_fragment.html.erb b/lib/rack/insight/views/headers_fragment.html.erb similarity index 61% rename from lib/insight/views/headers_fragment.html.erb rename to lib/rack/insight/views/headers_fragment.html.erb index da18ebe..3810fa7 100644 --- a/lib/insight/views/headers_fragment.html.erb +++ b/lib/rack/insight/views/headers_fragment.html.erb @@ -1,5 +1,5 @@ -
  • [X]
  • -
  • Insight (req# <%= request_id %>)
  • +
  • [X]
  • +
  • Rack::Insight (req# <%= request_id %>)
  • <% panels.each do |panel| %>
  • <% begin %> @@ -8,7 +8,9 @@ <%= panel.heading_for_request(request_id) %> <% else %> - <%= panel.heading_for_request(request_id) %> + + <%= panel.heading_for_request(request_id) %> + <% end %> <% rescue Object => ex %> Err: <%= panel.name rescue "xxx" %> diff --git a/lib/insight/views/panels/active_record.html.erb b/lib/rack/insight/views/panels/active_record.html.erb similarity index 100% rename from lib/insight/views/panels/active_record.html.erb rename to lib/rack/insight/views/panels/active_record.html.erb diff --git a/lib/insight/views/panels/active_resource.html.erb b/lib/rack/insight/views/panels/active_resource.html.erb similarity index 100% rename from lib/insight/views/panels/active_resource.html.erb rename to lib/rack/insight/views/panels/active_resource.html.erb diff --git a/lib/insight/views/panels/cache.html.erb b/lib/rack/insight/views/panels/cache.html.erb similarity index 83% rename from lib/insight/views/panels/cache.html.erb rename to lib/rack/insight/views/panels/cache.html.erb index 9f33996..615152f 100644 --- a/lib/insight/views/panels/cache.html.erb +++ b/lib/rack/insight/views/panels/cache.html.erb @@ -48,7 +48,7 @@ Parameters Function - + Delete All @@ -64,7 +64,7 @@ query.keys.first) %>" class="remote_call">View | - query.keys.first) %>" class="insight_delete_cache">Delete + query.keys.first) %>" class="rack-insight_delete_cache">Delete <% i += 1 %> @@ -75,14 +75,14 @@ -
    -
    +
    +
      <%= headers_fragment %>
    @@ -25,5 +25,5 @@ <%= request_fragment %> -
    +
    diff --git a/logical-insight.gemspec b/logical-insight.gemspec deleted file mode 100644 index ba9fc40..0000000 --- a/logical-insight.gemspec +++ /dev/null @@ -1,155 +0,0 @@ -# -*- encoding: utf-8 -*- - -Gem::Specification.new do |s| - s.name = %q{logical-insight} - s.version = "0.4.7" - - s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= - s.authors = ["Evan Dorn", "Judson Lester", "Bryan Helmkamp"] - s.date = %q{2012-05-17} - s.email = %w{evan@lrdesign.com judson@lrdesign.com bryan@brynary.com} - s.extra_rdoc_files = [ - "README.md", - "MIT-LICENSE.txt" - ] - s.homepage = %q{http://lrdesign.github.com/logical-insight/} - s.require_paths = ["lib"] - s.rubygems_version = %q{1.3.7} - s.summary = %q{Debugging toolbar for Rack applications implemented as - middleware. Rails 3 compatible version maintained by Logical Reality - Design. } - s.description = %q{Debugging toolbar for Rack applications implemented as - middleware. Rails 3 compatible version maintained by Logical Reality - Design. } - - # Do this: y$@" - # !!find lib bin doc spec spec_help -not -regex '.*\.sw.' -type f 2>/dev/null - # - s.files = %w[ - lib/logical-insight.rb - lib/insight.rb - lib/insight/rack_static_bug_avoider.rb - lib/insight/toolbar.rb - lib/insight/views/request_fragment.html.erb - lib/insight/views/enable-button.html.erb - lib/insight/views/redirect.html.erb - lib/insight/views/headers_fragment.html.erb - lib/insight/views/panels/rails_info.html.erb - lib/insight/views/panels/execute_sql.html.erb - lib/insight/views/panels/timer.html.erb - lib/insight/views/panels/view_cache.html.erb - lib/insight/views/panels/speedtracer/serverevent.html.erb - lib/insight/views/panels/speedtracer/traces.html.erb - lib/insight/views/panels/speedtracer/servertrace.html.erb - lib/insight/views/panels/sql.html.erb - lib/insight/views/panels/templates.html.erb - lib/insight/views/panels/explain_sql.html.erb - lib/insight/views/panels/log.html.erb - lib/insight/views/panels/active_record.html.erb - lib/insight/views/panels/cache.html.erb - lib/insight/views/panels/request_variables.html.erb - lib/insight/views/panels/profile_sql.html.erb - lib/insight/views/panels/redis.html.erb - lib/insight/views/panels/active_resource.html.erb - lib/insight/views/toolbar.html.erb - lib/insight/views/error.html.erb - lib/insight/options.rb - lib/insight/panel.rb - lib/insight/logger.rb - lib/insight/database.rb - lib/insight/panels-header.rb - lib/insight/filtered_backtrace.rb - lib/insight/panels-content.rb - lib/insight/enable-button.rb - lib/insight/instrumentation.rb - lib/insight/app.rb - lib/insight/path-filter.rb - lib/insight/panels/request_variables_panel.rb - lib/insight/panels/redis_panel.rb - lib/insight/panels/rails_info_panel.rb - lib/insight/panels/sql_panel/panel_app.rb - lib/insight/panels/sql_panel/query.rb - lib/insight/panels/cache_panel/panel_app.rb - lib/insight/panels/cache_panel/stats.rb - lib/insight/panels/timer_panel.rb - lib/insight/panels/redis_panel/redis_extension.rb - lib/insight/panels/redis_panel/stats.rb - lib/insight/panels/sql_panel.rb - lib/insight/panels/templates_panel.rb - lib/insight/panels/log_panel.rb - lib/insight/panels/speedtracer_panel/trace-app.rb - lib/insight/panels/speedtracer_panel/tracer.rb - lib/insight/panels/active_record_panel.rb - lib/insight/panels/cache_panel.rb - lib/insight/panels/speedtracer_panel.rb - lib/insight/panels/templates_panel/rendering.rb - lib/insight/panels/memory_panel.rb - lib/insight/panels/active_resource_panel.rb - lib/insight/panels/active_resource_panel/query.rb - lib/insight/request-recorder.rb - lib/insight/public/__insight__/bookmarklet.html - lib/insight/public/__insight__/bookmarklet.js - lib/insight/public/__insight__/spinner.gif - lib/insight/public/__insight__/insight.css - lib/insight/public/__insight__/jquery.tablesorter.min.js - lib/insight/public/__insight__/insight.js - lib/insight/public/__insight__/jquery-1.3.2.js - lib/insight/redirect_interceptor.rb - lib/insight/panel_app.rb - lib/insight/instrumentation/instrument.rb - lib/insight/instrumentation/package-definition.rb - lib/insight/instrumentation/backstage.rb - lib/insight/instrumentation/client.rb - lib/insight/instrumentation/setup.rb - lib/insight/instrumentation/probe.rb - lib/insight/instrumentation/probe-definition.rb - lib/insight/params_signature.rb - lib/insight/render.rb - spec/custom_matchers.rb - spec/spec_helper.rb - spec/instrumentation_spec.rb - spec/fixtures/config.ru - spec/fixtures/dummy_panel.rb - spec/fixtures/sample_app.rb - spec/spec.opts - spec/insight_spec.rb - spec/insight/panels/mongo_panel_spec_pending.rb - spec/insight/panels/active_record_panel_spec.rb - spec/insight/panels/redis_panel_spec.rb - spec/insight/panels/templates_panel_spec.rb - spec/insight/panels/memory_panel_spec.rb - spec/insight/panels/timer_panel_spec.rb - spec/insight/panels/sql_panel_spec.rb - spec/insight/panels/rails_info_panel_spec.rb - spec/insight/panels/log_panel_spec.rb - spec/insight/panels/cache_panel_spec.rb - spec/rcov.opts - History.txt - MIT-LICENSE.txt - README.md - Rakefile - Thorfile - ] - - s.add_development_dependency "corundum", "~> 0.0.13" - s.add_development_dependency "redcarpet" - -=begin -Legacy files: would like to re-include them, but they need work - lib/insight/views/panels/mongo.html.erb - lib/insight/panels/mongo_panel/mongo_extension.rb - lib/insight/panels/mongo_panel/stats.rb - lib/insight/panels/mongo_panel.rb - - lib/insight/views/panels/sphinx.html.erb - lib/insight/panels/sphinx_panel/stats.rb - lib/insight/panels/sphinx_panel.rb - - This one is mostly just a curiousity - lib/insight/panels/speedtracer_panel/profiling.rb -=end - - s.add_dependency("uuid", "~> 2.3.1") - s.add_dependency("sqlite3", "~> 1.3.3") - #s.test_files = Dir.glob("spec/**/*") gem test assumes Test::Unit -end diff --git a/rack-insight.gemspec b/rack-insight.gemspec new file mode 100644 index 0000000..804d059 --- /dev/null +++ b/rack-insight.gemspec @@ -0,0 +1,34 @@ +# -*- encoding: utf-8 -*- +require File.expand_path('../lib/rack/insight/version', __FILE__) + +Gem::Specification.new do |s| + s.name = %q{rack-insight} + s.version = Rack::Insight::VERSION + + s.authors = ["Peter Boling", "Evan Dorn", "Judson Lester", "Bryan Helmkamp"] + s.email = %w{peter.boling@gmail.com evan@lrdesign.com judson@lrdesign.com bryan@brynary.com} + s.extra_rdoc_files = [ + "README.md", + "MIT-LICENSE.txt" + ] + + s.files = `git ls-files`.split($\) + s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + s.test_files = s.files.grep(%r{^(test|spec|features)/}) + s.require_paths = ["lib"] + + s.homepage = "https://github.com/pboling/rack-insight" + s.summary = %q{Debugging toolbar for Rack applications implemented as + middleware.} + s.description = %q{Debugging toolbar for Rack applications implemented as + middleware. Based on logical-insight and rack-bug. } + + s.add_runtime_dependency("rack") + s.add_runtime_dependency("uuidtools", ">= 2.1.2") # incurs far fewer dependencies that the uuid gem, and no shell forking + s.add_runtime_dependency("sqlite3", ">= 1.3.3") + s.add_development_dependency "redcarpet" + s.add_development_dependency(%q, [">= 1.2.8"]) + s.add_development_dependency(%q, [">= 2.1.0"]) + s.add_development_dependency(%q, [">= 0"]) + +end diff --git a/rack-insight.sqlite b/rack-insight.sqlite new file mode 100644 index 0000000..32a794a Binary files /dev/null and b/rack-insight.sqlite differ diff --git a/spec/custom_matchers.rb b/spec/custom_matchers.rb index 0dfeaa6..e69de29 100644 --- a/spec/custom_matchers.rb +++ b/spec/custom_matchers.rb @@ -1,31 +0,0 @@ -module CustomMatchers - extend RSpec::Matchers::DSL - - define :have_row do |container, key, value| - match do |response| - if value - response.should have_selector("#{container} tr", :content => key) do |row| - row.should contain(value) - end - else - response.should have_selector("#{container} tr", :content => key) - end - end - - failure_message_for_should do |response| - "Expected: \n#{response.body}\nto have a row matching #{key}" - end - end - - define :have_heading do |text| - match do |response| - response.should have_selector("#insight_toolbar li") do |heading| - heading.should contain(text) - end - end - - failure_message_for_should do |response| - "Expected: \n#{response.body}\nto have heading #{text}" - end - end -end diff --git a/spec/fixtures/dummy_panel.rb b/spec/fixtures/dummy_panel.rb index 95c9d1b..01162c3 100644 --- a/spec/fixtures/dummy_panel.rb +++ b/spec/fixtures/dummy_panel.rb @@ -1,2 +1,2 @@ -class DummyPanel < Insight::Panel +class DummyPanel < Rack::Insight::Panel end diff --git a/spec/fixtures/sample_app.rb b/spec/fixtures/sample_app.rb index a40db85..6835d39 100644 --- a/spec/fixtures/sample_app.rb +++ b/spec/fixtures/sample_app.rb @@ -32,7 +32,7 @@ def before_return(&block) - use Insight::App, :log_path => "insight-test.log", :on_initialize => proc {|app| + use Rack::Insight::App, :log_path => "rack-insight-test.log", :on_initialize => proc {|app| self.insight_app = app } use OneLastThing @@ -62,7 +62,7 @@ def before_return(&block)

    Hello

    -

    Page with bookmarklet for enabling Insight

    +

    Page with bookmarklet for enabling Rack::Insight

    Page with an error to check insight not rescuing errors

    diff --git a/spec/fixtures/star_trek_panel.rb b/spec/fixtures/star_trek_panel.rb new file mode 100644 index 0000000..ac591ca --- /dev/null +++ b/spec/fixtures/star_trek_panel.rb @@ -0,0 +1 @@ +class StarTrekPanel < Rack::Insight::Panel; end diff --git a/spec/insight_spec.rb b/spec/insight_spec.rb index 6449eb5..b5d07e2 100644 --- a/spec/insight_spec.rb +++ b/spec/insight_spec.rb @@ -1,14 +1,13 @@ -require File.expand_path(File.dirname(__FILE__) + '/spec_helper') -require 'logical-insight' +require 'spec_helper' -describe Insight do +describe Rack::Insight do before :each do reset_insight end - it "inserts the Insight toolbar" do + it "inserts the Rack::Insight toolbar" do response = get "/" - response.should have_selector("div#insight") + response.should have_selector("div#rack-insight") end it "updates the Content-Length" do @@ -16,36 +15,36 @@ response["Content-Length"].should == response.body.size.to_s end - it "serves the Insight assets under /__insight__/" do + it "serves the Rack::Insight assets under /__insight__/" do response = get "/__insight__/insight.css" response.should be_ok end it "modifies HTML responses with a charset" do response = get "/", :content_type => "application/xhtml+xml; charset=utf-8" - response.should have_selector("div#insight") + response.should have_selector("div#rack-insight") end it "does not modify XMLHttpRequest responses" do response = get "/", {}, { :xhr => true } - response.should_not have_selector("div#insight") + response.should_not have_selector("div#rack-insight") end it "modifies XHTML responses" do response = get "/", :content_type => "application/xhtml+xml" - response.should have_selector("div#insight") + response.should have_selector("div#rack-insight") end it "does not modify non-HTML responses" do response = get "/", :content_type => "text/csv" - response.should_not have_selector("div#insight") + response.should_not have_selector("div#rack-insight") end it "does not modify server errors" do app.disable :raise_errors response = get "/error" app.enable :raise_errors - response.should_not have_selector("div#insight") + response.should_not have_selector("div#rack-insight") end context "redirected when not configured to intercept redirects" do @@ -62,12 +61,12 @@ it "does not insert the toolbar" do header 'cookie', "" response = get "/redirect" - response.should_not have_selector("div#insight") + response.should_not have_selector("div#rack-insight") end it "does not insert the toolbar if even toolbar requested" do response = get "/redirect" - response.should_not have_selector("div#insight") + response.should_not have_selector("div#rack-insight") end end @@ -78,7 +77,7 @@ it "shows the interception page" do response = get "/redirect" - response.should have_selector("div#insight") + response.should have_selector("div#rack-insight") end it "should provide a link to the target URL" do @@ -88,13 +87,13 @@ it "inserts the toolbar if requested" do response = get "/redirect" - response.should have_selector("div#insight") + response.should have_selector("div#rack-insight") end it "does not inserts the toolbar if not requested" do header 'cookie', "" response = get "/redirect" - response.should_not have_selector("div#insight") + response.should_not have_selector("div#rack-insight") end end @@ -103,14 +102,14 @@ app.insight_app.ip_masks = [IPAddr.new("127.0.0.1/255.255.255.0")] end - it "inserts the Insight toolbar when the IP matches" do + it "inserts the Rack::Insight toolbar when the IP matches" do response = get_via_rack "/", {}, "REMOTE_ADDR" => "127.0.0.2" - response.should have_selector("div#insight") + response.should have_selector("div#rack-insight") end it "is disabled when the IP doesn't match" do response = get_via_rack "/", {}, "REMOTE_ADDR" => "128.0.0.1" - response.should_not have_selector("div#insight") + response.should_not have_selector("div#rack-insight") end it "doesn't use any panels" do @@ -125,16 +124,16 @@ app.insight_app.password = "secret" end - it "should insert the Insight toolbar when the password matches" do - sha = Digest::SHA1.hexdigest ["insight", "secret"].join(":") - set_cookie ["insight_enabled=1", "insight_password=#{sha}"] + it "should insert the Rack::Insight toolbar when the password matches" do + sha = Digest::SHA1.hexdigest ["rack-insight", "secret"].join(":") + set_cookie ["rack-insight_enabled=1", "rack-insight_password=#{sha}"] response = get_via_rack "/" - response.should have_selector("div#insight") + response.should have_selector("div#rack-insight") end it "should be disabled when the password doesn't match" do response = get_via_rack "/" - response.should_not have_selector("div#insight") + response.should_not have_selector("div#rack-insight") end it "doesn't use any panels" do DummyPanel.should_not_receive(:new) diff --git a/spec/instrumentation_spec.rb b/spec/instrumentation_spec.rb index 2aef902..a8ca718 100644 --- a/spec/instrumentation_spec.rb +++ b/spec/instrumentation_spec.rb @@ -1,5 +1,5 @@ -require 'insight/instrumentation' -require 'insight/instrumentation/setup' +require 'rack/insight/instrumentation' +require 'rack/insight/instrumentation/setup' class One def initialize(arry) @@ -42,7 +42,7 @@ def self.a_class_method(array) let :test_collector do collector = Object.new - collector.extend Insight::Instrumentation::Client + collector.extend Rack::Insight::Instrumentation::Client collector.instance_variable_set("@calls", method_calls) def collector.after_detect(method_call, timing, arguments, results) @calls << [method_call, timing, arguments, results] @@ -51,7 +51,7 @@ def collector.after_detect(method_call, timing, arguments, results) end let :instrument_setup do - Insight::Instrumentation::Setup.new(nil) + Rack::Insight::Instrumentation::Setup.new(nil) end let :fake_env do diff --git a/spec/rack/insight/config_spec.rb b/spec/rack/insight/config_spec.rb new file mode 100644 index 0000000..9c65e8f --- /dev/null +++ b/spec/rack/insight/config_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe Rack::Insight::Config do + + context "configured with panel_load_paths" do + before(:each) do + Rack::Insight::Config.configure do |config| + # spec folder is in the load path during specs! + config[:panel_load_paths] << ['fixtures'] + end + require 'fixtures/star_trek_panel' + reset_insight :panel_files => %w{star_trek_panel} + end + it "should use StarTrekPanel" do + app.insight_app.panel_classes.include?(StarTrekPanel).should be_true + get_via_rack "/" + end + end + +end diff --git a/spec/insight/panels/active_record_panel_spec.rb b/spec/rack/insight/panels/active_record_panel_spec.rb similarity index 94% rename from spec/insight/panels/active_record_panel_spec.rb rename to spec/rack/insight/panels/active_record_panel_spec.rb index d56cd94..6e3110d 100644 --- a/spec/insight/panels/active_record_panel_spec.rb +++ b/spec/rack/insight/panels/active_record_panel_spec.rb @@ -1,5 +1,6 @@ -require File::expand_path("../../../spec_helper", __FILE__) -module Insight +require 'spec_helper' + +module Rack::Insight describe "ActiveRecordPanel" do before do mock_constant("ActiveRecord::Base") diff --git a/spec/insight/panels/active_resource_panel_spec.rb b/spec/rack/insight/panels/active_resource_panel_spec.rb similarity index 93% rename from spec/insight/panels/active_resource_panel_spec.rb rename to spec/rack/insight/panels/active_resource_panel_spec.rb index 788d789..8e03359 100644 --- a/spec/insight/panels/active_resource_panel_spec.rb +++ b/spec/rack/insight/panels/active_resource_panel_spec.rb @@ -1,5 +1,6 @@ -require File::expand_path("../../../spec_helper", __FILE__) -module Insight +require 'spec_helper' + +module Rack::Insight describe "ActiveResourcePanel" do before do mock_constant("ActiveResource::Connection") diff --git a/spec/insight/panels/cache_panel_spec.rb b/spec/rack/insight/panels/cache_panel_spec.rb similarity index 98% rename from spec/insight/panels/cache_panel_spec.rb rename to spec/rack/insight/panels/cache_panel_spec.rb index 4615b69..40a8953 100644 --- a/spec/insight/panels/cache_panel_spec.rb +++ b/spec/rack/insight/panels/cache_panel_spec.rb @@ -1,10 +1,12 @@ -module Insight +require 'spec_helper' + +module Rack::Insight describe "CachePanel" do before do mock_constant("Rails") mock_constant("Memcached") mock_constant("MemCache") - reset_insight :panel_classes => [CachePanel] + reset_insight :panel_classes => [Rack::Insight::CachePanel] end describe "heading" do diff --git a/spec/insight/panels/log_panel_spec.rb b/spec/rack/insight/panels/log_panel_spec.rb similarity index 83% rename from spec/insight/panels/log_panel_spec.rb rename to spec/rack/insight/panels/log_panel_spec.rb index 79275cd..3ecd5ce 100644 --- a/spec/insight/panels/log_panel_spec.rb +++ b/spec/rack/insight/panels/log_panel_spec.rb @@ -1,9 +1,9 @@ -require File::expand_path('../../../spec_helper', __FILE__) +require 'spec_helper' -module Insight +module Rack::Insight describe "LogPanel" do before do - reset_insight :panel_classes => [LogPanel] + reset_insight :panel_classes => [Rack::Insight::LogPanel] end describe "heading" do @@ -36,7 +36,7 @@ module Insight it "does not err out" do logger = LOGGER Object.send :remove_const, :LOGGER - lambda{ load("insight/panels/log_panel.rb") }.should_not raise_error + lambda{ load("rack/insight/panels/log_panel.rb") }.should_not raise_error ::LOGGER = logger end end diff --git a/spec/insight/panels/memory_panel_spec.rb b/spec/rack/insight/panels/memory_panel_spec.rb similarity index 79% rename from spec/insight/panels/memory_panel_spec.rb rename to spec/rack/insight/panels/memory_panel_spec.rb index 62b7d36..6878150 100644 --- a/spec/insight/panels/memory_panel_spec.rb +++ b/spec/rack/insight/panels/memory_panel_spec.rb @@ -1,7 +1,9 @@ -module Insight +require 'spec_helper' + +module Rack::Insight describe "MemoryPanel" do before do - reset_insight :panel => [MemoryPanel] + reset_insight :panel => [Rack::Insight::MemoryPanel] end describe "heading" do diff --git a/spec/insight/panels/mongo_panel_spec_pending.rb b/spec/rack/insight/panels/mongo_panel_spec_pending.rb similarity index 97% rename from spec/insight/panels/mongo_panel_spec_pending.rb rename to spec/rack/insight/panels/mongo_panel_spec_pending.rb index 77c83a1..73c9dc2 100644 --- a/spec/insight/panels/mongo_panel_spec_pending.rb +++ b/spec/rack/insight/panels/mongo_panel_spec_pending.rb @@ -1,5 +1,7 @@ +require 'spec_helper' + if defined? Mongo - module Insight + module Rack::Insight describe "MongoPanel" do before do MongoPanel.reset diff --git a/spec/insight/panels/rails_info_panel_spec.rb b/spec/rack/insight/panels/rails_info_panel_spec.rb similarity index 85% rename from spec/insight/panels/rails_info_panel_spec.rb rename to spec/rack/insight/panels/rails_info_panel_spec.rb index 0a78b57..1a20465 100644 --- a/spec/insight/panels/rails_info_panel_spec.rb +++ b/spec/rack/insight/panels/rails_info_panel_spec.rb @@ -1,8 +1,10 @@ -module Insight +require 'spec_helper' + +module Rack::Insight describe "RailsInfoPanel" do before do mock_constant("Rails::Info") - reset_insight :panel_classes => [RailsInfoPanel] + reset_insight :panel_classes => [Rack::Insight::RailsInfoPanel] Rails::Info.stub!(:properties => []) end diff --git a/spec/insight/panels/redis_panel_spec.rb b/spec/rack/insight/panels/redis_panel_spec.rb similarity index 96% rename from spec/insight/panels/redis_panel_spec.rb rename to spec/rack/insight/panels/redis_panel_spec.rb index 484e235..a365bc0 100644 --- a/spec/insight/panels/redis_panel_spec.rb +++ b/spec/rack/insight/panels/redis_panel_spec.rb @@ -1,5 +1,6 @@ -require File::expand_path("../../../spec_helper", __FILE__) -module Insight +require 'spec_helper' + +module Rack::Insight describe "RedisPanel" do before do reset_insight :panel_files => %w[redis_panel] diff --git a/spec/insight/panels/speedtracer_panel_spec.rb b/spec/rack/insight/panels/speedtracer_panel_spec.rb similarity index 98% rename from spec/insight/panels/speedtracer_panel_spec.rb rename to spec/rack/insight/panels/speedtracer_panel_spec.rb index 078f2a7..28b5a1d 100644 --- a/spec/insight/panels/speedtracer_panel_spec.rb +++ b/spec/rack/insight/panels/speedtracer_panel_spec.rb @@ -1,6 +1,6 @@ -require 'spec/spec_helper' +require 'spec_helper' -module Insight +module Rack::Insight describe "SpeedTracerPanel" do before do mock_constant("ActionView::Template") diff --git a/spec/insight/panels/sql_panel_spec.rb b/spec/rack/insight/panels/sql_panel_spec.rb similarity index 98% rename from spec/insight/panels/sql_panel_spec.rb rename to spec/rack/insight/panels/sql_panel_spec.rb index 3abf58d..1dad42f 100644 --- a/spec/insight/panels/sql_panel_spec.rb +++ b/spec/rack/insight/panels/sql_panel_spec.rb @@ -1,5 +1,6 @@ -require File::expand_path("../../../spec_helper", __FILE__) -module Insight +require 'spec_helper' + +module Rack::Insight describe "SQLPanel" do before do mock_constant("ActiveRecord::ConnectionAdapters::MysqlAdapter") diff --git a/spec/insight/panels/templates_panel_spec.rb b/spec/rack/insight/panels/templates_panel_spec.rb similarity index 96% rename from spec/insight/panels/templates_panel_spec.rb rename to spec/rack/insight/panels/templates_panel_spec.rb index f22577c..f9ee86b 100644 --- a/spec/insight/panels/templates_panel_spec.rb +++ b/spec/rack/insight/panels/templates_panel_spec.rb @@ -1,8 +1,10 @@ -module Insight +require 'spec_helper' + +module Rack::Insight describe "TemplatesPanel" do before do mock_constant("ActionView::Template") - reset_insight :panel_classes => [TemplatesPanel] + reset_insight :panel_classes => [Rack::Insight::TemplatesPanel] end describe "heading" do diff --git a/spec/insight/panels/timer_panel_spec.rb b/spec/rack/insight/panels/timer_panel_spec.rb similarity index 89% rename from spec/insight/panels/timer_panel_spec.rb rename to spec/rack/insight/panels/timer_panel_spec.rb index a774639..3f8bcf9 100644 --- a/spec/insight/panels/timer_panel_spec.rb +++ b/spec/rack/insight/panels/timer_panel_spec.rb @@ -1,7 +1,9 @@ -module Insight +require 'spec_helper' + +module Rack::Insight describe "TimerPanel" do before do - reset_insight :panel_classes => [TimerPanel] + reset_insight :panel_classes => [Rack::Insight::TimerPanel] end describe "heading" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index dfab771..4d0cc66 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,23 +4,34 @@ RAILS_ENV = "test" -$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__)) + '/lib' -$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__)) +#$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__)) + '/lib' +#$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__)) -require "insight" -require "spec/fixtures/sample_app" -require "spec/fixtures/dummy_panel" -require "spec/custom_matchers" +require "rack-insight" +require "fixtures/sample_app" +require "fixtures/dummy_panel" +require "rack/insight/rspec_matchers" RSpec.configure do |config| + config.treat_symbols_as_metadata_keys_with_true_values = true + config.run_all_when_everything_filtered = true + config.filter_run :focus + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + # TODO: Turn this on. Currently off because the specs bleed, and will randomly fail when run randomly. + #config.order = 'random' + TIME_MS_REGEXP = /\d+\.\d{2}ms/ - config.include Rack::Test::Methods + config.include Rack::Test::Methods config.include Webrat::Matchers - config.include CustomMatchers + config.include Rack::Insight::RspecMatchers config.before do - Thread.current["insight.logger"] = Insight::Logger.new(Logger::FATAL, "") + Thread.current["rack-insight.logger"] = Rack::Insight::Logger.new(Logger::FATAL, "") @added_constants = [] end @@ -32,16 +43,23 @@ end def reset_insight(options=nil) - system(*%w{rm -f insight.sqlite}) + system(*%w{rm -f rack-insight.sqlite}) - Insight::Database.reset + Rack::Insight::Database.reset app.prototype app.insight_app.reset(options) - Insight.enable + Rack::Insight.enable - set_cookie "insight_enabled=1" + set_cookie "rack-insight_enabled=1" + end + + def reset_config(config_options = {:panel_load_paths => [File::join('rack', 'insight', 'panels')]}) + Rack::Insight::Config.configure do |config| + # spec folder is in the load path during specs! + config[:panel_load_paths] = config_options[:panel_load_paths] + end end def app @@ -77,7 +95,7 @@ def mock_method_call(context, method, args=[], kind=:instance, object=Object.new block ||= proc {} - Insight::Instrumentation::Probe::ProbeRunner.probe_run( + Rack::Insight::Instrumentation::Probe::ProbeRunner.probe_run( object, context, kind, args, called_at, method, &block) end