scryglass 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/example_config.rb +1 -1
- data/lib/scryglass/config.rb +1 -1
- data/lib/scryglass/lens_helper.rb +61 -44
- data/lib/scryglass/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69ff16003c6e5b4ceb6e93e9c5f9ee8aed269b50954db3869963fdf9ab64215b
|
4
|
+
data.tar.gz: 6d5c2f92d50b86a1e837033646b7793ee08e5115df98c47c2772775132875337
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f76204b2d6a0e67901e5cee79c5b4a1dcbe7fd08bf03c289cc95268b6e562d86bc49804f215a476e2239a7dfa388e66771c2ad1b1206b23b0b16aeee00607a1
|
7
|
+
data.tar.gz: 25171585025b50992b202bff43a881715a11cb7e48c0cfef522281357ea9d2de0de2b584446ba36d979fce45eba7509b69531118f98ce55d3b02c03c5534129e
|
data/CHANGELOG.md
CHANGED
@@ -13,6 +13,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
13
13
|
|
14
14
|
## Fixed
|
15
15
|
|
16
|
+
## [2.0.2] - 2020-01-14
|
17
|
+
|
18
|
+
## Added
|
19
|
+
|
20
|
+
## Changed
|
21
|
+
|
22
|
+
- Added a default character limit to the method_showcase_for lens to speed it up (Some AR objects have over 1000 methods).
|
23
|
+
|
24
|
+
## Fixed
|
25
|
+
|
16
26
|
## [2.0.1] - 2020-01-13
|
17
27
|
|
18
28
|
## Changed
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -204,7 +204,7 @@ Scryglass.configure do |config|
|
|
204
204
|
# { name: 'Puts (`puts`)',
|
205
205
|
# lambda: ->(o) { Hexes.capture_io(char_limit: 20_000) { puts o } } },
|
206
206
|
# { name: 'Method Showcase',
|
207
|
-
# lambda: ->(o) { Scryglass::LensHelper.method_showcase_for(o) } },
|
207
|
+
# lambda: ->(o) { Scryglass::LensHelper.method_showcase_for(o, char_limit: 20_000) } },
|
208
208
|
# ]
|
209
209
|
|
210
210
|
## AmazingPrint defaults, if the user has not set their own:
|
data/example_config.rb
CHANGED
@@ -21,7 +21,7 @@ Scryglass.configure do |config|
|
|
21
21
|
# { name: 'Puts (`puts`)',
|
22
22
|
# lambda: ->(o) { Hexes.capture_io(char_limit: 20_000) { puts o } } },
|
23
23
|
# { name: 'Method Showcase',
|
24
|
-
# lambda: ->(o) { Scryglass::LensHelper.method_showcase_for(o) } },
|
24
|
+
# lambda: ->(o) { Scryglass::LensHelper.method_showcase_for(o, char_limit: 20_000) } },
|
25
25
|
# ]
|
26
26
|
|
27
27
|
## AmazingPrint defaults, if the user has not set their own:
|
data/lib/scryglass/config.rb
CHANGED
@@ -35,7 +35,7 @@ module Scryglass
|
|
35
35
|
{ name: 'Puts (`puts`)',
|
36
36
|
lambda: ->(o) { Hexes.capture_io(char_limit: 20_000) { puts o } } },
|
37
37
|
{ name: 'Method Showcase',
|
38
|
-
lambda: ->(o) { Scryglass::LensHelper.method_showcase_for(o) } },
|
38
|
+
lambda: ->(o) { Scryglass::LensHelper.method_showcase_for(o, char_limit: 20_000) } },
|
39
39
|
]
|
40
40
|
|
41
41
|
## AmazingPrint defaults, if the user has not set their own:
|
@@ -2,66 +2,83 @@
|
|
2
2
|
|
3
3
|
module Scryglass
|
4
4
|
module LensHelper
|
5
|
-
|
5
|
+
using ClipStringRefinement
|
6
|
+
|
7
|
+
def self.method_showcase_for(object, char_limit: nil)
|
6
8
|
# method_list = object.methods - Object.methods
|
7
9
|
method_list = object.methods - Object.methods
|
8
10
|
return '' if method_list.empty?
|
9
11
|
|
10
12
|
label_space = [method_list.map(&:length).max, 45].min
|
11
|
-
method_list.sort
|
13
|
+
method_list.sort!
|
14
|
+
running_method_showcase = ''
|
15
|
+
|
16
|
+
method_list.each do |method_name|
|
12
17
|
label = method_name.to_s
|
13
18
|
label_padding = ' ' * [(label_space - label.length), 0].max
|
14
19
|
label = "\e[1;34m#{label}\e[0m" # make blue and bold
|
15
20
|
|
16
|
-
|
17
|
-
|
21
|
+
if char_limit && running_method_showcase.length >= char_limit
|
22
|
+
break
|
23
|
+
end
|
18
24
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
25
|
+
running_method_showcase <<
|
26
|
+
begin
|
27
|
+
method = object.method(method_name)
|
28
|
+
|
29
|
+
method_source_location = method.source_location.to_a.join(':')
|
30
|
+
source_location_line =
|
31
|
+
unless method_source_location.empty?
|
32
|
+
" \e[36m\e[4m#{method_source_location}\e[0m\n" # Cyan, underlined
|
33
|
+
end
|
24
34
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
35
|
+
highlighted_space = "\e[7m\s\e[0m"
|
36
|
+
method_lines = Hexes.capture_io { puts method.source }.split("\n")
|
37
|
+
method_lines.prepend('')
|
38
|
+
method_source = method_lines.map do |line|
|
39
|
+
' ' + highlighted_space + line
|
40
|
+
end.join("\n")
|
31
41
|
|
32
|
-
|
33
|
-
|
34
|
-
|
42
|
+
translated_parameters = method.parameters.map do |pair|
|
43
|
+
arg_type = pair[0]
|
44
|
+
arg_name = pair[1]
|
35
45
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
case arg_type
|
47
|
+
when :req
|
48
|
+
"#{arg_name}"
|
49
|
+
when :opt
|
50
|
+
"#{arg_name} = ?"
|
51
|
+
when :keyreq
|
52
|
+
"#{arg_name}:"
|
53
|
+
when :key
|
54
|
+
"#{arg_name}: ?"
|
55
|
+
when :rest
|
56
|
+
"*#{arg_name}"
|
57
|
+
when :keyrest
|
58
|
+
"**#{arg_name}"
|
59
|
+
when :block
|
60
|
+
"&#{arg_name}"
|
61
|
+
end
|
51
62
|
end
|
52
|
-
end
|
53
63
|
|
54
|
-
|
64
|
+
arg_preview = "(#{translated_parameters.join(', ')})"
|
55
65
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
66
|
+
"#{label} #{arg_preview}\n" +
|
67
|
+
source_location_line +
|
68
|
+
"#{method_source}\n\n"
|
69
|
+
rescue => e
|
70
|
+
"#{label}#{label_padding} : " \
|
71
|
+
"Error: \e[31m#{e.message}\n\e[0m" +
|
72
|
+
(source_location_line || '') +
|
73
|
+
"\n"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
if char_limit
|
78
|
+
running_method_showcase.ansiless_clip_at(char_limit)
|
79
|
+
else
|
80
|
+
running_method_showcase
|
81
|
+
end
|
65
82
|
end
|
66
83
|
end
|
67
84
|
end
|
data/lib/scryglass/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scryglass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Myers
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|