rack-debug19 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ doc/*
2
+ pkg
@@ -0,0 +1,58 @@
1
+ Install
2
+
3
+ $ gem install rack-debug
4
+
5
+ Rails
6
+
7
+ # config/environments/development.rb
8
+ config.gem 'rack-debug'
9
+ config.middleware.use 'Rack::Debug'
10
+
11
+ # RAILS_ROOT/Rakefile
12
+ require 'rack-debug/tasks'
13
+
14
+ Middleware
15
+
16
+ # add a use line to your builder
17
+ require 'rack/debug'
18
+ Rack::Builder.new do
19
+ use Rack::Debug
20
+ run MyApp.new
21
+ end
22
+
23
+ # can optionally specify where to put the sockets
24
+ use Rack::Debug, :socket_path => '/tmp/rack-debug'
25
+
26
+ # Rakefile
27
+ require 'rack-debug/tasks'
28
+
29
+ Add breakpoints to your code
30
+
31
+ @user = User.find(params[:id])
32
+ debugger
33
+ render :show
34
+
35
+ Debugging:
36
+
37
+ # run the rake task,
38
+ $ rake debug
39
+ Connected.
40
+
41
+ # refresh a page in your browser, your app will break at debugger statements
42
+ (rdb:1) p @user
43
+ #<User id: 1, name: "David Dollar", email: "ddollar@gmail.com", created_at: "...", updated_at: "...">
44
+
45
+ # can specify the socket path
46
+ SOCKET_PATH=/tmp/rack-debug rake debug
47
+
48
+ Meta:
49
+
50
+ Author/Maintainer: David Dollar
51
+
52
+ Patches contributed by:
53
+ Bart Teeuwisse
54
+
55
+ Thanks to:
56
+
57
+ Rack::Bug for a good example of Rack middleware in Rails
58
+ Ben Scofield for making me want to build some Rack middleware
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rack-debug19"
8
+ gem.summary = %Q{Rack::Debug adds a middleware interface to ruby-debug}
9
+ gem.description = <<-DESCRIPTION
10
+
11
+ Rack::Debug adds a middlerware interface to ruby-debug
12
+ http://github.com/github/rack-debug
13
+
14
+ DESCRIPTION
15
+ gem.email = "<ddollar@gmail.com>"
16
+ gem.homepage = "http://github.com/ddollar/rack-debug"
17
+ gem.authors = ["David Dollar"]
18
+
19
+ gem.add_dependency 'rack', '>= 1.0'
20
+ gem.add_dependency 'ruby-debug19', '>= 0.11.6'
21
+ end
22
+ Jeweler::GemcutterTasks.new
23
+ rescue LoadError
24
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
25
+ end
26
+
27
+ require 'spec/rake/spectask'
28
+ Spec::Rake::SpecTask.new(:spec) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.spec_files = FileList['spec/**/*_spec.rb']
31
+ end
32
+
33
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
34
+ spec.libs << 'lib' << 'spec'
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :spec => :check_dependencies
40
+
41
+ task :default => :spec
42
+
43
+ begin
44
+ require 'yard'
45
+ YARD::Rake::YardocTask.new
46
+ rescue LoadError
47
+ task :yardoc do
48
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
49
+ end
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.4.2
@@ -0,0 +1 @@
1
+ require 'rack/debug'
@@ -0,0 +1,97 @@
1
+ require 'ruby-debug'
2
+ require 'socket'
3
+ require 'thread'
4
+ require 'fileutils'
5
+
6
+ module Debugger
7
+
8
+ DEFAULT_SOCKET_PATH = File.join(Dir.getwd, 'tmp', 'sockets', 'debugger')
9
+
10
+ class << self
11
+ def start_unix_socket_remote(socket_path, post_mortem = false)
12
+ return if @thread
13
+ return if started?
14
+
15
+ socket_path ||= DEFAULT_SOCKET_PATH
16
+
17
+ self.interface = nil
18
+ start
19
+ self.post_mortem if post_mortem
20
+
21
+ FileUtils.mkdir_p(File.dirname(socket_path))
22
+
23
+ server_path = "#{socket_path}.server"
24
+ control_path = "#{socket_path}.control"
25
+
26
+ start_unix_socket_control(control_path)
27
+
28
+ yield if block_given?
29
+
30
+ mutex = Mutex.new
31
+ proceed = ConditionVariable.new
32
+
33
+ File.unlink(server_path) if File.exists?(server_path)
34
+ @thread = DebugThread.new do
35
+ server = UNIXServer.open(server_path)
36
+ while (session = server.accept)
37
+ self.interface = RemoteInterface.new(session)
38
+ if wait_connection
39
+ mutex.synchronize do
40
+ proceed.signal
41
+ end
42
+ end
43
+ end
44
+ end
45
+ if wait_connection
46
+ mutex.synchronize do
47
+ proceed.wait(mutex)
48
+ end
49
+ end
50
+ end
51
+ alias_method :start_unix_socket_server, :start_unix_socket_remote
52
+
53
+ def start_unix_socket_control(socket_path) # :nodoc:
54
+ raise "Debugger is not started" unless started?
55
+ return if defined?(@control_thread) && @control_thread
56
+
57
+ socket_path ||= DEFAULT_SOCKET_PATH
58
+
59
+ File.unlink(socket_path) if File.exists?(socket_path)
60
+ @control_thread = DebugThread.new do
61
+ server = UNIXServer.open(socket_path)
62
+ while (session = server.accept)
63
+ interface = RemoteInterface.new(session)
64
+ processor = ControlCommandProcessor.new(interface)
65
+ processor.process_commands
66
+ end
67
+ end
68
+ end
69
+
70
+ def start_unix_socket_client(socket_path)
71
+ socket_path ||= DEFAULT_SOCKET_PATH
72
+
73
+ require "socket"
74
+ interface = Debugger::LocalInterface.new
75
+ socket = UNIXSocket.new(socket_path + '.server')
76
+ puts "Connected."
77
+
78
+ catch(:exit) do
79
+ while (line = socket.gets)
80
+ case line
81
+ when /^PROMPT (.*)$/
82
+ input = interface.read_command($1)
83
+ throw :exit unless input
84
+ socket.puts input
85
+ when /^CONFIRM (.*)$/
86
+ input = interface.confirm($1)
87
+ throw :exit unless input
88
+ socket.puts input
89
+ else
90
+ print line
91
+ end
92
+ end
93
+ end
94
+ socket.close
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,17 @@
1
+ # desc "Explaining what the task does"
2
+ # task :socket_debugger do
3
+ # # Task goes here
4
+ # end
5
+
6
+ desc 'Launch the Rack::Debug client'
7
+ task :debug do
8
+ require File.join(File.dirname(__FILE__), 'debugger')
9
+
10
+ begin
11
+ Debugger.start_unix_socket_client ENV['SOCKET_PATH']
12
+ rescue Errno::ENOENT
13
+ puts "Server is not running or Passenger has spooled down"
14
+ rescue StandardError => ex
15
+ puts "Unable to connect to debugging socket: #{ex}"
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ require 'rack'
2
+
3
+ class Rack::Debug
4
+
5
+ attr_reader :app, :options
6
+
7
+ def initialize(app, options={})
8
+ @app = app
9
+ @options = options
10
+
11
+ extend_ruby_debug!
12
+ end
13
+
14
+ def call(env)
15
+ LineCache::clear_file_cache
16
+ Debugger.start_unix_socket_remote(socket_path)
17
+ app.call(env)
18
+ end
19
+
20
+ private ######################################################################
21
+
22
+ def extend_ruby_debug!
23
+ require File.join(File.dirname(__FILE__), '..', 'rack-debug', 'debugger')
24
+ end
25
+
26
+ def socket_path
27
+ options[:socket_path]
28
+ end
29
+
30
+ end
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rack-debug}
8
+ s.version = "1.4.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["David Dollar"]
12
+ s.date = %q{2010-01-04}
13
+ s.description = %q{
14
+ Rack::Debug adds a middlerware interface to ruby-debug
15
+ http://github.com/github/rack-debug
16
+
17
+ }
18
+ s.email = %q{<ddollar@gmail.com>}
19
+ s.extra_rdoc_files = [
20
+ "README.rdoc"
21
+ ]
22
+ s.files = [
23
+ ".gitignore",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/rack-debug.rb",
28
+ "lib/rack-debug/debugger.rb",
29
+ "lib/rack-debug/tasks.rb",
30
+ "lib/rack/debug.rb",
31
+ "rack-debug.gemspec"
32
+ ]
33
+ s.homepage = %q{http://github.com/ddollar/rack-debug}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.5}
37
+ s.summary = %q{Rack::Debug adds a middleware interface to ruby-debug}
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<rack>, [">= 1.0"])
45
+ s.add_runtime_dependency(%q<ruby-debug>, [">= 0.10"])
46
+ else
47
+ s.add_dependency(%q<rack>, [">= 1.0"])
48
+ s.add_dependency(%q<ruby-debug>, [">= 0.10"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<rack>, [">= 1.0"])
52
+ s.add_dependency(%q<ruby-debug>, [">= 0.10"])
53
+ end
54
+ end
55
+
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-debug19
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 4
8
+ - 2
9
+ version: 1.4.2
10
+ platform: ruby
11
+ authors:
12
+ - David Dollar
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-11 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rack
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ version: "1.0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: ruby-debug19
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ - 11
43
+ - 6
44
+ version: 0.11.6
45
+ type: :runtime
46
+ version_requirements: *id002
47
+ description: |+
48
+
49
+ Rack::Debug adds a middlerware interface to ruby-debug
50
+ http://github.com/github/rack-debug
51
+
52
+ email: <ddollar@gmail.com>
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files:
58
+ - README.rdoc
59
+ files:
60
+ - .gitignore
61
+ - README.rdoc
62
+ - Rakefile
63
+ - VERSION
64
+ - lib/rack-debug.rb
65
+ - lib/rack-debug/debugger.rb
66
+ - lib/rack-debug/tasks.rb
67
+ - lib/rack/debug.rb
68
+ - rack-debug.gemspec
69
+ has_rdoc: true
70
+ homepage: http://github.com/ddollar/rack-debug
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --charset=UTF-8
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.3.6
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Rack::Debug adds a middleware interface to ruby-debug
99
+ test_files: []
100
+