pry-state 0.1.8 → 0.1.9

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: 6eccdad43c0a88648366757e290f56d39cdb6f37
4
- data.tar.gz: e21eff3b8a714dc4b43cdbf39c2801a1c3c28f4c
3
+ metadata.gz: 9da30b0944c81f4639366cdee57e1a4cef95a825
4
+ data.tar.gz: c90b73a17b7831a2de3471b5b7498ce3b7014d92
5
5
  SHA512:
6
- metadata.gz: 7a1c0ba046e5dc5b3bf84204b5765f83162cd45b0b3694be2b9b6cf91004129d7cf66ff340e3bde48d25f0c7a6f0f0050b5706ddbcc2ec39ee1b59431c9bbe5a
7
- data.tar.gz: d65de01a734669d4dcf44710a3c83d8d5d28a6389174099b01c64ad7a364573bd146464a00c83b48473892c74b52d15ed1fe6ccc5dc090c1c79dcd27520bdcf5
6
+ metadata.gz: 185981b87ebc4070bf7346435e3343bacfdb37f01250a7721d3936b910241301daeaa1f21bec9969b83301c287d5ebf4de175d2f2e8e38ec1da3722dd86774ee
7
+ data.tar.gz: '094eaf046383729a9b282b9f4a81ae8baececb7fa88f5e988a86efc129ddeb4edc28a75d9926169576fd66c739e2b0deb9f85b1ae0dd2559cfd397b52a8d405a'
@@ -6,10 +6,10 @@ class HookAction
6
6
  CONTROLLER_INSTANCE_VARIABLES = [:@_request, :@_response, :@_routes]
7
7
  RSPEC_INSTANCE_VARIABLES = [:@__inspect_output, :@__memoized]
8
8
  IGNORABLE_INSTANCE_VARS = CONTROLLER_INSTANCE_VARIABLES + RSPEC_INSTANCE_VARIABLES
9
+ IGNORABLE_GLOBAL_VARS = [:$@]
9
10
 
10
11
  def initialize binding, pry
11
12
  @binding, @pry = binding, pry
12
-
13
13
  end
14
14
 
15
15
  def act
@@ -19,12 +19,22 @@ class HookAction
19
19
  return
20
20
  end
21
21
 
22
- (binding.eval('instance_variables').sort - IGNORABLE_INSTANCE_VARS).each do |var|
23
- eval_and_print var, var_color: 'green'
22
+ if ENV['SHOW_GLOBAL_VARIABLES']
23
+ (binding.eval('global_variables').sort - IGNORABLE_GLOBAL_VARS).each do |var|
24
+ eval_and_print var, var_color: 'white', value_colore: 'yellow'
25
+ end
26
+ end
27
+
28
+ unless ENV['HIDE_INSTANCE_VARIABLES']
29
+ (binding.eval('instance_variables').sort - IGNORABLE_INSTANCE_VARS).each do |var|
30
+ eval_and_print var, var_color: 'green'
31
+ end
24
32
  end
25
33
 
26
- (binding.eval('local_variables').sort - IGNORABLE_LOCAL_VARS).each do |var|
27
- eval_and_print var, var_color: 'cyan'
34
+ unless ENV['HIDE_LOCAL_VARIABLES']
35
+ (binding.eval('local_variables').sort - IGNORABLE_LOCAL_VARS).each do |var|
36
+ eval_and_print var, var_color: 'cyan'
37
+ end
28
38
  end
29
39
  end
30
40
 
@@ -36,7 +46,7 @@ class HookAction
36
46
  if value_changed? var, value
37
47
  var_color = "bright_#{var_color}"; value_color = 'bright_yellow'
38
48
  end
39
- Printer.trunc_and_print var, value, var_color, value_color
49
+ PryState::Printer.trunc_and_print var, value, var_color, value_color
40
50
  stick_value! var, value # to refer the value in next
41
51
  end
42
52
 
@@ -1,43 +1,51 @@
1
- module Printer
2
- extend self
1
+ module PryState
2
+ module Printer
3
+ extend self
3
4
 
4
- def trunc_and_print var, value, var_color, value_color
5
- width = ENV['COLUMNS'] ? ENV['COLUMNS'].to_i : 80
6
- # Ratios are 1:3 left:right
7
- left_column_width = width / 4
8
- left_column_width = left_column_width < 25 ? 25 : left_column_width
9
- var_name_adjusted = var.to_s.ljust(left_column_width)
10
- # Ensure at least 1 space between left and right columns
11
- left_column_text = truncate(var_name_adjusted, left_column_width - 1) + ' '
12
- print Pry::Helpers::Text.send(var_color, left_column_text)
13
- print stringified_val_or_nil(value, value_color, width - left_column_width)
14
- print "\n"
15
- end
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
16
10
 
17
- private
18
- def truncate text, length
19
- if text.nil? then return end
20
- l = length - "...".length
21
- (text.chars.to_a.size > length ? text.chars.to_a[0...l].join + "..." : text).to_s
22
- end
11
+ # Defaults to true
12
+ TRUNCATE = ENV['PRY_STATE_TRUNCATE'] != 'false'
23
13
 
24
- def stringified_val_or_nil value, color, length
25
- value = stringify_value value
26
- if value.empty?
27
- Pry::Helpers::Text.red 'nil'
28
- else
29
- text = truncate(value, length)
30
- Pry::Helpers::Text.send(color, text)
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
31
39
  end
32
- end
33
40
 
34
- def stringify_value value
35
- if value.class == String
36
- "\"#{value}\""
37
- elsif value.class == Array
38
- "len:#{value.count} #{value.inspect}"
39
- else
40
- value.inspect
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
41
49
  end
42
50
  end
43
51
  end
@@ -1,3 +1,3 @@
1
1
  module PryState
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-state
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sudhagar
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-24 00:00:00.000000000 Z
11
+ date: 2017-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler