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 +4 -4
- data/lib/pry-state/hook_action.rb +16 -6
- data/lib/pry-state/printer.rb +43 -35
- data/lib/pry-state/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9da30b0944c81f4639366cdee57e1a4cef95a825
|
4
|
+
data.tar.gz: c90b73a17b7831a2de3471b5b7498ce3b7014d92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
23
|
-
|
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
|
-
|
27
|
-
|
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
|
|
data/lib/pry-state/printer.rb
CHANGED
@@ -1,43 +1,51 @@
|
|
1
|
-
module
|
2
|
-
|
1
|
+
module PryState
|
2
|
+
module Printer
|
3
|
+
extend self
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
# Ratios are 1:3 left:right
|
7
|
-
|
8
|
-
|
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
|
-
|
18
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
41
49
|
end
|
42
50
|
end
|
43
51
|
end
|
data/lib/pry-state/version.rb
CHANGED
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.
|
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:
|
11
|
+
date: 2017-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|