pry-inline 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bad0830574abaae8e85b28338c86853dfadf68ec
4
- data.tar.gz: 038f400021c0b7085a7dd829f2c31ff19678fcc5
3
+ metadata.gz: ccf76045d92a7d2fc6007dd1c25e50ecd132cd32
4
+ data.tar.gz: 57745615589a32560e63968cb342257b9591967a
5
5
  SHA512:
6
- metadata.gz: e63bb2968aca4882bf6489a9a81235a92aa0b8029d02f14ea81ef1314a286a346656999e8d5b90bd587c12434fe4d0afa15ee58f25b119f6771251bed2fd1300
7
- data.tar.gz: 07d738a52bb58f932cb5b3ccaae3a63576c6625b8573522b0686935bd84b7a48b477ebb5b92b88ac3b4d4a29a5391d1858f582190a74ba80bfbe60f4a66d648a
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/[USERNAME]/pry-inline.
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/when_started_hook'
6
- require 'pry-inline/before_session_hook'
5
+ require 'pry-inline/inline_debuggable_code'
7
6
 
8
- Pry.config.hooks
9
- .add_hook(:when_started, :pry_inline, PryInline::WhenStartedHook.new)
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, PryInline::BeforeSessionHook.new)
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
- def initialize(lines, start_line, code_type)
5
- super(lines, start_line, code_type)
6
-
7
- @lineno_to_variables = Hash.new { |h, k| h[k] = Set.new }
8
- traverse_sexp(Ripper.sexp(lines.is_a?(String) ? lines : lines.join("\n")))
9
- @lineno_to_variables.each do |lineno, variables|
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 with_marker(lineno = 1)
16
- super.tap do
17
- @lines.each do |line|
18
- line.variables = nil if line.lineno >= lineno
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 params).include?(event)
31
- traverse_sexp(sexp[1..sexp.length]) unless event.to_s.start_with?('@')
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..sexp.length])
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
@@ -1,3 +1,3 @@
1
1
  module PryInline
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
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.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-05 00:00:00.000000000 Z
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,2 +0,0 @@
1
- --format documentation
2
- --color
@@ -1,9 +0,0 @@
1
- require 'pry-inline/inline_debuggable_loc'
2
-
3
- module PryInline
4
- class BeforeSessionHook
5
- def call(_, target, _)
6
- PryInline::InlineDebuggableLOC.binding = target
7
- end
8
- end
9
- end
@@ -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