ruby_inspector 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9cc62aa2145cbcc7a866417af8336e4938191bde
4
+ data.tar.gz: 9140911db39e45b9b73bbb59f8ae8fcf008590b2
5
+ SHA512:
6
+ metadata.gz: 6c45ff6e7d390b47ada436aa0a21e6db621fee5efa6b221d264a7d9a7ade3e33cd7c09af0573967280e353b0bdd1bb7b5466eb2d4e1e8d86554b5576534ec774
7
+ data.tar.gz: fdf89ce39c7efa9c11ced6fabf6b8cc2a5a5e99855c07c092c4ab008d048122da39f4bd2a01c196032e08e87c7e031dd11efa9e957b9ac846ff30d387d6d9766
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby_inspector.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Max Brosnahan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ # Ruby Inspector
2
+
3
+ Allows for ruby apps to be debugged using the standard chrome developer tools
4
+
5
+ # Getting started
6
+
7
+ 1. Get a copy of [chrome devtools app](https://github.com/auchenberg/chrome-devtools-app)
8
+ 2. Setup and start [ruby_inspector_server](https://github.com/gingermusketeer/ruby_inspector_server)
9
+ 3. Run `ruby demo.rb`
10
+ 4. Connect the devtools app to your app. apps -> Go
11
+ 5. Unleash the app from the breakpoint
12
+ 6. Monitor http traffic
13
+
14
+
15
+ # Todo
16
+ - Start the server automatically in the background unless it is started (server.pid?)
17
+ - Pull the tcp socket port from the node app (socket.port?)
18
+ - Add ruby script debugging via byebug
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ruby_inspector'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require 'pry'
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,97 @@
1
+ require 'net/http'
2
+
3
+ module Nsa
4
+ class NetHttpTracker
5
+ class<<self
6
+ def on_request(&block)
7
+ if block_given?
8
+ @on_request = block
9
+ else
10
+ @on_request
11
+ end
12
+ end
13
+ end
14
+
15
+ attr_reader :protocol, :address, :port, :path, :method, :request_headers,
16
+ :request_body, :status_code, :status_message, :response_headers,
17
+ :response_body
18
+
19
+ def initialize(protocol, address, port, path, method, headers, body)
20
+ @protocol = protocol
21
+ @address = address
22
+ @port = port
23
+ @path = path
24
+ @method = method
25
+ @request_headers = headers
26
+ @request_body = body
27
+ self.class.on_request.call(self)
28
+ end
29
+
30
+ def url
31
+ "#{protocol}://#{address}#{path}"
32
+ end
33
+
34
+ def on_response(&block)
35
+ if block_given?
36
+ @on_response = block
37
+ else
38
+ @on_response
39
+ end
40
+ end
41
+
42
+ def on_body(&block)
43
+ if block_given?
44
+ @on_body = block
45
+ else
46
+ @on_body
47
+ end
48
+ end
49
+
50
+ def set_response_info(status_code, status_message, headers)
51
+ @status_code = status_code
52
+ @status_message = status_message
53
+ @response_headers = headers
54
+ on_response.call
55
+ end
56
+
57
+ def response_body=(body)
58
+ @response_body = body
59
+ on_body.call
60
+ end
61
+ end
62
+ end
63
+
64
+ module Net
65
+ class HTTP
66
+ alias_method(:orig_request, :request) unless method_defined?(:orig_request)
67
+ alias_method(:orig_connect, :connect) unless method_defined?(:orig_connect)
68
+
69
+ def request(req, request_body = nil, &block)
70
+ return orig_request(req, request_body, &block) unless started?
71
+ protocol = use_ssl? ? 'https' : 'http'
72
+ request_headers = Hash[req.each_header.to_a]
73
+ request_tracker = ::Nsa::NetHttpTracker.new(
74
+ protocol, @address, @port, req.path, req.method, request_headers,
75
+ request_body || req.body
76
+ )
77
+
78
+ response_body = ''
79
+ block_provided = block_given?
80
+ response = orig_request(req, request_body) do |resp|
81
+ resp.read_body { |str| response_body << str }
82
+ resp.define_singleton_method(:read_body) do |dest = nil, &block|
83
+ dest << response_body unless dest.nil?
84
+ block.call(response_body) unless block.nil?
85
+ response_body
86
+ end
87
+ block.call(resp) if block_provided
88
+ end
89
+
90
+ request_tracker.set_response_info(
91
+ response.code, response.message, Hash[response.each_header.to_a]
92
+ )
93
+ request_tracker.response_body = response_body
94
+ response
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,43 @@
1
+ require 'ruby_inspector/version'
2
+
3
+ require 'json'
4
+ require_relative './nsa/net_http_tracker'
5
+ require_relative './ruby_inspector/dev_tools_request_tracker'
6
+
7
+ module RubyInspector
8
+ DELIMITER = "\0"
9
+ class << self
10
+ def enable(app_name, description = '')
11
+ connect
12
+ send_init_info(app_name, description)
13
+
14
+ ::Nsa::NetHttpTracker.on_request do |net_http_request_tracker|
15
+ DevToolsRequestTracker.new(net_http_request_tracker)
16
+ end
17
+ end
18
+
19
+ def send_info(data)
20
+ socket.puts(
21
+ ::JSON.generate(data) + DELIMITER
22
+ )
23
+ end
24
+
25
+ private
26
+
27
+ attr_accessor :socket
28
+ def connect
29
+ @socket = TCPSocket.new('localhost', 8124)
30
+ end
31
+
32
+ def send_init_info(app_name, description)
33
+ send_info(
34
+ method: 'RubyInspector.initialize',
35
+ params: {
36
+ name: app_name,
37
+ type: :ruby,
38
+ description: description
39
+ }
40
+ )
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,75 @@
1
+ module RubyInspector
2
+ class DevToolsRequestTracker
3
+ def self.next_request_id
4
+ @current_request_id ||= 0
5
+ @current_request_id += 1
6
+ end
7
+
8
+ attr_reader :request_id, :request_tracker
9
+
10
+ def initialize(request_tracker)
11
+ @request_tracker = request_tracker
12
+ @request_id = self.class.next_request_id.to_s
13
+ notify_request_started
14
+ request_tracker.on_response { notify_response_received }
15
+ request_tracker.on_body { notify_body_received }
16
+ end
17
+
18
+ def notify_request_started
19
+ RubyInspector.send_info(
20
+ method: 'Network.requestWillBeSent',
21
+ params: {
22
+ requestId: request_id,
23
+ request: {
24
+ url: request_tracker.url,
25
+ method: request_tracker.method,
26
+ headers: request_tracker.request_headers,
27
+ postData: request_tracker.request_body
28
+ },
29
+ timestamp: Time.now.to_f,
30
+ type: 'Other'
31
+ }
32
+ )
33
+ end
34
+
35
+ def notify_response_received
36
+ RubyInspector.send_info(
37
+ method: 'Network.responseReceived',
38
+ params: {
39
+ requestId: request_id,
40
+ timestamp: Time.now.to_f,
41
+ type: 'Document',
42
+ response: {
43
+ url: request_tracker.url,
44
+ status: request_tracker.status_code,
45
+ statusText: request_tracker.status_message,
46
+ headers: request_tracker.response_headers,
47
+ mimeType: 'text/html',
48
+ requestHeaders: request_tracker.request_headers,
49
+ remotePort: request_tracker.port
50
+ }
51
+ }
52
+ )
53
+ end
54
+
55
+ def notify_body_received
56
+ RubyInspector.send_info(
57
+ method: 'RubyInspector.network.cacheBody',
58
+ params: { requestId: request_id },
59
+ result: {
60
+ body: request_tracker.response_body,
61
+ base64Encoded: false
62
+ }
63
+ )
64
+
65
+ RubyInspector.send_info(
66
+ method: 'Network.loadingFinished',
67
+ params: {
68
+ requestId: request_id,
69
+ timestamp: Time.now.to_f,
70
+ encodedDataLength: request_tracker.response_body.length
71
+ }
72
+ )
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ module RubyInspector
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruby_inspector/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ruby_inspector'
8
+ spec.version = RubyInspector::VERSION
9
+ spec.authors = ['Max Brosnahan']
10
+ spec.email = ['maximilianbrosnahan@gmail.com']
11
+
12
+ spec.summary = 'Debugging ruby with chrome devtools'
13
+ spec.homepage = 'https://github.com/gingermusketeer/ruby_inspector'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(/^(test|spec|features)\//)
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(/^exe\//) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.8'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.2'
26
+ spec.add_development_dependency 'rack', '~> 1.6'
27
+ spec.add_development_dependency 'thin', '~> 1.6'
28
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_inspector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Max Brosnahan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thin
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.6'
83
+ description:
84
+ email:
85
+ - maximilianbrosnahan@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/nsa/net_http_tracker.rb
101
+ - lib/ruby_inspector.rb
102
+ - lib/ruby_inspector/dev_tools_request_tracker.rb
103
+ - lib/ruby_inspector/version.rb
104
+ - ruby_inspector.gemspec
105
+ homepage: https://github.com/gingermusketeer/ruby_inspector
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.0.14
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Debugging ruby with chrome devtools
129
+ test_files: []
130
+ has_rdoc: