yard-link_stdlib 0.1.3 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/VERSION +1 -1
- data/bin/make_map.rb +46 -2
- data/lib/yard/cli/link_stdlib.rb +22 -345
- data/lib/yard/cli/link_stdlib/add.rb +70 -0
- data/lib/yard/cli/link_stdlib/command_helper.rb +103 -0
- data/lib/yard/cli/link_stdlib/help.rb +72 -0
- data/lib/yard/cli/link_stdlib/list.rb +59 -0
- data/lib/yard/cli/link_stdlib/search.rb +156 -0
- data/lib/yard/cli/link_stdlib/url.rb +65 -0
- data/lib/yard/link_stdlib.rb +1 -1
- data/maps/ruby-2.3.0.json.gz +0 -0
- data/maps/ruby-2.4.0.json.gz +0 -0
- data/maps/ruby-2.5.0.json.gz +0 -0
- data/maps/ruby-2.6.0.json.gz +0 -0
- data/maps/ruby-2.7.0.json.gz +0 -0
- data/maps/ruby-3.0.0.json.gz +0 -0
- metadata +23 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f5e7356071edda1c5ce9bf616147e40f02069f92c35da1e33c450b502884718b
|
4
|
+
data.tar.gz: 29b1b6d8cd736cdfb76935e9ec94cd8645b956219d42bcd70954f69edab47658
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae3626b5e848ce86406ac0c75f85cc4d417f58c73733e0ce4091e6ae943f086853736c511f7e77799a641a2e7ed6734f85a3f8f2e331fc91a40a3bb63561a075
|
7
|
+
data.tar.gz: 6510319602c33029c50afe71adca2fc80cd20ea55b1d70f5b52909626e179ed6c6d39917e44144af1de9c7b83b44f3007bb41458fb747cdd451725ab931bc2a1
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
data/bin/make_map.rb
CHANGED
@@ -90,6 +90,45 @@ class RDoc::RDoc
|
|
90
90
|
end # class RDoc::RDoc
|
91
91
|
|
92
92
|
|
93
|
+
def load_pry
|
94
|
+
require 'pry'
|
95
|
+
# In most project you probably *don't* want to load the RC file,
|
96
|
+
# as it may have dependencies
|
97
|
+
Pry.config.should_load_rc = false
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
# Add pre-defined global variables and constants, which are hand-documented in
|
102
|
+
# RUBY_SRC/doc/globals.rdoc
|
103
|
+
#
|
104
|
+
# and available on the site at
|
105
|
+
#
|
106
|
+
# https://docs.ruby-lang.org/en/<MAJOR.MINOR.0>/globals_rdoc.html
|
107
|
+
#
|
108
|
+
# like https://docs.ruby-lang.org/en/2.3.0/globals_rdoc.html
|
109
|
+
#
|
110
|
+
#
|
111
|
+
def add_globals_and_constants map
|
112
|
+
rdoc_path = './doc/globals.rdoc'
|
113
|
+
html_path = 'globals_rdoc.html'
|
114
|
+
|
115
|
+
unless File.file? rdoc_path
|
116
|
+
warn "Can't find globals and constants RDoc file at " +
|
117
|
+
"#{ File.expand_path rdoc_path }"
|
118
|
+
warn "Pre-defined global variables and constants will NOT be available" +
|
119
|
+
"in this map!"
|
120
|
+
return
|
121
|
+
end
|
122
|
+
|
123
|
+
contents = File.read rdoc_path
|
124
|
+
|
125
|
+
contents.scan /^(\S+)::\s/ do |(name)|
|
126
|
+
map[ name ] = html_path
|
127
|
+
# puts "Added #{ name.inspect } => #{ html_path }"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
|
93
132
|
def main args
|
94
133
|
src = Pathname.new( args.shift ).expand_path
|
95
134
|
dest = Pathname.new( args.shift ).expand_path
|
@@ -112,8 +151,12 @@ def main args
|
|
112
151
|
rd.almost_document args
|
113
152
|
|
114
153
|
map = {}
|
115
|
-
|
154
|
+
|
155
|
+
add_globals_and_constants map
|
156
|
+
|
157
|
+
# Add all classes and modules
|
116
158
|
rd.store.all_classes_and_modules.each do |mod|
|
159
|
+
# Example of how to stop and inspect a particular module when debugging
|
117
160
|
# if mod.full_name == 'Gem::Specification'
|
118
161
|
# require 'pry'
|
119
162
|
# Pry.config.should_load_rc = false
|
@@ -126,9 +169,10 @@ def main args
|
|
126
169
|
mod.class_attributes,
|
127
170
|
mod.class_method_list,
|
128
171
|
mod.instance_attributes,
|
129
|
-
mod.
|
172
|
+
mod.instance_methods,
|
130
173
|
].flatten.each { |entry|
|
131
174
|
map[ entry.full_name ] = entry.path
|
175
|
+
# puts "Added #{ entry.full_name.inspect } => #{ entry.path }"
|
132
176
|
}
|
133
177
|
|
134
178
|
end
|
data/lib/yard/cli/link_stdlib.rb
CHANGED
@@ -15,7 +15,12 @@ require 'yard'
|
|
15
15
|
|
16
16
|
### Project / Package ###
|
17
17
|
|
18
|
-
|
18
|
+
#### Sub-Commands ####
|
19
|
+
require_relative './link_stdlib/add'
|
20
|
+
require_relative './link_stdlib/help'
|
21
|
+
require_relative './link_stdlib/list'
|
22
|
+
require_relative './link_stdlib/search'
|
23
|
+
require_relative './link_stdlib/url'
|
19
24
|
|
20
25
|
|
21
26
|
# Namespace
|
@@ -28,357 +33,29 @@ module CLI
|
|
28
33
|
# Definitions
|
29
34
|
# =======================================================================
|
30
35
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def parse! *args
|
42
|
-
super( *args ).tap { after_parse_block.each &:call }
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
module CommandHelper
|
48
|
-
|
49
|
-
def description
|
50
|
-
self.class::DESCRIPTION
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
def usage
|
55
|
-
self.class::USAGE
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
def check_args! args, count
|
60
|
-
if args.length < count
|
61
|
-
log.error "Too few args! Expected #{ count }, given #{ args.length }"
|
62
|
-
exit false
|
63
|
-
elsif args.length > count
|
64
|
-
log.error "Too many args! Expected #{ count }, given #{ args.length }"
|
65
|
-
exit false
|
66
|
-
end
|
67
|
-
|
68
|
-
if args.length == 1 then args[ 0 ] else args end
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
def opts
|
73
|
-
@opts ||= {}
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
def add_header op, text = nil
|
78
|
-
op.banner = description
|
79
|
-
op.separator ''
|
80
|
-
op.separator 'Usage:'
|
81
|
-
op.separator ''
|
82
|
-
op.separator " #{ usage }"
|
83
|
-
op.separator ''
|
84
|
-
unless text.nil?
|
85
|
-
text.lines.each { |line| op.separator line }
|
86
|
-
end
|
87
|
-
op.separator ''
|
88
|
-
op.separator 'Options:'
|
89
|
-
|
90
|
-
op.on_tail( '-q', '--quiet', 'Show no warnings.' ) {
|
91
|
-
log.level = Logger::ERROR
|
92
|
-
}
|
93
|
-
|
94
|
-
op.on_tail( '--verbose', 'Show more information.') {
|
95
|
-
log.level = Logger::INFO
|
96
|
-
}
|
97
|
-
|
98
|
-
op.on_tail( '--debug', 'Show debugging information.' ) {
|
99
|
-
log.level = Logger::DEBUG
|
100
|
-
}
|
101
|
-
|
102
|
-
op.on_tail( '--backtrace', 'Show stack traces' ) {
|
103
|
-
log.show_backtraces = true
|
104
|
-
}
|
105
|
-
|
106
|
-
op.on_tail( '-h', '--help', %(You're looking at it!) ) {
|
107
|
-
log.puts op
|
108
|
-
exit true
|
109
|
-
}
|
110
|
-
end
|
111
|
-
|
112
|
-
def add_version_opt op
|
113
|
-
# **DON'T** make missing versions by default here!
|
114
|
-
YARD::LinkStdlib::RubySource.make_missing = false
|
115
|
-
|
116
|
-
op.on(
|
117
|
-
'-v VERSION',
|
118
|
-
'--ruby-version=VERSION',
|
119
|
-
%(Set Ruby version)
|
120
|
-
) { |ruby_version|
|
121
|
-
YARD::LinkStdlib::RubyVersion.set ruby_version
|
122
|
-
# opts[ :ruby_version ] = ruby_version
|
123
|
-
}
|
124
|
-
|
125
|
-
op.on(
|
126
|
-
'--make-missing',
|
127
|
-
%(Download and make an object map if the Ruby version is not present)
|
128
|
-
) { |make_missing|
|
129
|
-
YARD::LinkStdlib::RubySource.make_missing = make_missing
|
130
|
-
# opts[ :make_missing ] = make_missing
|
131
|
-
}
|
132
|
-
end
|
133
|
-
|
134
|
-
end # CommandHelper
|
135
|
-
|
136
|
-
|
137
|
-
# @todo document LinkStdlib class.
|
36
|
+
# Top-level {YARD::CLI::Command} for the `yard-link_stdlib` plugin. Added under
|
37
|
+
# the name `stdlib` (see {YARD::LinkStdlib.install!}).
|
38
|
+
#
|
39
|
+
# Simply a router to the sub-commands. Like {YARD::CLI::CommandParser}, which
|
40
|
+
# handles routing for `yard`, but is not really re-usable. In addition, this
|
41
|
+
# class handles "-" → "_" conversion in sub-command names, since we have
|
42
|
+
# multi-word commands.
|
43
|
+
#
|
138
44
|
class LinkStdlib < Command
|
139
|
-
|
140
|
-
# Sub-commands
|
141
|
-
# ============================================================================
|
142
|
-
|
143
|
-
class List < Command
|
144
|
-
include CommandHelper
|
145
|
-
|
146
|
-
DESCRIPTION = "List Ruby versions"
|
147
|
-
USAGE = "yard stdlib list"
|
148
|
-
|
149
|
-
def run *args
|
150
|
-
|
151
|
-
|
152
|
-
log.puts \
|
153
|
-
YARD::LinkStdlib::ObjectMap.
|
154
|
-
all.
|
155
|
-
map { |om| om.version.to_s }.
|
156
|
-
join( "\n" )
|
157
|
-
end
|
158
|
-
end # class List
|
159
|
-
|
160
|
-
|
161
|
-
class Add < Command
|
162
|
-
|
163
|
-
include CommandHelper
|
164
|
-
|
165
|
-
DESCRIPTION = "Download version source and build object map"
|
166
|
-
USAGE = "yard stdlib add [OPTIONS] RUBY_VERSION"
|
167
|
-
|
168
|
-
def run *args
|
169
|
-
# Want to see what's going on by default here...
|
170
|
-
log.level = Logger::INFO
|
171
|
-
|
172
|
-
opts[ :force ] = false
|
173
|
-
|
174
|
-
OptionParser.new { |op|
|
175
|
-
add_header op
|
176
|
-
|
177
|
-
op.on( '-f', '--force',
|
178
|
-
%(Force building of map data when already present)
|
179
|
-
) { |force| opts[ :force ] = force }
|
180
|
-
|
181
|
-
}.parse! args
|
182
|
-
|
183
|
-
args.each do |version|
|
184
|
-
log.info "Adding object map for Ruby #{ version }..."
|
185
|
-
YARD::LinkStdlib::ObjectMap.add version, force: opts[ :force ]
|
186
|
-
end
|
187
|
-
|
188
|
-
exit true
|
189
|
-
end
|
190
|
-
|
191
|
-
end # class Add
|
192
|
-
|
193
|
-
|
194
|
-
class URL < Command
|
195
|
-
|
196
|
-
include CommandHelper
|
197
|
-
|
198
|
-
DESCRIPTION = "Print the online doc URL for a stdlib name"
|
199
|
-
USAGE = "yard stdlib url [OPTIONS] NAME"
|
200
|
-
|
201
|
-
def run *args
|
202
|
-
OptionParser.new { |op|
|
203
|
-
add_header op
|
204
|
-
add_version_opt op
|
205
|
-
}.parse! args
|
206
|
-
|
207
|
-
name = check_args! args, 1
|
208
|
-
|
209
|
-
url = YARD::LinkStdlib::ObjectMap.current.url_for name
|
210
|
-
|
211
|
-
if url.nil?
|
212
|
-
$stderr.puts "Name not found: #{ name.inspect }"
|
213
|
-
exit false
|
214
|
-
end
|
215
|
-
|
216
|
-
puts url
|
217
|
-
exit true
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
|
222
|
-
# Hooks into {YARD::LinkStdlib::ObjectMap#grep} to search for names using
|
223
|
-
# regular expressions.
|
224
|
-
#
|
225
|
-
class Search < Command
|
226
|
-
|
227
|
-
include CommandHelper
|
228
|
-
|
229
|
-
DESCRIPTION = "Find stdlib names that match Regexp patterns"
|
230
|
-
USAGE = "yard stdlib search [OPTIONS] TERMS..."
|
231
|
-
|
232
|
-
def run *args
|
233
|
-
# Default format is `:plain`
|
234
|
-
opts[ :format ] = :plain
|
235
|
-
|
236
|
-
OptionParser.new { |op|
|
237
|
-
add_header op, <<~END
|
238
|
-
Examples:
|
239
|
-
|
240
|
-
1. {Pathname} instance methods
|
241
|
-
|
242
|
-
$ yard stdlib search '^Pathname#'
|
243
|
-
|
244
|
-
2. All `#to_s` methods
|
245
|
-
|
246
|
-
$ yard stdlib search '#to_s$'
|
247
|
-
|
248
|
-
3. Print results in serialized formats.
|
249
|
-
|
250
|
-
All `#to_s` instance methods in JSON:
|
251
|
-
|
252
|
-
$ yard stdlib search --format=json '#to_s$'
|
253
|
-
|
254
|
-
Supports a short `-f` flag and first-letter formats too.
|
255
|
-
|
256
|
-
Instance methods of {Array} in YAML:
|
257
|
-
|
258
|
-
$ yard stdlib search -f y '^Array#'
|
259
|
-
END
|
260
|
-
|
261
|
-
add_version_opt op
|
262
|
-
|
263
|
-
op.on( '-u', '--urls',
|
264
|
-
%(Print doc URLs along with names)
|
265
|
-
) { |urls| opts[ :urls ] = !!urls }
|
266
|
-
|
267
|
-
op.on( '-f FORMAT', '--format=FORMAT',
|
268
|
-
%(Specify print format: (p)lain, (j)son or (y)aml)
|
269
|
-
) { |format|
|
270
|
-
opts[ :format ] = \
|
271
|
-
case format.downcase
|
272
|
-
when 'p', 'plain'
|
273
|
-
:plain
|
274
|
-
when 'j', 'json'
|
275
|
-
:json
|
276
|
-
when 'y', 'yaml'
|
277
|
-
:yaml
|
278
|
-
else
|
279
|
-
log.fatal \
|
280
|
-
%(Unknown format - expected "plain", "json" or "yaml"; ) +
|
281
|
-
%(given #{ format.inspect })
|
282
|
-
exit false
|
283
|
-
end
|
284
|
-
}
|
285
|
-
|
286
|
-
}.parse! args
|
287
|
-
|
288
|
-
if args.empty?
|
289
|
-
YARD::LinkStdlib::ObjectMap.
|
290
|
-
current.
|
291
|
-
names.
|
292
|
-
sort_by( &:downcase ).
|
293
|
-
each { |key| log.puts key }
|
294
|
-
exit true
|
295
|
-
end
|
296
|
-
|
297
|
-
terms = args.map { |arg|
|
298
|
-
begin
|
299
|
-
Regexp.new arg
|
300
|
-
rescue RegexpError => error
|
301
|
-
Regexp.new \
|
302
|
-
Regexp.escape( YARD::LinkStdlib.normalize_name( arg ) )
|
303
|
-
end
|
304
|
-
}
|
305
|
-
|
306
|
-
log.debug "Terms:\n " + terms.map( &:to_s ).join( "\n " )
|
307
|
-
|
308
|
-
names = YARD::LinkStdlib.grep *terms
|
309
|
-
|
310
|
-
results = \
|
311
|
-
if opts[ :urls ]
|
312
|
-
names.each_with_object( {} ) { |name, hash|
|
313
|
-
hash[ name ] = YARD::LinkStdlib::ObjectMap.current.url_for name
|
314
|
-
}
|
315
|
-
else
|
316
|
-
names
|
317
|
-
end
|
318
|
-
|
319
|
-
case opts[ :format ]
|
320
|
-
when :plain
|
321
|
-
results.each do |entry|
|
322
|
-
if entry.is_a? ::Array
|
323
|
-
log.puts "#{ entry[0] } <#{ entry[ 1 ]}>"
|
324
|
-
else
|
325
|
-
log.puts entry
|
326
|
-
end
|
327
|
-
end
|
328
|
-
when :json
|
329
|
-
require 'json'
|
330
|
-
log.puts JSON.pretty_generate( results )
|
331
|
-
when :yaml
|
332
|
-
require 'yaml'
|
333
|
-
log.puts YAML.dump( results )
|
334
|
-
end
|
335
|
-
|
336
|
-
exit true
|
337
|
-
end
|
338
|
-
end # class Search
|
339
|
-
|
340
|
-
|
341
|
-
class Help < Command
|
342
|
-
|
343
|
-
include CommandHelper
|
344
|
-
|
345
|
-
DESCRIPTION = "Show this message"
|
346
|
-
|
347
|
-
def run
|
348
|
-
commands = LinkStdlib.commands
|
349
|
-
log.puts <<~END
|
350
|
-
yard-link_stdlib provides linking to online Ruby docs for standard
|
351
|
-
library code objects.
|
352
|
-
|
353
|
-
Usage:
|
354
|
-
|
355
|
-
yard stdlib COMMAND... [OPTIONS] [ARGS]
|
356
|
-
|
357
|
-
Commands:
|
358
|
-
|
359
|
-
END
|
360
|
-
commands.keys.sort_by(&:to_s).each do |command_name|
|
361
|
-
command_class = commands[command_name]
|
362
|
-
next unless command_class < Command
|
363
|
-
command = command_class.new
|
364
|
-
log.puts "%-8s %s" % [command_name, command.description]
|
365
|
-
end
|
366
|
-
log.puts
|
367
|
-
end
|
368
|
-
end
|
369
45
|
|
46
|
+
@commands = SymbolHash[
|
47
|
+
help: Help,
|
48
|
+
list: List,
|
49
|
+
add: Add,
|
50
|
+
url: URL,
|
51
|
+
search: Search,
|
52
|
+
]
|
370
53
|
|
371
54
|
# Singleton Methods
|
372
55
|
# ==========================================================================
|
373
56
|
|
374
57
|
def self.commands
|
375
|
-
|
376
|
-
help: Help,
|
377
|
-
list: List,
|
378
|
-
add: Add,
|
379
|
-
url: URL,
|
380
|
-
search: Search,
|
381
|
-
}
|
58
|
+
@commands
|
382
59
|
end
|
383
60
|
|
384
61
|
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
### Stdlib ###
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
|
11
|
+
### Deps ###
|
12
|
+
|
13
|
+
# We need {YARD::CLI::Command}
|
14
|
+
require 'yard'
|
15
|
+
|
16
|
+
### Project / Package ###
|
17
|
+
|
18
|
+
require_relative './command_helper'
|
19
|
+
|
20
|
+
|
21
|
+
# Namespace
|
22
|
+
# =======================================================================
|
23
|
+
|
24
|
+
module YARD
|
25
|
+
module CLI
|
26
|
+
class LinkStdlib < Command
|
27
|
+
|
28
|
+
|
29
|
+
# Definitions
|
30
|
+
# =======================================================================
|
31
|
+
|
32
|
+
class Add < Command
|
33
|
+
|
34
|
+
include CommandHelper
|
35
|
+
|
36
|
+
DESCRIPTION = "Download version source and build object map"
|
37
|
+
USAGE = "yard stdlib add [OPTIONS] RUBY_VERSION"
|
38
|
+
|
39
|
+
def run *args
|
40
|
+
# Want to see what's going on by default here...
|
41
|
+
log.level = Logger::INFO
|
42
|
+
|
43
|
+
opts[ :force ] = false
|
44
|
+
|
45
|
+
OptionParser.new { |op|
|
46
|
+
add_header op
|
47
|
+
|
48
|
+
op.on( '-f', '--force',
|
49
|
+
%(Force building of map data when already present)
|
50
|
+
) { |force| opts[ :force ] = force }
|
51
|
+
|
52
|
+
}.parse! args
|
53
|
+
|
54
|
+
args.each do |version|
|
55
|
+
log.info "Adding object map for Ruby #{ version }..."
|
56
|
+
YARD::LinkStdlib::ObjectMap.add version, force: opts[ :force ]
|
57
|
+
end
|
58
|
+
|
59
|
+
exit true
|
60
|
+
end
|
61
|
+
|
62
|
+
end # class Add
|
63
|
+
|
64
|
+
|
65
|
+
# /Namespace
|
66
|
+
# =======================================================================
|
67
|
+
|
68
|
+
end # class LinkStdlib
|
69
|
+
end # module CLI
|
70
|
+
end # module YARD
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
### Deps ###
|
8
|
+
|
9
|
+
# We need {YARD::CLI::Command}
|
10
|
+
require 'yard'
|
11
|
+
|
12
|
+
### Project / Package ###
|
13
|
+
|
14
|
+
# `.make_missing`, `.set` from {YARD::LinkStdlib::RubySource}
|
15
|
+
require 'yard/link_stdlib/ruby_source'
|
16
|
+
|
17
|
+
|
18
|
+
# Namespace
|
19
|
+
# =======================================================================
|
20
|
+
|
21
|
+
module YARD
|
22
|
+
module CLI
|
23
|
+
class LinkStdlib < Command
|
24
|
+
|
25
|
+
|
26
|
+
# Definitions
|
27
|
+
# =======================================================================
|
28
|
+
|
29
|
+
module CommandHelper
|
30
|
+
|
31
|
+
def description
|
32
|
+
self.class::DESCRIPTION
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def usage
|
37
|
+
self.class::USAGE
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def check_args! args, count
|
42
|
+
if args.length < count
|
43
|
+
log.error "Too few args! Expected #{ count }, given #{ args.length }"
|
44
|
+
exit false
|
45
|
+
elsif args.length > count
|
46
|
+
log.error "Too many args! Expected #{ count }, given #{ args.length }"
|
47
|
+
exit false
|
48
|
+
end
|
49
|
+
|
50
|
+
if args.length == 1 then args[ 0 ] else args end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def opts
|
55
|
+
@opts ||= {}
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def add_header op, text = nil
|
60
|
+
op.banner = description
|
61
|
+
op.separator ''
|
62
|
+
op.separator 'Usage:'
|
63
|
+
op.separator ''
|
64
|
+
op.separator " #{ usage }"
|
65
|
+
op.separator ''
|
66
|
+
unless text.nil?
|
67
|
+
text.lines.each { |line| op.separator line }
|
68
|
+
end
|
69
|
+
|
70
|
+
# Call {YARD::CLI::Command#common_options}, which adds file loading, plugin
|
71
|
+
# loading, logging, YARD version and help options
|
72
|
+
common_options( op )
|
73
|
+
end
|
74
|
+
|
75
|
+
def add_version_opt op
|
76
|
+
# **DON'T** make missing versions by default here!
|
77
|
+
YARD::LinkStdlib::RubySource.make_missing = false
|
78
|
+
|
79
|
+
op.on(
|
80
|
+
'-R VERSION',
|
81
|
+
'--ruby-version=VERSION',
|
82
|
+
%(Set Ruby version)
|
83
|
+
) { |ruby_version|
|
84
|
+
YARD::LinkStdlib::RubyVersion.set ruby_version
|
85
|
+
}
|
86
|
+
|
87
|
+
op.on(
|
88
|
+
'--make-missing',
|
89
|
+
%(Download and make an object map if the Ruby version is not present)
|
90
|
+
) { |make_missing|
|
91
|
+
YARD::LinkStdlib::RubySource.make_missing = make_missing
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
end # CommandHelper
|
96
|
+
|
97
|
+
|
98
|
+
# /Namespace
|
99
|
+
# =======================================================================
|
100
|
+
|
101
|
+
end # class LinkStdlib
|
102
|
+
end # module CLI
|
103
|
+
end # module YARD
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
### Stdlib ###
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
|
11
|
+
### Deps ###
|
12
|
+
|
13
|
+
# We need {YARD::CLI::Command}
|
14
|
+
require 'yard'
|
15
|
+
|
16
|
+
### Project / Package ###
|
17
|
+
|
18
|
+
require_relative './command_helper'
|
19
|
+
|
20
|
+
|
21
|
+
# Namespace
|
22
|
+
# =======================================================================
|
23
|
+
|
24
|
+
module YARD
|
25
|
+
module CLI
|
26
|
+
class LinkStdlib < Command
|
27
|
+
|
28
|
+
|
29
|
+
# Definitions
|
30
|
+
# =======================================================================
|
31
|
+
|
32
|
+
class Help < Command
|
33
|
+
|
34
|
+
include CommandHelper
|
35
|
+
|
36
|
+
USAGE = "yard stdlib help [OTHER_OPTIONS]"
|
37
|
+
DESCRIPTION = "Show this message"
|
38
|
+
|
39
|
+
def run *args
|
40
|
+
OptionParser.new { |op|
|
41
|
+
add_header op
|
42
|
+
}.parse! args
|
43
|
+
|
44
|
+
commands = LinkStdlib.commands
|
45
|
+
log.puts <<~END
|
46
|
+
yard-link_stdlib provides linking to online Ruby docs for standard
|
47
|
+
library code objects.
|
48
|
+
|
49
|
+
Usage:
|
50
|
+
|
51
|
+
yard stdlib COMMAND... [OPTIONS] [ARGS]
|
52
|
+
|
53
|
+
Commands:
|
54
|
+
|
55
|
+
END
|
56
|
+
commands.keys.sort_by(&:to_s).each do |command_name|
|
57
|
+
command_class = commands[command_name]
|
58
|
+
next unless command_class < Command
|
59
|
+
command = command_class.new
|
60
|
+
log.puts "%-8s %s" % [command_name, command.description]
|
61
|
+
end
|
62
|
+
log.puts
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
# /Namespace
|
68
|
+
# =======================================================================
|
69
|
+
|
70
|
+
end # class LinkStdlib
|
71
|
+
end # module CLI
|
72
|
+
end # module YARD
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
### Stdlib ###
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
|
11
|
+
### Deps ###
|
12
|
+
|
13
|
+
# We need {YARD::CLI::Command}
|
14
|
+
require 'yard'
|
15
|
+
|
16
|
+
### Project / Package ###
|
17
|
+
|
18
|
+
require_relative './command_helper'
|
19
|
+
|
20
|
+
|
21
|
+
# Namespace
|
22
|
+
# =======================================================================
|
23
|
+
|
24
|
+
module YARD
|
25
|
+
module CLI
|
26
|
+
class LinkStdlib < Command
|
27
|
+
|
28
|
+
|
29
|
+
# Definitions
|
30
|
+
# =======================================================================
|
31
|
+
|
32
|
+
class List < Command
|
33
|
+
include CommandHelper
|
34
|
+
|
35
|
+
DESCRIPTION = "List Ruby versions"
|
36
|
+
USAGE = "yard stdlib list"
|
37
|
+
|
38
|
+
def run *args
|
39
|
+
OptionParser.new { |op|
|
40
|
+
add_header op
|
41
|
+
}.parse! args
|
42
|
+
|
43
|
+
check_args! args, 0
|
44
|
+
|
45
|
+
log.puts \
|
46
|
+
YARD::LinkStdlib::ObjectMap.
|
47
|
+
all.
|
48
|
+
map { |om| om.version.to_s }.
|
49
|
+
join( "\n" )
|
50
|
+
end
|
51
|
+
end # class List
|
52
|
+
|
53
|
+
|
54
|
+
# /Namespace
|
55
|
+
# =======================================================================
|
56
|
+
|
57
|
+
end # class LinkStdlib
|
58
|
+
end # module CLI
|
59
|
+
end # module YARD
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
### Stdlib ###
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
|
11
|
+
### Deps ###
|
12
|
+
|
13
|
+
# We need {YARD::CLI::Command}
|
14
|
+
require 'yard'
|
15
|
+
|
16
|
+
### Project / Package ###
|
17
|
+
|
18
|
+
require_relative './command_helper'
|
19
|
+
|
20
|
+
|
21
|
+
# Namespace
|
22
|
+
# =======================================================================
|
23
|
+
|
24
|
+
module YARD
|
25
|
+
module CLI
|
26
|
+
class LinkStdlib < Command
|
27
|
+
|
28
|
+
|
29
|
+
# Definitions
|
30
|
+
# =======================================================================
|
31
|
+
|
32
|
+
# Hooks into {YARD::LinkStdlib::ObjectMap#grep} to search for names using
|
33
|
+
# regular expressions.
|
34
|
+
#
|
35
|
+
class Search < Command
|
36
|
+
|
37
|
+
include CommandHelper
|
38
|
+
|
39
|
+
DESCRIPTION = "Find stdlib names that match Regexp patterns"
|
40
|
+
USAGE = "yard stdlib search [OPTIONS] TERMS..."
|
41
|
+
|
42
|
+
def run *args
|
43
|
+
# Default format is `:plain`
|
44
|
+
opts[ :format ] = :plain
|
45
|
+
|
46
|
+
OptionParser.new { |op|
|
47
|
+
add_header op, <<~END
|
48
|
+
Examples:
|
49
|
+
|
50
|
+
1. {Pathname} instance methods
|
51
|
+
|
52
|
+
$ yard stdlib search '^Pathname#'
|
53
|
+
|
54
|
+
2. All `#to_s` methods
|
55
|
+
|
56
|
+
$ yard stdlib search '#to_s$'
|
57
|
+
|
58
|
+
3. Print results in serialized formats.
|
59
|
+
|
60
|
+
All `#to_s` instance methods in JSON:
|
61
|
+
|
62
|
+
$ yard stdlib search --format=json '#to_s$'
|
63
|
+
|
64
|
+
Supports a short `-f` flag and first-letter formats too.
|
65
|
+
|
66
|
+
Instance methods of {Array} in YAML:
|
67
|
+
|
68
|
+
$ yard stdlib search -f y '^Array#'
|
69
|
+
END
|
70
|
+
|
71
|
+
add_version_opt op
|
72
|
+
|
73
|
+
op.on( '-u', '--urls',
|
74
|
+
%(Print doc URLs along with names)
|
75
|
+
) { |urls| opts[ :urls ] = !!urls }
|
76
|
+
|
77
|
+
op.on( '-f FORMAT', '--format=FORMAT',
|
78
|
+
%(Specify print format: (p)lain, (j)son or (y)aml)
|
79
|
+
) { |format|
|
80
|
+
opts[ :format ] = \
|
81
|
+
case format.downcase
|
82
|
+
when 'p', 'plain'
|
83
|
+
:plain
|
84
|
+
when 'j', 'json'
|
85
|
+
:json
|
86
|
+
when 'y', 'yaml'
|
87
|
+
:yaml
|
88
|
+
else
|
89
|
+
log.fatal \
|
90
|
+
%(Unknown format - expected "plain", "json" or "yaml"; ) +
|
91
|
+
%(given #{ format.inspect })
|
92
|
+
exit false
|
93
|
+
end
|
94
|
+
}
|
95
|
+
|
96
|
+
}.parse! args
|
97
|
+
|
98
|
+
if args.empty?
|
99
|
+
YARD::LinkStdlib::ObjectMap.
|
100
|
+
current.
|
101
|
+
names.
|
102
|
+
sort_by( &:downcase ).
|
103
|
+
each { |key| log.puts key }
|
104
|
+
exit true
|
105
|
+
end
|
106
|
+
|
107
|
+
terms = args.map { |arg|
|
108
|
+
begin
|
109
|
+
Regexp.new arg
|
110
|
+
rescue RegexpError => error
|
111
|
+
Regexp.new \
|
112
|
+
Regexp.escape( YARD::LinkStdlib.normalize_name( arg ) )
|
113
|
+
end
|
114
|
+
}
|
115
|
+
|
116
|
+
log.debug "Terms:\n " + terms.map( &:to_s ).join( "\n " )
|
117
|
+
|
118
|
+
names = YARD::LinkStdlib.grep *terms
|
119
|
+
|
120
|
+
results = \
|
121
|
+
if opts[ :urls ]
|
122
|
+
names.each_with_object( {} ) { |name, hash|
|
123
|
+
hash[ name ] = YARD::LinkStdlib::ObjectMap.current.url_for name
|
124
|
+
}
|
125
|
+
else
|
126
|
+
names
|
127
|
+
end
|
128
|
+
|
129
|
+
case opts[ :format ]
|
130
|
+
when :plain
|
131
|
+
results.each do |entry|
|
132
|
+
if entry.is_a? ::Array
|
133
|
+
log.puts "#{ entry[0] } <#{ entry[ 1 ]}>"
|
134
|
+
else
|
135
|
+
log.puts entry
|
136
|
+
end
|
137
|
+
end
|
138
|
+
when :json
|
139
|
+
require 'json'
|
140
|
+
log.puts JSON.pretty_generate( results )
|
141
|
+
when :yaml
|
142
|
+
require 'yaml'
|
143
|
+
log.puts YAML.dump( results )
|
144
|
+
end
|
145
|
+
|
146
|
+
exit true
|
147
|
+
end
|
148
|
+
end # class Search
|
149
|
+
|
150
|
+
|
151
|
+
# /Namespace
|
152
|
+
# =======================================================================
|
153
|
+
|
154
|
+
end # class LinkStdlib
|
155
|
+
end # module CLI
|
156
|
+
end # module YARD
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
### Stdlib ###
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
|
11
|
+
### Deps ###
|
12
|
+
|
13
|
+
# We need {YARD::CLI::Command}
|
14
|
+
require 'yard'
|
15
|
+
|
16
|
+
### Project / Package ###
|
17
|
+
|
18
|
+
require_relative './command_helper'
|
19
|
+
|
20
|
+
|
21
|
+
# Namespace
|
22
|
+
# =======================================================================
|
23
|
+
|
24
|
+
module YARD
|
25
|
+
module CLI
|
26
|
+
class LinkStdlib < Command
|
27
|
+
|
28
|
+
|
29
|
+
# Definitions
|
30
|
+
# =======================================================================
|
31
|
+
|
32
|
+
class URL < Command
|
33
|
+
|
34
|
+
include CommandHelper
|
35
|
+
|
36
|
+
DESCRIPTION = "Print the online doc URL for a stdlib name"
|
37
|
+
USAGE = "yard stdlib url [OPTIONS] NAME"
|
38
|
+
|
39
|
+
def run *args
|
40
|
+
OptionParser.new { |op|
|
41
|
+
add_header op
|
42
|
+
add_version_opt op
|
43
|
+
}.parse! args
|
44
|
+
|
45
|
+
name = check_args! args, 1
|
46
|
+
|
47
|
+
url = YARD::LinkStdlib::ObjectMap.current.url_for name
|
48
|
+
|
49
|
+
if url.nil?
|
50
|
+
$stderr.puts "Name not found: #{ name.inspect }"
|
51
|
+
exit false
|
52
|
+
end
|
53
|
+
|
54
|
+
puts url
|
55
|
+
exit true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
# /Namespace
|
61
|
+
# =======================================================================
|
62
|
+
|
63
|
+
end # class LinkStdlib
|
64
|
+
end # module CLI
|
65
|
+
end # module YARD
|
data/lib/yard/link_stdlib.rb
CHANGED
@@ -290,7 +290,7 @@ module LinkStdlib
|
|
290
290
|
#
|
291
291
|
# @example Puke if it's not a {String}
|
292
292
|
# YARD::LinkStdlib.normalize_name 123
|
293
|
-
# #=> raise TypeError, %(`name` must be a String, given
|
293
|
+
# #=> raise TypeError, %(`name` must be a String, given Integer: 123)
|
294
294
|
#
|
295
295
|
# @example Handle operator singleton methods separated by '.'
|
296
296
|
# YARD::LinkStdlib.normalize_name 'Dir.[]'
|
data/maps/ruby-2.3.0.json.gz
CHANGED
Binary file
|
data/maps/ruby-2.4.0.json.gz
CHANGED
Binary file
|
data/maps/ruby-2.5.0.json.gz
CHANGED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yard-link_stdlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nrser
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
@@ -44,70 +44,56 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.7'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '3.7'
|
54
|
+
version: '13.0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: pry
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
61
|
+
version: 0.14.0
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
68
|
+
version: 0.14.0
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: pry-rescue
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: 1.
|
75
|
+
version: 1.5.2
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: 1.
|
82
|
+
version: 1.5.2
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: pry-stack_explorer
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
89
|
+
version: 0.6.1
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
94
|
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
96
|
+
version: 0.6.1
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: yard-commonmarker
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,6 +153,12 @@ files:
|
|
167
153
|
- bin/make_map.rb
|
168
154
|
- lib/yard-link_stdlib.rb
|
169
155
|
- lib/yard/cli/link_stdlib.rb
|
156
|
+
- lib/yard/cli/link_stdlib/add.rb
|
157
|
+
- lib/yard/cli/link_stdlib/command_helper.rb
|
158
|
+
- lib/yard/cli/link_stdlib/help.rb
|
159
|
+
- lib/yard/cli/link_stdlib/list.rb
|
160
|
+
- lib/yard/cli/link_stdlib/search.rb
|
161
|
+
- lib/yard/cli/link_stdlib/url.rb
|
170
162
|
- lib/yard/link_stdlib.rb
|
171
163
|
- lib/yard/link_stdlib/html_helper.rb
|
172
164
|
- lib/yard/link_stdlib/object_map.rb
|
@@ -176,11 +168,14 @@ files:
|
|
176
168
|
- maps/ruby-2.3.0.json.gz
|
177
169
|
- maps/ruby-2.4.0.json.gz
|
178
170
|
- maps/ruby-2.5.0.json.gz
|
171
|
+
- maps/ruby-2.6.0.json.gz
|
172
|
+
- maps/ruby-2.7.0.json.gz
|
173
|
+
- maps/ruby-3.0.0.json.gz
|
179
174
|
homepage: https://github.com/nrser/yard-link_stdlib
|
180
175
|
licenses:
|
181
176
|
- BSD
|
182
177
|
metadata: {}
|
183
|
-
post_install_message:
|
178
|
+
post_install_message:
|
184
179
|
rdoc_options: []
|
185
180
|
require_paths:
|
186
181
|
- lib
|
@@ -195,9 +190,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
190
|
- !ruby/object:Gem::Version
|
196
191
|
version: '0'
|
197
192
|
requirements: []
|
198
|
-
|
199
|
-
|
200
|
-
signing_key:
|
193
|
+
rubygems_version: 3.2.3
|
194
|
+
signing_key:
|
201
195
|
specification_version: 4
|
202
196
|
summary: A YARD plugin & patch to link Ruby stdlib references.
|
203
197
|
test_files: []
|