pryx 0.4.3 → 0.6.0

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
  SHA256:
3
- metadata.gz: 6d121965f11784fd2deb6c2fbee66d4f96faa2743906a9a9b400b85065359c1b
4
- data.tar.gz: 1f90e8cd2c47468f93ad15e1254f3688b91c1e307e98261e305709693f40a4e0
3
+ metadata.gz: 83cd7279138aacd2a29d974c18db5fd6d1a6bd6aa9ed6012167e88771c50d13e
4
+ data.tar.gz: 5d34a1c16ccaa9abfed32635614262e44414d5bd48b26e5ffc25614b1bf623c8
5
5
  SHA512:
6
- metadata.gz: 657a819364d7e7c648d603d5b0d924caac8ac4666f874bd3cbc4eb7920831dd889323cfcf235562918e70c3540a55f0cfe53cfc6461b51e4f4dbdc6cb8ad2856
7
- data.tar.gz: abdfabd15423b7bb21b16177ab7f20f9e276094983ae92977ee22e0f38c54dd2df78ef32289394ef06e8804b4cd847e1708ced38fef94119e4979c2655d0e34e
6
+ metadata.gz: 96c64a8e59687991d2c9ede2973ef32f97549c4b8aaa8e60f0993fa5202ec6dc62267e73e3bfb88404fe1b0424622a4224c60b2ce2d604799c4d2b50128d911b
7
+ data.tar.gz: 27b2f23ad20df15b0330cb929def9ead48d725c0743ad2174521dae7622e97ad8aed6329df162138443f18ab6c590f972d952b6dd431b5102888cbb1eff4b7a7
data/README.md CHANGED
@@ -9,6 +9,8 @@ Don't add this gem into bundler's Gemfile.
9
9
  Instead, install it directly via RubyGems
10
10
 
11
11
  $ gem install pryx
12
+
13
+ Then use can use pryx cross all your's project.
12
14
 
13
15
  ## Usage
14
16
 
@@ -30,9 +32,32 @@ $: RUBYOPT+='-rpryx' ruby your_file.rb # add pry! in your_file for start pry se
30
32
 
31
33
  Then, try add `pry!` into your's ruby code, then run it, have fun!
32
34
 
33
- ## useful command add directly to Kernel#
35
+ Following is a example, assume we have test.rb, it content like this:
36
+
37
+ ```rb
38
+ # test.rb
39
+ 3.times do
40
+ pry!
41
+ puts 'hello'
42
+ end
43
+ ```
44
+
45
+ Then, when you run `RUBYOPT='-rpryx' ruby test.rb`
46
+
47
+ ![pry.png](images/pry!.png)
48
+
49
+ You can even connect to a pry session started from remote or background process
50
+ use http connection.
34
51
 
35
- ### pry!
52
+ ![pry_remote.png](images/pry_remote.png)
53
+
54
+
55
+ Until now, you've only seen the tip of the iceberg, please have a try.
56
+
57
+
58
+ ## useful command which added directly to Kernel#
59
+
60
+ ### Kernel#pry!
36
61
 
37
62
  start a pry session, this session only can be intercept once if add into a loop.
38
63
  when used with a rails/roda web server, it only intercept one per request.
@@ -45,23 +70,27 @@ $: RUBYOPT+='-rpryx_irb' ruby your_file.rb # add irb! in your_file for start pry
45
70
 
46
71
  Following feature both available when start a Pry or IRB session:
47
72
 
48
- 1. add `next/step/up/down` command for debug, use [break](https://github.com/gsamokovarov/break)
49
- 2. add `Kernel#ls1`(use ls1 to avoid conflict with pry builtin ls command), see [looksee](https://github.com/oggy/looksee)
50
- 3. Use AwesomePrint for printer. see [https://github.com/awesome-print/awesome_print]
73
+ 1. Add `next/step/up/down` command for debug, use [break](https://github.com/gsamokovarov/break)
74
+ 2. Add `Kernel#ls1`(use ls1 to avoid conflict with pry builtin ls command), see [looksee](https://github.com/oggy/looksee)
75
+ 3. Use `ap` for pretty print. see [awesome-print](https://github.com/awesome-print/awesome_print)
76
+ 4. Use `Clipboard.copy` or `Clipboard.paste` to interactive with system clipboard. see [clipboard](https://github.com/janlelis/clipboard)
51
77
 
52
- Following feature only available when start a Pry session:
78
+ Following is pry command available only after start a Pry session:
53
79
 
54
- 1. add `$/?` command for see source, see [pry-doc](https://github.com/pry/pry-doc)
80
+ 1. Add `$/?` command for see source, see [pry-doc](https://github.com/pry/pry-doc)
55
81
  2. pry-remote debug support. you still use `pry!` no changes, it will use `pry-remote` automatically
56
82
  if current ruby process was running on backround, then, it will use pry-remote, and listen on 0.0.0.0:9876,
57
83
  Then, you can connect to it from another terminal! see [pry-remote](https://github.com/Mon-Ouie/pry-remote)
58
- 3. add `pa` command, see [pry-power_assert](https://github.com/yui-knk/pry-power_assert)
59
- 4. add `hier` command for print the class hierarchies, see [pry-hier](https://github.com/phaul/pry-hier)
60
- 5. add `pry-aa_ancestors` command for print the class hierarchy, see [pry-aa_ancestors](https://github.com/tbpgr/pry-aa_ancestors)
61
- 6. add `up/down/frame/stack` command, see [pry-stack_explorer](https://github.com/pry/pry-stack_explorer)
62
- 2. add `yes` or `y` command, see [pry-yes](https://github.com/christofferh/pry-yes)
63
-
64
- ### pry1 pry2 (sorry for this bad name, please create a issue you have a better one)
84
+ 3. Add `pa` command, see [pry-power_assert](https://github.com/yui-knk/pry-power_assert)
85
+ 4. Add `hier` command for print the class hierarchies, see [pry-hier](https://github.com/phaul/pry-hier)
86
+ 5. Add `pry-aa_ancestors` command for print the class hierarchy, see [pry-aa_ancestors](https://github.com/tbpgr/pry-aa_ancestors)
87
+ 6. Add `up/down/frame/stack` command, see [pry-stack_explorer](https://github.com/pry/pry-stack_explorer)
88
+ 7. Add `yes` or `y` command, see [pry-yes](https://github.com/christofferh/pry-yes)
89
+ 8. Add `pry-disam`, Check following screenshot for a example:
90
+
91
+ ![pry-disasm](images/disasm.png)
92
+
93
+ ### Kernel#pry1 Kernel#pry2 (sorry for this bad name, please create a issue you have a better one)
65
94
 
66
95
  pry2 do nothing, but it will be interceptd and start a pry session only after pry1 is running.
67
96
 
@@ -69,32 +98,57 @@ I haven use this hack for avoid pry session start on working place.
69
98
 
70
99
  You know what i means.
71
100
 
72
- ### irb1 irb2
101
+ ### Kernel#irb1 Kernel#irb2
73
102
 
74
103
  IRB equivalent for pry1, pry2
75
104
  we have irb1 and irb2 too.
76
105
 
77
- ### pry3
106
+ ### Kernel#pry3
78
107
 
79
108
  It just normal `binding.pry`, that is, will always be intercept if code can reach.
80
109
  but above plugins and libraries all correct configured.
81
110
 
82
111
  we have another Kernel#pry?, which enable `pry-state` automatically, see [pry-state](https://github.com/SudhagarS/pry-state)
83
112
 
84
- ### we have two binary, pryx, irbx
113
+ ### Add command from command line, rescue, kill-pry-rescue, pryx, irbx, pry!
114
+
115
+ `rescue` and `kill-pry-rescue` come from `pry-rescue` gem, it not load by default, but you can use rescue command from command line directly.
116
+ see [pry-rescue](https://github.com/ConradIrwin/pry-rescue)
85
117
 
86
118
  pryx is same as pry, but, with plugins and libraries correct configured.
87
119
 
88
- irbx is same for irb.
120
+ irbx is same things for irb.
121
+
122
+ pry! just a alias to `pry-remote` command, when `Kernel#pry!` was intercepted in a background process,
123
+ you can run `pry!` directly in terminal connect to it.
124
+
125
+ if your's pry-remote server started background on another host, or on a container, you man need
126
+ specify hostname and port, e.g. connnect to 192.168.1.100, with port 9876
127
+
128
+ ```sh
129
+ $: pry! -s 192.168.1.100 -p 9876
130
+ ```
89
131
 
90
132
  ## Philosophy
91
133
 
92
- This gem is design to maximum limit take effect current ruby program, so, it should be safe to use it.
93
- But, you should only use it when development, though, it was tested when use in docker-compose container too.
134
+ This gem is design to Minimal impact on target ruby code, in fact, after `require 'pryx'` or `RUBYOPT='-rpryx'`
135
+ (they do same thing), only several instance method be defined on Kernel, and several gems add to $LOAD_PATH,
136
+ but not load, ready to require it, no more. so, it should be safe to use it, either affect performance nor
137
+ namespace/variables etc.
138
+
139
+ But, you should only use it in development, though, it was tested is run in container(alpine) too.
140
+
141
+
142
+ ## Limit
143
+
144
+ 1. `break` not work well if you add more than one break point, but still use `next` goto the next break point,
145
+ See https://github.com/gsamokovarov/break/issues/12
146
+ 2. because `pry!` use binding.of\_caller, when work with pry-stack\_explorer up command, you can see two
147
+ more stack get pushed. so, you have to up 3 times instead 1 time in normal case.
94
148
 
95
149
  ## Support
96
150
 
97
- * MRI 2.2+
151
+ * MRI 2.6+
98
152
 
99
153
  ## History
100
154
 
@@ -6,7 +6,7 @@ Pry::Commands.create_command 'disasm' do
6
6
  group 'Context'
7
7
 
8
8
  def process
9
- expr = eval(arg_string)
9
+ expr = target.eval(arg_string)
10
10
  PryDisasm.process(expr)
11
11
  end
12
12
  end
data/lib/pry-disasm.rb CHANGED
@@ -1,11 +1,16 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'pry'
4
2
  require 'pry-disasm/commands'
5
3
 
6
4
  class PryDisasm
7
5
  def self.process(expr)
8
- str = RubyVM::InstructionSequence.disasm(expr)
6
+ case expr
7
+ when Method, Proc
8
+ str = RubyVM::InstructionSequence.disasm(expr)
9
+ when String
10
+ str = RubyVM::InstructionSequence.compile(expr).disasm
11
+ else
12
+ return puts "Error: The command 'disasm' requires Method/Proc/String instance."
13
+ end
9
14
 
10
15
  lines = str.split("\n")
11
16
  lines[0].gsub!(/=+/) { |s| "\033[0;32m#{s}\033[0m" }
@@ -0,0 +1,9 @@
1
+ require 'binding_of_caller'
2
+ require 'clipboard'
3
+
4
+ # ap_hack 可以确保,当使用 irb! 时,looksee ls1 输出显示正确,同时不用关闭 irb :USE_COLORIZE 设置。
5
+ # See https://github.com/oggy/looksee/issues/57
6
+ # 但是,ap_hack 必须放到 break_hack 前面,调换顺序,上面的 hack 失效。
7
+ # WARN: 下面两行代码顺序不要换。
8
+ require 'pryx/ap_hack'
9
+ require 'pryx/break_hack'
data/lib/pryx/irb_hack.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'binding_of_caller'
2
-
3
1
  class Binding
4
2
  def _irb(_host=nil)
5
3
  warn 'loading irb ...'
@@ -26,7 +24,9 @@ module Kernel
26
24
 
27
25
  ENV['IRB_was_started'] = 'true'
28
26
 
29
- binding.of_caller(1)._irb
27
+ require 'binding_of_caller'
28
+
29
+ irb3(2)
30
30
  end
31
31
 
32
32
  def reirb!
@@ -37,10 +37,19 @@ module Kernel
37
37
  ENV['IRB2_should_start'] = 'true'
38
38
  end
39
39
 
40
- def irb2(caller=1, remote: nil, port: 9876)
40
+ def irb2
41
41
  if ENV['IRB2_should_start'] == 'true'
42
42
  ENV['IRB2_should_start'] = nil
43
- binding.of_caller(caller)._irb
43
+
44
+ require 'binding_of_caller'
45
+
46
+ irb3(2)
44
47
  end
45
48
  end
49
+
50
+ def irb3(caller=1)
51
+ require 'binding_of_caller'
52
+
53
+ binding.of_caller(caller)._irb
54
+ end
46
55
  end
@@ -10,7 +10,7 @@
10
10
  # 被覆写的方法 灰色 30
11
11
 
12
12
  module Kernel
13
- def load_looksee
13
+ def _load_looksee
14
14
  case RbConfig::CONFIG['ruby_version']
15
15
  when '1.9.0'...'2.1.0'
16
16
  require 'old_looksee'
@@ -23,12 +23,12 @@ module Kernel
23
23
  end
24
24
 
25
25
  def ls1(*args)
26
- load_looksee unless defined? Looksee
26
+ _load_looksee unless defined? Looksee
27
27
  Looksee[self, *args, :noprivate]
28
28
  end
29
29
 
30
30
  def ls2(*args)
31
- load_looksee unless defined? Looksee
31
+ _load_looksee unless defined? Looksee
32
32
  Looksee[self, *args]
33
33
  end
34
34
  end
data/lib/pryx/pry_hack.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # 注意如果开启 pry-stack_explorer, 就不要使用 debugger, 因为进入新的上下文后, pry-stack_explorer 将失效.
2
2
 
3
- require 'binding_of_caller'
4
-
5
3
  class Binding
6
4
  def _pry(host=nil, port=nil, options={})
7
5
  if host
@@ -10,32 +8,8 @@ class Binding
10
8
  require 'pry'
11
9
  end
12
10
 
13
- require 'pryx/ap_hack'
14
-
15
- require 'pryx/break_hack'
16
-
17
- require 'pry-power_assert'
18
-
19
- require 'pry-doc'
20
-
21
- require 'pry-yes'
22
- Pry.commands.alias_command 'y', 'yes'
23
-
24
- require 'pry-hier'
25
-
26
- require 'pry-aa_ancestors'
27
- Pry::Commands.alias_command 'aa', 'aa_ancestors'
28
-
29
- # 这个必须在最后才有效, 但是目前存在一个问题,就是会将 pry3, pry! 加入 stacks
30
- # stack 显示 stack 的列表,frame 显示当前所在 stack, stack N 也可以根据数字跳转到 N
31
- require 'pry-stack_explorer' # Support: up, down, bottom, top, stack, frame
32
-
33
-
34
- Pry::Commands.block_command 'cc', 'Continue, but stop in pry! breakpoint' do
35
- Pry.instance_variable_set(:@initial_session, true)
36
- ENV['Pry_was_started'] = nil
37
- throw(:breakout)
38
- end
11
+ require 'pryx/common_plugins'
12
+ require 'pryx/pry_plugins'
39
13
 
40
14
  if host
41
15
  notify_send('loading remote pry ...')
@@ -78,14 +52,6 @@ module Kernel
78
52
  # 这里如果有代码, 将会让 pry! 进入这个方法, 因此保持为空.
79
53
  end
80
54
 
81
- # 等价于默认的 binding.pry, 会反复被拦截。
82
- # 起成 pry3 这个名字,也是为了方便直接使用。
83
- def pry3(caller=1, remote: nil, port: 9876)
84
- remote = '0.0.0.0' if Pryx::Background.background?
85
-
86
- binding.of_caller(caller)._pry(remote, port)
87
- end
88
-
89
55
  def pry1
90
56
  ENV['Pry2_should_start'] = 'true'
91
57
  end
@@ -96,10 +62,20 @@ module Kernel
96
62
  def pry2(caller=1, remote: nil, port: 9876)
97
63
  if ENV['Pry2_should_start'] == 'true'
98
64
  ENV['Pry2_should_start'] = nil
99
- binding.of_caller(caller)._pry(remote, port)
65
+ pry3(2, remote: remote, port: port)
100
66
  end
101
67
  end
102
68
 
69
+ # 等价于默认的 binding.pry, 会反复被拦截。
70
+ # 起成 pry3 这个名字,也是为了方便直接使用。
71
+ def pry3(caller=1, remote: nil, port: 9876)
72
+ remote = '0.0.0.0' if Pryx::Background.background?
73
+
74
+ require 'binding_of_caller'
75
+
76
+ binding.of_caller(caller)._pry(remote, port)
77
+ end
78
+
103
79
  def notify_send(msg)
104
80
  system("notify-send \"#{msg}\"") if system 'which notify-send &>/dev/null'
105
81
 
@@ -0,0 +1,23 @@
1
+ require 'pry-power_assert'
2
+
3
+ require 'pry-doc'
4
+
5
+ require 'pry-yes'
6
+ Pry.commands.alias_command 'y', 'yes'
7
+
8
+ require 'pry-hier'
9
+
10
+ require 'pry-disasm'
11
+
12
+ require 'pry-aa_ancestors'
13
+ Pry::Commands.alias_command 'aa', 'aa_ancestors'
14
+
15
+ # 这个必须在最后才有效, 但是目前存在一个问题,就是会将 pry3, pry! 加入 stacks
16
+ # stack 显示 stack 的列表,frame 显示当前所在 stack, stack N 也可以根据数字跳转到 N
17
+ require 'pry-stack_explorer' # Support: up, down, bottom, top, stack, frame
18
+
19
+ Pry::Commands.block_command 'cc', 'Continue, but stop in pry! breakpoint' do
20
+ Pry.instance_variable_set(:@initial_session, true)
21
+ ENV['Pry_was_started'] = nil
22
+ throw(:breakout)
23
+ end
data/lib/pryx/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pryx
4
- VERSION = [0, 4, 3]
4
+ VERSION = [0, 6, 0]
5
5
 
6
6
  class << VERSION
7
7
  include Comparable
data/lib/pryx_irb.rb CHANGED
@@ -5,10 +5,5 @@
5
5
  # we need set `export RUBYOPT+=" -rpryx_irb"` instead of `-rpryx` to make
6
6
  # irb work with break and ap gem.
7
7
 
8
- # ap_hack 可以确保,当时用 irb! 的时候,输入代码是彩色的,并且 looksee 也正常显示
9
- # 但是,ap_hack 不可以放到 break_hack 后面,否则会失效。
10
- # WARN: 下面两行代码顺序不要换。
11
- require 'pryx/ap_hack'
12
- require 'pryx/break_hack'
13
-
8
+ require 'pryx/common_plugins'
14
9
  require 'pryx'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pryx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Billy.Zheng(zw963)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-22 00:00:00.000000000 Z
11
+ date: 2022-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '4.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: clipboard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: pry
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -112,16 +126,16 @@ dependencies:
112
126
  name: pry-aa_ancestors
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - ">="
129
+ - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '0'
131
+ version: 0.0.1
118
132
  type: :runtime
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - ">="
136
+ - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '0'
138
+ version: 0.0.1
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: pry-stack_explorer
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -137,7 +151,21 @@ dependencies:
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0.6'
139
153
  - !ruby/object:Gem::Dependency
140
- name: rake
154
+ name: pry-rescue
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.5'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.5'
167
+ - !ruby/object:Gem::Dependency
168
+ name: minitest
141
169
  requirement: !ruby/object:Gem::Requirement
142
170
  requirements:
143
171
  - - ">="
@@ -150,20 +178,34 @@ dependencies:
150
178
  - - ">="
151
179
  - !ruby/object:Gem::Version
152
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: m
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '1.6'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '1.6'
153
195
  - !ruby/object:Gem::Dependency
154
196
  name: ritual
155
197
  requirement: !ruby/object:Gem::Requirement
156
198
  requirements:
157
199
  - - "~>"
158
200
  - !ruby/object:Gem::Version
159
- version: '0.4'
201
+ version: '0.5'
160
202
  type: :development
161
203
  prerelease: false
162
204
  version_requirements: !ruby/object:Gem::Requirement
163
205
  requirements:
164
206
  - - "~>"
165
207
  - !ruby/object:Gem::Version
166
- version: '0.4'
208
+ version: '0.5'
167
209
  description: ''
168
210
  email:
169
211
  - vil963@gmail.com
@@ -197,10 +239,12 @@ files:
197
239
  - lib/pryx/ap_hack.rb
198
240
  - lib/pryx/background.rb
199
241
  - lib/pryx/break_hack.rb
242
+ - lib/pryx/common_plugins.rb
200
243
  - lib/pryx/drip.wav
201
244
  - lib/pryx/irb_hack.rb
202
245
  - lib/pryx/looksee_hack.rb
203
246
  - lib/pryx/pry_hack.rb
247
+ - lib/pryx/pry_plugins.rb
204
248
  - lib/pryx/trap_backtrace.rb
205
249
  - lib/pryx/version.rb
206
250
  - lib/pryx_irb.rb
@@ -217,7 +261,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
217
261
  requirements:
218
262
  - - ">="
219
263
  - !ruby/object:Gem::Version
220
- version: 2.2.2
264
+ version: '2.6'
221
265
  required_rubygems_version: !ruby/object:Gem::Requirement
222
266
  requirements:
223
267
  - - ">="