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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 794955e1442681f7888649a777bba632228df242fb61506623900f8b301f7e68
4
- data.tar.gz: a91831413fb4c87d28281a2ab9bab126666d9646c56d9056563785e41914ceaf
3
+ metadata.gz: 69ff16003c6e5b4ceb6e93e9c5f9ee8aed269b50954db3869963fdf9ab64215b
4
+ data.tar.gz: 6d5c2f92d50b86a1e837033646b7793ee08e5115df98c47c2772775132875337
5
5
  SHA512:
6
- metadata.gz: dcc4c9b7d57a5f57c34ebddf4f4cd94cc1eec0d47dc28818efeb3be964c2a8533fb79cc85127b479759b318c1eb380a12a917bcd30b5942861d5de16738ad56c
7
- data.tar.gz: fac7a9f0f29d291b3711b7d5e8750c2af9567afda592666b58924bbc9d658a2cc36b7b040f735c245957ab4c62d2b16f8f24e76eb16463472c9fc367c2a6ef23
6
+ metadata.gz: 2f76204b2d6a0e67901e5cee79c5b4a1dcbe7fd08bf03c289cc95268b6e562d86bc49804f215a476e2239a7dfa388e66771c2ad1b1206b23b0b16aeee00607a1
7
+ data.tar.gz: 25171585025b50992b202bff43a881715a11cb7e48c0cfef522281357ea9d2de0de2b584446ba36d979fce45eba7509b69531118f98ce55d3b02c03c5534129e
@@ -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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scryglass (2.0.1)
4
+ scryglass (2.0.2)
5
5
  amazing_print
6
6
  binding_of_caller
7
7
  method_source
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:
@@ -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:
@@ -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
- def self.method_showcase_for(object)
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.map do |method_name|
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
- begin
17
- method = object.method(method_name)
21
+ if char_limit && running_method_showcase.length >= char_limit
22
+ break
23
+ end
18
24
 
19
- method_source_location = method.source_location.to_a.join(':')
20
- source_location_line =
21
- unless method_source_location.empty?
22
- " \e[36m\e[4m#{method_source_location}\e[0m\n" # Cyan, underlined
23
- end
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
- highlighted_space = "\e[7m\s\e[0m"
26
- method_lines = Hexes.capture_io { puts method.source }.split("\n")
27
- method_lines.prepend('')
28
- method_source = method_lines.map do |line|
29
- ' ' + highlighted_space + line
30
- end.join("\n")
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
- translated_parameters = method.parameters.map do |pair|
33
- arg_type = pair[0]
34
- arg_name = pair[1]
42
+ translated_parameters = method.parameters.map do |pair|
43
+ arg_type = pair[0]
44
+ arg_name = pair[1]
35
45
 
36
- case arg_type
37
- when :req
38
- "#{arg_name}"
39
- when :opt
40
- "#{arg_name} = ?"
41
- when :keyreq
42
- "#{arg_name}:"
43
- when :key
44
- "#{arg_name}: ?"
45
- when :rest
46
- "*#{arg_name}"
47
- when :keyrest
48
- "**#{arg_name}"
49
- when :block
50
- "&#{arg_name}"
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
- arg_preview = "(#{translated_parameters.join(', ')})"
64
+ arg_preview = "(#{translated_parameters.join(', ')})"
55
65
 
56
- "#{label} #{arg_preview}\n" +
57
- source_location_line +
58
- "#{method_source}\n"
59
- rescue => e
60
- "#{label}#{label_padding} : " \
61
- "Error: \e[31m#{e.message}\n\e[0m" +
62
- (source_location_line || '')
63
- end
64
- end.join("\n")
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
@@ -1,3 +1,3 @@
1
1
  module Scryglass
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
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.1
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-14 00:00:00.000000000 Z
11
+ date: 2021-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler