pryx 0.3.1 → 0.4.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
  SHA256:
3
- metadata.gz: dcb416c6abf10f2f3445ba1f230cc22f2839fd2056e0eb789d292bc611a463c5
4
- data.tar.gz: 560f480272bee2673cb6b415267dc224f30d618015123734f75d9a97ed3be311
3
+ metadata.gz: 8dc55b47663a1ef4812e8c462d08d69816ca9e8034c39cf73f118e57c020eada
4
+ data.tar.gz: ea4bc22be549f9dcd3ba149ae8c1946f258564d10b9a4126c150115fe3cd6df1
5
5
  SHA512:
6
- metadata.gz: f042cb7cbe7d0ca0ceec859a39ef85d90fe871ca45fe1d34151a4fb87f094a9658f0ee35ef70a4900bd1a0f7e957e766127c82e4083f219b46150ba7f9b07b2a
7
- data.tar.gz: e695d828a869dd19a654e91d087ea3c3ad777a5c951b2f07cb54e832e721d7a4d0f4f3e54a993cde6dedc86a2957b5f51a0417d5393ef7f43c8d83934e8ec706
6
+ metadata.gz: 5b8dacec92274b90a844479b7a0c1b473fc1a84e530a9da411a021dfe32476283a86b91c3219a1c8e8d3459319cf1838ce271a0070880bde6a8338130ad64286
7
+ data.tar.gz: 1e36fb07f093e6d53079fb8d4a074b3c391cceebab425602fc60df8e5bfec55cd3647232dd87de6a949f584a73ad448847245d8218c61565afc365de46f1ee26
data/README.md CHANGED
@@ -1,35 +1,100 @@
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
2
 
3
- TODO: Write a gem description
4
-
5
- ## Philosophy
6
-
7
- TODO: Write philosophy
3
+ Three Virtues of a Programmer: Laziness, Impatience, and Hubris. -- Larry Wall, the author of Perl Programming language.
8
4
 
9
5
  ## Getting Started
10
6
 
11
- Install via Rubygems
7
+ Don't add this gem into bundler's Gemfile.
8
+
9
+ Instead, install it directly via RubyGems
12
10
 
13
11
  $ gem install pryx
14
12
 
15
- OR ...
13
+ ## Usage
16
14
 
17
- Add to your Gemfile
15
+ Before use it, you need set `RUBYOPT` variable.
18
16
 
19
- gem 'pryx'
17
+ You can do this two way in a terminal.
20
18
 
21
- ## Usage
19
+ ```sh
20
+ $: export RUBYOPT+=' -rpryx'
21
+ $: ruby your_file.rb # add pry! in your_file for start pry session
22
22
 
23
- TODO: Write usage instructions here
23
+ ```
24
24
 
25
- ## Support
25
+ or Run your's code directly use:
26
+
27
+ ```sh
28
+ $: RUBYOPT+='-rpryx' ruby your_file.rb # add pry! in your_file for start pry session
29
+ ```
30
+
31
+ Then, try add `pry!` into your's ruby code, then run it, have fun!
32
+
33
+ ## useful command add directly to Kernel#
34
+
35
+ ### pry!
36
+
37
+ start a pry session, this session only can be intercept once if add into a loop.
38
+ when used with a rails/roda web server, it only intercept one per request.
39
+
40
+ we have IRB equivalent, named `irb!`, for use more nice feature, use following code instead:
41
+
42
+ ```sh
43
+ $: RUBYOPT+='-rpryx_irb' ruby your_file.rb # add irb! in your_file for start pry session
44
+ ```
45
+
46
+ Following feature both available when start a Pry or IRB session:
47
+
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]
51
+
52
+ Following feature only available when start a Pry session:
26
53
 
27
- * MRI 1.9.3+
28
- * Rubinius 2.2+
54
+ 1. add `$/?` command for see source, see [pry-doc](https://github.com/pry/pry-doc)
55
+ 2. pry-remote debug support. you still use `pry!` no changes, it will use `pry-remote` automatically
56
+ if current ruby process was running on backround, then, it will use pry-remote, and listen on 0.0.0.0:9876,
57
+ 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)
29
65
 
30
- ## Dependency
66
+ pry2 do nothing, but it will be interceptd and start a pry session only after pry1 is running.
67
+
68
+ I haven use this hack for avoid pry session start on working place.
69
+
70
+ You know what i means.
71
+
72
+ ### irb1 irb2
73
+
74
+ IRB equivalent for pry1, pry2
75
+ we have irb1 and irb2 too.
76
+
77
+ ### pry3
78
+
79
+ It just normal `binding.pry`, that is, will always be intercept if code can reach.
80
+ but above plugins and libraries all correct configured.
81
+
82
+ we have another Kernel#pry?, which enable `pry-state` automatically, see [pry-state](https://github.com/SudhagarS/pry-state)
83
+
84
+ ### we have two binary, pryx, irbx
85
+
86
+ pryx is same as pry, but, with plugins and libraries correct configured.
87
+
88
+ irbx is same for irb.
89
+
90
+ ## Philosophy
91
+
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.
94
+
95
+ ## Support
31
96
 
32
- No known limit.
97
+ * MRI 2.2+
33
98
 
34
99
  ## History
35
100
 
@@ -46,6 +111,8 @@ No known limit.
46
111
  * Commit your changes: `git commit -am 'Add some feature'`.
47
112
  * Push to the branch: `git push origin my-new-feature`.
48
113
  * Send a pull request :D.
114
+
115
+ Not listed famous pry plugins is welcome!!
49
116
 
50
117
  ## license
51
118
 
@@ -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/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)
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, 1]
4
+ VERSION = [0, 4, 2]
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.1
4
+ version: 0.4.2
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
@@ -161,6 +189,10 @@ files:
161
189
  - lib/pry-disasm.rb
162
190
  - lib/pry-disasm/commands.rb
163
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
164
196
  - lib/pryx.rb
165
197
  - lib/pryx/ap_hack.rb
166
198
  - lib/pryx/background.rb