pryx 0.3.0 → 0.4.1

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: a9d67d15a83b0d92beee0841d429cb42bc2c91ce2c0aea21b4a8ebb68cc88125
4
- data.tar.gz: 828770b2b1bb5e958058d74136e9c759b461eac7ad8ff12c907ab92fa6b943f2
3
+ metadata.gz: '09eac82758bc4ccc6f232842efacfb4d6949bc2e4ed5a4a0e3277a6b239915b0'
4
+ data.tar.gz: f8244fb13a69f0db1973c80d24d6ca01fa63f54a486d968556e9844ec62cdc5a
5
5
  SHA512:
6
- metadata.gz: 1d6f3688c0709bc039167c55aea81b6cee322381631b40f1507abdb4d18067c8e92a196d5deeb2899df61588a8bfd4397f8954301507c0e0357ab849995831fb
7
- data.tar.gz: 8540e5b11640d70305e6f21f94459b7756bf13260ea441a87f62c89d3c4c90b308c021d0c5c59ea5d119300b31bbf1cba668620b394a316b8ae872c3a24728fb
6
+ metadata.gz: e827a19c29a4ec79ea836675183649ed897abaedbee169cf920f64940efe0b83a11af8102f22957f0ba139b35edc4cfcb067a9eaee30a36cbbdff75f9bb3a922
7
+ data.tar.gz: 5e7cd1b9e5d80ba3cd4d74fc20422f2151566958c2247e9a5eb92d869596a0b6a0f1d3e1aa2e73308daa1803917bb3f21ca2738ab15526f807b973a33673d43f
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
- # Pryx [![Build Status](https://travis-ci.org/zw963/pryx.svg?branch=master)](https://travis-ci.org/zw963/pryx) [![Gem Version](https://badge.fury.io/rb/pryx.svg)](http://badge.fury.io/rb/pryx)
1
+ # Pryx [![Build Status](https://travis-ci.com/zw963/pryx.svg?branch=master)](https://travis-ci.com/zw963/pryx) [![Gem Version](https://badge.fury.io/rb/pryx.svg)](http://badge.fury.io/rb/pryx)
2
+
3
+ Three Virtues of a Programmer: Laziness, Impatience, and Hubris. -- Larry Wall, the author of Perl Programming language.
2
4
 
3
- TODO: Write a gem description
4
5
 
5
6
  ## Philosophy
6
7
 
@@ -8,24 +9,86 @@ TODO: Write philosophy
8
9
 
9
10
  ## Getting Started
10
11
 
11
- Install via Rubygems
12
+ Don't add this gem into bundler's Gemfile.
13
+
14
+ Instead, install it directly via RubyGems
12
15
 
13
16
  $ gem install pryx
14
17
 
15
- OR ...
18
+ ## Usage
19
+
20
+ Before use it, you need set `RUBYOPT` variable.
16
21
 
17
- Add to your Gemfile
22
+ You can do this two way in a terminal.
18
23
 
19
- gem 'pryx'
24
+ ```sh
25
+ $: export RUBYOPT+=' -rpryx'
26
+ $: ruby your_file.rb # add pry! in your_file for start pry session
20
27
 
21
- ## Usage
28
+ ```
29
+
30
+ or Run your's code directly use:
31
+
32
+ ```sh
33
+ $: RUBYOPT+='-rpryx' ruby your_file.rb # add pry! in your_file for start pry session
34
+ ```
35
+
36
+ Then, try add `pry!` into your's ruby code, then run it, have fun!
37
+
38
+ ## useful command add directly to Kernel#
39
+
40
+ ### pry!
41
+
42
+ start a pry session, this session only can be intercept once if add into a loop.
43
+ when used with a rails/roda web server, it only intercept one per request.
44
+
45
+ we have IRB equivalent, named `irb!`, for use more nice feature, use following code instead:
46
+
47
+ ```sh
48
+ $: RUBYOPT+='-rpryx_irb' ruby your_file.rb # add irb! in your_file for start pry session
49
+ ```
50
+
51
+ Following feature both available when start a Pry or IRB session:
52
+
53
+ 1. add `next/step/up/down` command for debug, use [break](https://github.com/gsamokovarov/break)
54
+ 2. add `Kernel#ls1`(use ls1 to avoid conflict with pry builtin ls command), see [looksee](https://github.com/oggy/looksee)
55
+ 3. Use AwesomePrint for printer. see [https://github.com/awesome-print/awesome_print]
56
+
57
+ Following feature only available when start a Pry session:
58
+
59
+ 1. add `$/?` command for see source, see [pry-doc](https://github.com/pry/pry-doc)
60
+ 2. pry-remote debug support. you still use `pry!` no changes, it will use `pry-remote` automatically
61
+ if current ruby process was running on backround, then, it will use pry-remote, and listen on 0.0.0.0:9876,
62
+ Then, you can connect to it from another terminal! see [pry-remote](https://github.com/Mon-Ouie/pry-remote)
63
+ 3. add `pa` command, see [pry-power_assert](https://github.com/yui-knk/pry-power_assert)
64
+ 4. add `hier` command for print the class hierarchies, see [pry-hier](https://github.com/phaul/pry-hier)
65
+ 5. add `pry-aa_ancestors` command for print the class hierarchy, see [pry-aa_ancestors](https://github.com/tbpgr/pry-aa_ancestors)
66
+ 6. add `up/down/frame/stack` command, see [pry-stack_explorer](https://github.com/pry/pry-stack_explorer)
67
+ 2. add `yes` or `y` command, see [pry-yes](https://github.com/christofferh/pry-yes)
68
+
69
+ ### pry1 pry2 (sorry for this bad name, please create a issue you have a better one)
70
+
71
+ pry2 do nothing, but it will be interceptd and start a pry session only after pry1 is running.
72
+
73
+ I haven use this hack for avoid pry session start on working place.
74
+
75
+ You know what i means.
76
+
77
+ ### irb1 irb2
78
+
79
+ IRB equivalent for pry1, pry2
80
+ we have irb1 and irb2 too.
81
+
82
+ ### pry3
83
+
84
+ It just normal `binding.pry`, that is, will always be intercept if code can reach.
85
+ but above plugins and library all correct configured.
22
86
 
23
- TODO: Write usage instructions here
87
+ we have another Kernel#pry?, which enable `pry-state` automatically, see [pry-state](https://github.com/SudhagarS/pry-state)
24
88
 
25
89
  ## Support
26
90
 
27
- * MRI 1.9.3+
28
- * Rubinius 2.2+
91
+ * MRI 2.2+
29
92
 
30
93
  ## Dependency
31
94
 
@@ -46,6 +109,8 @@ No known limit.
46
109
  * Commit your changes: `git commit -am 'Add some feature'`.
47
110
  * Push to the branch: `git push origin my-new-feature`.
48
111
  * Send a pull request :D.
112
+
113
+ Not listed famous pry plugins is welcome!!
49
114
 
50
115
  ## license
51
116
 
data/bin/irbx ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # irb.rb - interactive ruby
4
+ # $Release Version: 0.9.6 $
5
+ # $Revision$
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+
9
+ require 'irb'
10
+ require 'pryx_irb'
11
+
12
+ IRB.start(__FILE__)
data/bin/pryx ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # (C) John Mair (banisterfiend)
5
+ # MIT license
6
+
7
+ $0 = 'pry'
8
+
9
+ require 'pry'
10
+ require 'pryx'
11
+
12
+ # Process command line options and run Pry
13
+ opts = Pry::CLI.parse_options
14
+ Pry::CLI.start(opts)
@@ -0,0 +1,61 @@
1
+ require 'pry-state/printer'
2
+
3
+ class HookAction
4
+ IGNORABLE_LOCAL_VARS = [:__, :_, :_ex_, :_pry_, :_out_, :_in_, :_dir_, :_file_]
5
+
6
+ CONTROLLER_INSTANCE_VARIABLES = [:@_request, :@_response, :@_routes]
7
+ RSPEC_INSTANCE_VARIABLES = [:@__inspect_output, :@__memoized]
8
+ IGNORABLE_INSTANCE_VARS = CONTROLLER_INSTANCE_VARIABLES + RSPEC_INSTANCE_VARIABLES
9
+ IGNORABLE_GLOBAL_VARS = [:$@]
10
+
11
+ def initialize binding, pry
12
+ @binding, @pry = binding, pry
13
+ end
14
+
15
+ def act
16
+ if ENV['SHOW_GLOBAL_VARIABLES']
17
+ (binding.eval('global_variables').sort - IGNORABLE_GLOBAL_VARS).each do |var|
18
+ eval_and_print var, var_color: 'white', value_colore: 'yellow'
19
+ end
20
+ end
21
+
22
+ unless ENV['HIDE_INSTANCE_VARIABLES']
23
+ (binding.eval('instance_variables').sort - IGNORABLE_INSTANCE_VARS).each do |var|
24
+ eval_and_print var, var_color: 'green'
25
+ end
26
+ end
27
+
28
+ unless ENV['HIDE_LOCAL_VARIABLES']
29
+ (binding.eval('local_variables').sort - IGNORABLE_LOCAL_VARS).each do |var|
30
+ eval_and_print var, var_color: 'cyan'
31
+ end
32
+ end
33
+ end
34
+
35
+ private
36
+ attr_reader :binding, :pry
37
+
38
+ def eval_and_print var, var_color: 'green', value_color: 'white'
39
+ value = binding.eval(var.to_s)
40
+ if value_changed? var, value
41
+ var_color = "bright_#{var_color}"; value_color = 'bright_yellow'
42
+ end
43
+ PryState::Printer.trunc_and_print var, value, var_color, value_color
44
+ stick_value! var, value # to refer the value in next
45
+ end
46
+
47
+ def value_changed? var, value
48
+ prev_state[var] and prev_state[var] != value
49
+ end
50
+
51
+ def stick_value! var, value
52
+ prev_state[var] = value
53
+ end
54
+
55
+ def prev_state
56
+ # init a hash to store state to be used in next session
57
+ # in finding diff
58
+ pry.config.extra_sticky_locals[:pry_state_prev] ||= {}
59
+ end
60
+
61
+ end
@@ -0,0 +1,51 @@
1
+ module PryState
2
+ module Printer
3
+ extend self
4
+
5
+ WIDTH = ENV['COLUMNS'] ? ENV['COLUMNS'].to_i : 80
6
+ MAX_LEFT_COLUMN_WIDTH = 25
7
+ # Ratios are 1:3 left:right, or 1/4 left
8
+ COLUMN_RATIO = 3 # right column to left ratio
9
+ LEFT_COLUMN_WIDTH = [(WIDTH / (COLUMN_RATIO + 1)).floor, MAX_LEFT_COLUMN_WIDTH].min
10
+
11
+ # Defaults to true
12
+ TRUNCATE = ENV['PRY_STATE_TRUNCATE'] != 'false'
13
+
14
+ def trunc_and_print var, value, var_color, value_color
15
+ var_name_adjusted = var.to_s.ljust(LEFT_COLUMN_WIDTH)
16
+ # Ensure at least 1 space between left and right columns
17
+ left_column_text = truncate(var_name_adjusted, LEFT_COLUMN_WIDTH - 1) + ' '
18
+ print Pry::Helpers::Text.send(var_color, left_column_text)
19
+ print stringified_val_or_nil(value, value_color, WIDTH - LEFT_COLUMN_WIDTH)
20
+ print "\n"
21
+ end
22
+
23
+ private
24
+ def truncate text, length
25
+ if text.nil? then return end
26
+ return text unless ENV['TRUNCATE']
27
+ l = length - "...".length
28
+ (text.chars.to_a.size > length ? text.chars.to_a[0...l].join + "..." : text).to_s
29
+ end
30
+
31
+ def stringified_val_or_nil value, color, length
32
+ value = stringify_value value
33
+ if value.empty?
34
+ Pry::Helpers::Text.red 'nil'
35
+ else
36
+ text = truncate(value, length)
37
+ Pry::Helpers::Text.send(color, text)
38
+ end
39
+ end
40
+
41
+ def stringify_value value
42
+ if value.class == String
43
+ "\"#{value}\""
44
+ elsif value.class == Array
45
+ "len:#{value.count} #{value.inspect}"
46
+ else
47
+ value.inspect
48
+ end
49
+ end
50
+ end
51
+ end
data/lib/pry-state.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "pry"
2
+ require 'pry-state/hook_action'
3
+
4
+
5
+ Pry.hooks.add_hook(:before_session, "pry_state_hook") do |output, binding, pry|
6
+ HookAction.new(binding, pry).act
7
+ end
data/lib/pry-yes.rb ADDED
@@ -0,0 +1,37 @@
1
+ Pry::Commands.create_command "yes" do
2
+ description 'Re-runs previous command with "Did you mean?" suggestion.'
3
+ def options(opt)
4
+ opt.on :d, :debug, 'Debug mode.'
5
+ end
6
+
7
+ def process
8
+ ex = target.eval("defined?(_ex_) and _ex_")
9
+ return unless ex && ex.message.include?("Did you mean?")
10
+
11
+ matched_exception = ex.message.match(
12
+ /undefined.*`(.*)'|uninitialized constant (.*)\n/)
13
+ return unless matched_exception
14
+
15
+ typo = matched_exception.captures.compact.first
16
+ return unless typo
17
+
18
+ typo_guess = ex.message.split('Did you mean? ').last.split.first
19
+ last_command = Pry.history.to_a[-2]
20
+ guessed_command = last_command.gsub(typo, typo_guess)
21
+
22
+ pry_instance.input = StringIO.new(guessed_command)
23
+ rescue => e
24
+ # Schhh
25
+ raise e if opts.present?(:debug)
26
+ ensure
27
+ if opts.present?(:debug)
28
+ puts "matched_exception: #{matched_exception}"
29
+ puts "typo: #{typo}"
30
+ puts "typo_guess: #{typo_guess}"
31
+ puts "last_command: #{last_command}"
32
+ puts "guessed_command: #{guessed_command}"
33
+ end
34
+ end
35
+ end
36
+
37
+ module PryYes; end
data/lib/pryx/ap_hack.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'awesome_print'
2
2
 
3
- AwesomePrint.defaults = {
4
- index: false
5
- }
3
+ # AwesomePrint.defaults = {
4
+ # index: false
5
+ # }
6
6
 
7
7
  if defined? AwesomePrint
8
8
  if defined? Pry
@@ -1,2 +1,6 @@
1
1
  require 'break'
2
2
  load "#{__dir__}/../break/pry/extensions.rb"
3
+
4
+ Pry.commands.alias_command 'n', 'next'
5
+ Pry.commands.alias_command 's', 'step'
6
+ Pry.commands.alias_command 'w', 'watch' # watch is pry builtin
data/lib/pryx/pry_hack.rb CHANGED
@@ -9,10 +9,27 @@ class Binding
9
9
  else
10
10
  require 'pry'
11
11
  end
12
+
12
13
  require 'pryx/ap_hack'
14
+
13
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
+
14
29
  # 这个必须在最后才有效, 但是目前存在一个问题,就是会将 pry3, pry! 加入 stacks
15
- require 'pry-stack_explorer'
30
+ # stack 显示 stack 的列表,frame 显示当前所在 stack, stack N 也可以根据数字跳转到 N
31
+ require 'pry-stack_explorer' # Support: up, down, bottom, top, stack, frame
32
+
16
33
 
17
34
  Pry::Commands.block_command 'cc', 'Continue, but stop in pry! breakpoint' do
18
35
  Pry.instance_variable_set(:@initial_session, true)
@@ -93,20 +110,34 @@ end
93
110
 
94
111
  # Hack for roda/rails, 在每一次发送请求之前,总是设定 ENV['Pry_was_started'] to nil.
95
112
  # 这可以确保,pry! 总是会被拦截,但是仅仅只会被拦截一次。
113
+
114
+ class Pryx::PryHackForRodaRailsMiddleware
115
+ attr_reader :app
116
+
117
+ def initialize(app)
118
+ @app = app
119
+ end
120
+
121
+ def call(env)
122
+ ENV['Pry_was_started'] = nil
123
+ @app.call(env)
124
+ end
125
+ end
126
+
96
127
  begin
97
128
  require 'roda'
98
- class PryHackRodaMiddleware
99
- attr_reader :app
100
-
101
- def initialize(app)
102
- @app = app
103
- end
129
+ Roda.use Pryx::PryHackForRodaRailsMiddleware
130
+ rescue LoadError
131
+ end
104
132
 
105
- def call(env)
106
- ENV['Pry_was_started'] = nil
107
- @app.call(env)
108
- end
133
+ begin
134
+ require 'active_support/lazy_load_hooks'
135
+ ActiveSupport.on_load(:before_configuration) do
136
+ # because exits less command error when use in container, use irb instead.
137
+ # require 'pry'
138
+ # require 'pryx'
139
+ # Rails.application.config.console = Pry
140
+ Rails.application.config.middleware.use Pryx::PryHackForRodaRailsMiddleware
109
141
  end
110
- Roda.use PryHackRodaMiddleware
111
142
  rescue LoadError
112
143
  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, 3, 0]
4
+ VERSION = [0, 4, 1]
5
5
 
6
6
  class << VERSION
7
7
  include Comparable
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pryx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Billy.Zheng(zw963)
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.0.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-hier
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.1'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-aa_ancestors
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: pry-stack_explorer
99
127
  requirement: !ruby/object:Gem::Requirement
@@ -140,13 +168,17 @@ description: ''
140
168
  email:
141
169
  - vil963@gmail.com
142
170
  executables:
171
+ - irbx
143
172
  - pry!
173
+ - pryx
144
174
  extensions: []
145
175
  extra_rdoc_files: []
146
176
  files:
147
177
  - LICENSE
148
178
  - README.md
179
+ - bin/irbx
149
180
  - bin/pry!
181
+ - bin/pryx
150
182
  - lib/break/pry/extensions.rb
151
183
  - lib/pry-byebug.rb
152
184
  - lib/pry-byebug/WARN
@@ -157,6 +189,10 @@ files:
157
189
  - lib/pry-disasm.rb
158
190
  - lib/pry-disasm/commands.rb
159
191
  - lib/pry-remote.rb
192
+ - lib/pry-state.rb
193
+ - lib/pry-state/hook_action.rb
194
+ - lib/pry-state/printer.rb
195
+ - lib/pry-yes.rb
160
196
  - lib/pryx.rb
161
197
  - lib/pryx/ap_hack.rb
162
198
  - lib/pryx/background.rb
@@ -191,5 +227,5 @@ requirements: []
191
227
  rubygems_version: 3.3.3
192
228
  signing_key:
193
229
  specification_version: 4
194
- summary: ''
230
+ summary: pry extension tools!
195
231
  test_files: []