pry-inline 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -6
- data/README.md +1 -1
- data/lib/pry-inline.rb +7 -5
- data/lib/pry-inline/inline_debuggable_code.rb +41 -16
- data/lib/pry-inline/version.rb +1 -1
- metadata +3 -6
- data/.rspec +0 -2
- data/lib/pry-inline/before_session_hook.rb +0 -9
- data/lib/pry-inline/inline_debuggable_loc.rb +0 -45
- data/lib/pry-inline/when_started_hook.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccf76045d92a7d2fc6007dd1c25e50ecd132cd32
|
4
|
+
data.tar.gz: 57745615589a32560e63968cb342257b9591967a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adf5e3164713671c75e60575e0cf4976230f069482d8491ede24e4b43bcc0d669bc140100b65d320d1b621ae2418d3676a49efb2392d0cef6a29fdb29a8b213b
|
7
|
+
data.tar.gz: 81e37a0a848be77bda06062269b3ee8e6256b51b461fde7628271af3a5b00f7a468a21143a0d042d7d2c4ba76320778c92db882b17ef0eef6412e14a431d3547
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
AllCops:
|
2
2
|
Exclude:
|
3
3
|
- examples/*.rb
|
4
|
+
- test/**/*.rb
|
4
5
|
|
5
6
|
Metrics/LineLength:
|
6
7
|
Max: 120
|
@@ -13,9 +14,3 @@ Style/Documentation:
|
|
13
14
|
|
14
15
|
Style/FileName:
|
15
16
|
Enabled: false
|
16
|
-
|
17
|
-
Style/ParallelAssignment:
|
18
|
-
Enabled: false
|
19
|
-
|
20
|
-
Lint/UselessAssignment:
|
21
|
-
Enabled: false
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ push git commits and tags, and push the `.gem` file to [rubygems.org](https://ru
|
|
40
40
|
|
41
41
|
## Contributing
|
42
42
|
|
43
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/seikichi/pry-inline.
|
44
44
|
This project is intended to be a safe, welcoming space for collaboration,
|
45
45
|
and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
46
46
|
|
data/lib/pry-inline.rb
CHANGED
@@ -2,17 +2,19 @@ require 'pry'
|
|
2
2
|
require 'ripper'
|
3
3
|
require 'set'
|
4
4
|
|
5
|
-
require 'pry-inline/
|
6
|
-
require 'pry-inline/before_session_hook'
|
5
|
+
require 'pry-inline/inline_debuggable_code'
|
7
6
|
|
8
|
-
Pry.config.hooks
|
9
|
-
.
|
7
|
+
Pry.config.hooks.add_hook(:when_started, :pry_inline) do
|
8
|
+
Pry::Code.send(:prepend, PryInline::InlineDebuggableCode)
|
9
|
+
end
|
10
10
|
|
11
11
|
before_session_hooks = Pry.config.hooks.get_hooks(:before_session)
|
12
12
|
Pry.config.hooks.delete_hooks(:before_session)
|
13
13
|
|
14
14
|
begin
|
15
|
-
Pry.config.hooks.add_hook(:before_session, :pry_inline,
|
15
|
+
Pry.config.hooks.add_hook(:before_session, :pry_inline) do |_, target, _|
|
16
|
+
PryInline::InlineDebuggableCode.binding = target
|
17
|
+
end
|
16
18
|
ensure
|
17
19
|
before_session_hooks.each do |name, callable|
|
18
20
|
Pry.config.hooks.add_hook(:before_session, name, callable)
|
@@ -1,23 +1,27 @@
|
|
1
1
|
module PryInline
|
2
2
|
# monkey patch for Pry::Code
|
3
3
|
module InlineDebuggableCode
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
next if lineno == 0 || @lines.length <= lineno
|
11
|
-
@lines[lineno - 1].variables = variables
|
12
|
-
end
|
4
|
+
MAX_DEBUG_INFO_LENGTH = 80
|
5
|
+
|
6
|
+
@@binding = nil
|
7
|
+
|
8
|
+
def self.binding=(value)
|
9
|
+
@@binding = value
|
13
10
|
end
|
14
11
|
|
15
|
-
def
|
16
|
-
|
17
|
-
@
|
18
|
-
|
12
|
+
def print_to_output(output, color = false)
|
13
|
+
begin
|
14
|
+
@lineno_to_variables = Hash.new { |h, k| h[k] = Set.new }
|
15
|
+
traverse_sexp(Ripper.sexp(@lines.map(&:line).join("\n")))
|
16
|
+
@lineno_to_variables.each do |lineno, variables|
|
17
|
+
next if lineno == 0 || @lines.length <= lineno
|
18
|
+
next if @with_marker && lineno > (@marker_lineno - @lines[0].lineno)
|
19
|
+
add_debug_info(@lines[lineno - 1], variables)
|
19
20
|
end
|
21
|
+
ensure
|
22
|
+
ret = super(output, color)
|
20
23
|
end
|
24
|
+
ret
|
21
25
|
end
|
22
26
|
|
23
27
|
private
|
@@ -27,8 +31,9 @@ module PryInline
|
|
27
31
|
event = sexp[0]
|
28
32
|
|
29
33
|
return sexp.each { |s| traverse_sexp(s) } if event.is_a?(Array)
|
30
|
-
return traverse_sexp_in_assignment(sexp[1]) if %i(assign massign
|
31
|
-
|
34
|
+
return traverse_sexp_in_assignment(sexp[1]) if %i( assign massign ).include?(event)
|
35
|
+
return traverse_sexp_in_assignment(sexp[1..-1]) if event == :params
|
36
|
+
traverse_sexp(sexp[1..-1]) unless event.to_s.start_with?('@')
|
32
37
|
end
|
33
38
|
|
34
39
|
def traverse_sexp_in_assignment(sexp)
|
@@ -40,7 +45,27 @@ module PryInline
|
|
40
45
|
return @lineno_to_variables[sexp[2][0]] << sexp[1]
|
41
46
|
end
|
42
47
|
|
43
|
-
traverse_sexp_in_assignment(sexp[1
|
48
|
+
traverse_sexp_in_assignment(sexp[1..-1])
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_debug_info(loc, variables)
|
52
|
+
return if !variables || (variables & defined_variables).size <= 0
|
53
|
+
info = debug_info(variables)
|
54
|
+
loc.tuple[0] += " # #{info[0..MAX_DEBUG_INFO_LENGTH]}"
|
55
|
+
loc.tuple[0] += ' ...' if info.length > MAX_DEBUG_INFO_LENGTH
|
56
|
+
end
|
57
|
+
|
58
|
+
def defined_variables
|
59
|
+
return [] unless @@binding
|
60
|
+
@@binding.eval('local_variables').map(&:to_s) |
|
61
|
+
@@binding.eval('self.instance_variables').map(&:to_s) |
|
62
|
+
@@binding.eval('self.class.class_variables').map(&:to_s)
|
63
|
+
end
|
64
|
+
|
65
|
+
def debug_info(variables)
|
66
|
+
variables.select { |k| defined_variables.include?(k) }
|
67
|
+
.map { |k| "#{k}: #{@@binding.eval(k).inspect}" }
|
68
|
+
.join(', ')
|
44
69
|
end
|
45
70
|
end
|
46
71
|
end
|
data/lib/pry-inline/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-inline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seiichi KONDO
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -74,7 +74,6 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
|
-
- ".rspec"
|
78
77
|
- ".rubocop.yml"
|
79
78
|
- ".travis.yml"
|
80
79
|
- CODE_OF_CONDUCT.md
|
@@ -85,11 +84,8 @@ files:
|
|
85
84
|
- bin/console
|
86
85
|
- bin/setup
|
87
86
|
- lib/pry-inline.rb
|
88
|
-
- lib/pry-inline/before_session_hook.rb
|
89
87
|
- lib/pry-inline/inline_debuggable_code.rb
|
90
|
-
- lib/pry-inline/inline_debuggable_loc.rb
|
91
88
|
- lib/pry-inline/version.rb
|
92
|
-
- lib/pry-inline/when_started_hook.rb
|
93
89
|
- pry-inline.gemspec
|
94
90
|
- screenshot.png
|
95
91
|
homepage: https://github.com/seikichi/pry-inline
|
@@ -117,3 +113,4 @@ signing_key:
|
|
117
113
|
specification_version: 4
|
118
114
|
summary: Inline debugging like RubyMine
|
119
115
|
test_files: []
|
116
|
+
has_rdoc:
|
data/.rspec
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
module PryInline
|
2
|
-
# monkey patch for Pry::Code::LOC
|
3
|
-
module InlineDebuggableLOC
|
4
|
-
MAX_DEBUG_INFO_LENGTH = 80
|
5
|
-
|
6
|
-
@@binding = nil
|
7
|
-
|
8
|
-
attr_accessor :variables
|
9
|
-
|
10
|
-
def dup
|
11
|
-
super.tap { |ret| ret.variables = variables }
|
12
|
-
end
|
13
|
-
|
14
|
-
def colorize(code_type)
|
15
|
-
if @variables && (@variables & defined_variables).size > 0
|
16
|
-
if debug_info.length <= MAX_DEBUG_INFO_LENGTH
|
17
|
-
tuple[0] += " # #{debug_info}"
|
18
|
-
else
|
19
|
-
tuple[0] += " # #{debug_info[0..MAX_DEBUG_INFO_LENGTH]} ...}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
ensure
|
23
|
-
super(code_type)
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.binding=(value)
|
27
|
-
@@binding = value
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def defined_variables
|
33
|
-
return [] unless @@binding
|
34
|
-
@@binding.eval('local_variables').map(&:to_s) |
|
35
|
-
@@binding.eval('self.instance_variables').map(&:to_s) |
|
36
|
-
@@binding.eval('self.class.class_variables').map(&:to_s)
|
37
|
-
end
|
38
|
-
|
39
|
-
def debug_info
|
40
|
-
@variables.select { |k| defined_variables.include?(k) }
|
41
|
-
.map { |k| "#{k}: #{@@binding.eval(k).inspect}" }
|
42
|
-
.join(', ')
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'pry-inline/inline_debuggable_code'
|
2
|
-
require 'pry-inline/inline_debuggable_loc'
|
3
|
-
|
4
|
-
module PryInline
|
5
|
-
class WhenStartedHook
|
6
|
-
def call(_, _, _)
|
7
|
-
Pry::Code.send(:prepend, PryInline::InlineDebuggableCode)
|
8
|
-
Pry::Code::LOC.send(:prepend, PryInline::InlineDebuggableLOC)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|