pryx 0.3.1 → 0.4.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: dcb416c6abf10f2f3445ba1f230cc22f2839fd2056e0eb789d292bc611a463c5
4
- data.tar.gz: 560f480272bee2673cb6b415267dc224f30d618015123734f75d9a97ed3be311
3
+ metadata.gz: 2a6ae2e11955f264a9c73ecf4b11b06be4449e5ca5700010e8d1cb0790cee06b
4
+ data.tar.gz: 5bb01a1eb5eb2115ef31711a8d160afa25abaf0677b1172b2a383bbcc53d279c
5
5
  SHA512:
6
- metadata.gz: f042cb7cbe7d0ca0ceec859a39ef85d90fe871ca45fe1d34151a4fb87f094a9658f0ee35ef70a4900bd1a0f7e957e766127c82e4083f219b46150ba7f9b07b2a
7
- data.tar.gz: e695d828a869dd19a654e91d087ea3c3ad777a5c951b2f07cb54e832e721d7a4d0f4f3e54a993cde6dedc86a2957b5f51a0417d5393ef7f43c8d83934e8ec706
6
+ metadata.gz: 78b9fe62e3330c1b8619f8638f7d5121e4e9806eee6e5e242d9e91cb572c238462761bd9fcde671c882cd806e5b5559bcf93ddfb7228f250d014ce386c436e5c
7
+ data.tar.gz: 6c68b315d94c28d7dba89d87e548b52fe3506dcecea7660571a7dd7eb41bf7b3cc835ce34bc2a05e04756d8d0e3343e5c1b5ea9938e7bb46750889e239e6c43e
@@ -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, 0]
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.0
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