check_everything 0.3.1 → 0.3.3
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 +4 -4
- data/README.md +5 -3
- data/lib/check_everything.rb +196 -136
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d5e756b99eed4f3831d529030106fc413e7cef22
|
|
4
|
+
data.tar.gz: 46794552d76c567c334bda168e5b1d7bd8063a23
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6f161be0d9ef1283f5602d8cd41f5fd79a4d8eaf3c54fa95c7e847be15f469a2811ae43abc0f1fe8cf14f8768f5c669f083015667e73181c9af8b974d0d03749
|
|
7
|
+
data.tar.gz: c0b6444386aab67e1ac4f8579ba0a2e73e92ef4de9f9b177a08f4ff85298f9c2c6a05592da26c67ebe6377d0567d9bf1a50015727ab3dc367273f55e60dfd0c7
|
data/README.md
CHANGED
|
@@ -26,12 +26,14 @@ will be evaluated):
|
|
|
26
26
|
| <category> | open a specific site group |
|
|
27
27
|
| <Ruby class> | open Ruby documentation (if feature is installed) |
|
|
28
28
|
|
|
29
|
-
NOTE: in versions 0.3.
|
|
30
|
-
|
|
29
|
+
NOTE: in versions 0.3.2 and higher, you can check Ruby documentation in one of three ways:
|
|
30
|
+
|
|
31
31
|
----
|
|
32
32
|
1. `check_everything array` (for the [class](http://www.ruby-doc.org/core-2.1.0/Array.html))
|
|
33
33
|
2. `check_everything array#slice` (for the
|
|
34
|
-
[method](http://www.ruby-doc.org/core-2.1.0/Array.html#method-i-slice))
|
|
34
|
+
[instance method](http://www.ruby-doc.org/core-2.1.0/Array.html#method-i-slice))
|
|
35
|
+
3. `check_everything array::new` (for the [class method](http://www.ruby-doc.org/core-2.1.0/Array.html#method-c-new))
|
|
36
|
+
|
|
35
37
|
----
|
|
36
38
|
|
|
37
39
|
### Configure
|
data/lib/check_everything.rb
CHANGED
|
@@ -2,12 +2,32 @@ require 'open-uri'
|
|
|
2
2
|
require 'nokogiri'
|
|
3
3
|
|
|
4
4
|
class CheckEverything
|
|
5
|
-
|
|
6
|
-
:help =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
KNOWN_FLAGS = {
|
|
6
|
+
:help => {
|
|
7
|
+
:position => 1,
|
|
8
|
+
:flags => ['-h','--help'],
|
|
9
|
+
:description => 'display the help message'
|
|
10
|
+
},
|
|
11
|
+
:links => {
|
|
12
|
+
:position => 2,
|
|
13
|
+
:flags => ['-l','--links'],
|
|
14
|
+
:description => 'view/edit links and categories'
|
|
15
|
+
},
|
|
16
|
+
:ruby => {
|
|
17
|
+
:position => 3,
|
|
18
|
+
:flags => ['-r','--ruby'],
|
|
19
|
+
:description => 'install/update Ruby Documentation functionality'
|
|
20
|
+
},
|
|
21
|
+
:categories => {
|
|
22
|
+
:position => 4,
|
|
23
|
+
:flags => ['-c', '--categories'],
|
|
24
|
+
:description => 'view the currently defined categories'
|
|
25
|
+
},
|
|
26
|
+
:all => {
|
|
27
|
+
:position => 5,
|
|
28
|
+
:flags => ['-a', '--all'],
|
|
29
|
+
:description => 'open all websites (will override documentation lookup)'
|
|
30
|
+
}
|
|
11
31
|
}
|
|
12
32
|
LINKPATH = "#{File.expand_path('~')}/.check_everything_links"
|
|
13
33
|
LINKFILE = "#{LINKPATH}/links.txt"
|
|
@@ -33,100 +53,108 @@ class CheckEverything
|
|
|
33
53
|
|
|
34
54
|
def self.run
|
|
35
55
|
@argv = ARGV.map(&:downcase)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
@ruby_dev_assemble = false
|
|
41
|
-
# Create a new link file if none has been created yet
|
|
42
|
-
if !File.exists?(LINKFILE)
|
|
43
|
-
# If a previous version created a file rather than a directory, move it into
|
|
44
|
-
# the new directory.
|
|
45
|
-
if File.exists?(LINKPATH)
|
|
46
|
-
system("mv #{LINKPATH} #{LINKPATH}2")
|
|
47
|
-
system("mkdir #{LINKPATH}")
|
|
48
|
-
system("mv #{LINKPATH}2 #{LINKFILE}")
|
|
49
|
-
else
|
|
50
|
-
system("mkdir #{LINKPATH}")
|
|
51
|
-
system("cp #{File.dirname(__FILE__)}/check_everything/links.txt #{LINKFILE}")
|
|
52
|
-
end
|
|
53
|
-
@argv = ["-l"]
|
|
54
|
-
print "Are you a Ruby Dev who will want documentation-checking ",
|
|
55
|
-
"functionality? [Y/n] "
|
|
56
|
-
@ruby_dev_assemble = true unless gets.strip.downcase == 'n'
|
|
57
|
-
puts "\nPlease customize your installation.",
|
|
58
|
-
"This message will only be shown once.",
|
|
59
|
-
"To open again and customize, just enter 'check_everything -l' to open",
|
|
60
|
-
"the link file."
|
|
61
|
-
end
|
|
62
|
-
# Assume no problems with the link file.
|
|
63
|
-
@category_space, @category_dash = false, false
|
|
56
|
+
ARGV.clear # prevent ARGV from interfering with "gets" input.
|
|
57
|
+
|
|
58
|
+
# Run first-time options if check_everything hasn't been run yet.
|
|
59
|
+
customize_installation if !File.exists?(LINKFILE)
|
|
64
60
|
|
|
65
61
|
extract_links
|
|
66
62
|
|
|
67
63
|
# First check for unknown arguments and print out a helpful message.
|
|
68
|
-
|
|
69
|
-
unmatched_args = @argv.select do |arg|
|
|
70
|
-
!known_tags.any? do |known_tag|
|
|
71
|
-
known_tag.downcase == arg.split("#")[0]
|
|
72
|
-
end
|
|
73
|
-
end
|
|
64
|
+
unmatched_args = unknown_arguments
|
|
74
65
|
if !unmatched_args.empty?
|
|
75
|
-
|
|
76
|
-
"#{unmatched_args.join(" ")}"
|
|
77
|
-
print "usage: check_everything"
|
|
78
|
-
KNOWN_TAGS.values.flatten.each {|tag| print " [#{tag}]"}
|
|
79
|
-
puts "\n\nHint: Enter 'check_everything --help' to see the options!"
|
|
80
|
-
puts "\n"
|
|
66
|
+
puts_unmatched_error_message(unmatched_args)
|
|
81
67
|
|
|
82
|
-
#
|
|
83
|
-
elsif
|
|
68
|
+
# Respond to flags.
|
|
69
|
+
elsif argv_requests?(:help)
|
|
84
70
|
help
|
|
85
|
-
|
|
86
|
-
# Edit the tags and links.
|
|
87
|
-
elsif @argv.any? {|arg| KNOWN_TAGS[:links].include?(arg)}
|
|
88
|
-
# If asked to build the Ruby Dev file, build it!
|
|
89
|
-
assemble_ruby_docs_file if @ruby_dev_assemble
|
|
90
|
-
|
|
71
|
+
elsif argv_requests?(:links)
|
|
91
72
|
system("open #{LINKFILE}")
|
|
92
|
-
|
|
93
|
-
elsif @argv.any? {|arg| KNOWN_TAGS[:ruby].include?(arg)}
|
|
73
|
+
elsif argv_requests?(:ruby)
|
|
94
74
|
assemble_ruby_docs_file
|
|
95
|
-
|
|
96
|
-
# Check for errors; don't allow the user to see bad categories or open up
|
|
97
|
-
# websites if the categories are not formatted properly.
|
|
98
|
-
elsif @category_space
|
|
99
|
-
puts "Your link file includes a category with a space in it; " +
|
|
100
|
-
"please fix by entering 'check_everything -l' into your command line."
|
|
101
|
-
elsif @category_dash
|
|
102
|
-
puts "Your link file includes a category with a dash, which is " +
|
|
103
|
-
"not allowed; please fix by entering 'check_everything -l' into your command line."
|
|
104
|
-
|
|
105
|
-
# View the categories the user has defined.
|
|
106
|
-
elsif @argv.any? {|arg| KNOWN_TAGS[:categories].include?(arg)}
|
|
107
|
-
view_categories
|
|
108
75
|
|
|
109
|
-
#
|
|
76
|
+
# Block execution of final options if an invalid character exists
|
|
77
|
+
# in the user's link file.
|
|
78
|
+
elsif @invalid_char_in_links
|
|
79
|
+
puts "Your link file includes a category with a " +
|
|
80
|
+
"\"#{@invalid_char_in_links}\" character in it; please fix by " +
|
|
81
|
+
"entering 'check_everything -l' into your command line."
|
|
82
|
+
elsif argv_requests?(:categories)
|
|
83
|
+
view_categories
|
|
84
|
+
# If there are no flags, open the websites!
|
|
110
85
|
else
|
|
111
86
|
open_links
|
|
112
87
|
end
|
|
113
88
|
end
|
|
114
89
|
|
|
115
90
|
private
|
|
91
|
+
|
|
92
|
+
def self.known_flags
|
|
93
|
+
KNOWN_FLAGS.values.map{|command| command[:flags]}.flatten
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def self.customize_installation
|
|
97
|
+
# If a previous version created a file rather than a directory, move it into
|
|
98
|
+
# the new directory.
|
|
99
|
+
if File.exists?(LINKPATH)
|
|
100
|
+
system("mv #{LINKPATH} #{LINKPATH}99999999")
|
|
101
|
+
system("mkdir #{LINKPATH}")
|
|
102
|
+
system("mv #{LINKPATH}99999999 #{LINKFILE}")
|
|
103
|
+
else
|
|
104
|
+
system("mkdir #{LINKPATH}")
|
|
105
|
+
system("cp #{File.dirname(__FILE__)}/check_everything/links.txt #{LINKFILE}")
|
|
106
|
+
|
|
107
|
+
# On first run, prompt to customize the installation.
|
|
108
|
+
@argv = ["-l"]
|
|
109
|
+
print "Greetings, new user! You're almost ready to use check_everything! "
|
|
110
|
+
print "Are you a Ruby Dev who will want documentation-checking ",
|
|
111
|
+
"functionality? [Y/n] "
|
|
112
|
+
assemble_ruby_docs_file unless gets.strip.downcase == 'n'
|
|
113
|
+
puts "\nPlease customize your installation.",
|
|
114
|
+
"This message will only be shown once.",
|
|
115
|
+
"To open again and customize, just enter 'check_everything -l' to open",
|
|
116
|
+
"the link file."
|
|
117
|
+
puts "You may now use check_everything normally."
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def self.unknown_arguments
|
|
122
|
+
all_known_flags = known_flags + @links.keys + @ruby_links
|
|
123
|
+
@argv.select do |arg|
|
|
124
|
+
all_known_flags.none? do |known_flag|
|
|
125
|
+
known_flag.downcase == arg.split(/#|::/)[0]
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def self.puts_unmatched_error_message(unmatched_args)
|
|
131
|
+
puts "\nUnknown option#{@argv.size > 1 ? "s" : nil}: " +
|
|
132
|
+
"#{unmatched_args.join(" ")}"
|
|
133
|
+
print "usage: check_everything"
|
|
134
|
+
known_flags.each {|flag| print " [#{flag}]"}
|
|
135
|
+
puts "\n\nHint: Enter 'check_everything --help' to see the options!"
|
|
136
|
+
puts "\n"
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def self.argv_requests?(command)
|
|
140
|
+
@argv.any? {|arg| KNOWN_FLAGS[command][:flags].include?(arg)}
|
|
141
|
+
end
|
|
142
|
+
|
|
116
143
|
def self.help
|
|
117
|
-
puts "\n'check_everything' will open all sites labeled
|
|
144
|
+
puts "\n'check_everything' without flags will open all sites labeled " +
|
|
145
|
+
"with the 'default' category."
|
|
118
146
|
puts
|
|
119
|
-
puts "Available
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
puts "
|
|
125
|
-
puts " <categories> open a specific site group"
|
|
147
|
+
puts "Available flags:"
|
|
148
|
+
sorted_flags = KNOWN_FLAGS.sort_by{|command, details| details[:position]}
|
|
149
|
+
sorted_flags.each do |command, details|
|
|
150
|
+
puts " #{details[:flags].join(", ").ljust(21)}#{details[:description]}"
|
|
151
|
+
end
|
|
152
|
+
puts " #{"<categories>".ljust(21)}open a specific site group"
|
|
126
153
|
puts " (multiple are allowed, separated by spaces)"
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
154
|
+
if ruby_doc_installed?
|
|
155
|
+
puts " #{"<Ruby classes>".ljust(21)}open specified Ruby documentation"
|
|
156
|
+
end
|
|
157
|
+
puts "\nNote: The first flag in this list will be the only flag evaluated."
|
|
130
158
|
end
|
|
131
159
|
|
|
132
160
|
def self.view_categories
|
|
@@ -135,6 +163,7 @@ class CheckEverything
|
|
|
135
163
|
end
|
|
136
164
|
|
|
137
165
|
def self.assemble_ruby_docs_file
|
|
166
|
+
added_or_installed = ruby_doc_installed? ? "updated" : "installed"
|
|
138
167
|
ruby_doc = Nokogiri::HTML(open("http://ruby-doc.org/core/"))
|
|
139
168
|
class_names = []
|
|
140
169
|
ruby_doc.css("p.class a").each{|class_name| class_names << class_name.text}
|
|
@@ -146,14 +175,13 @@ class CheckEverything
|
|
|
146
175
|
f.print class_names.join("\n")
|
|
147
176
|
}
|
|
148
177
|
system("cp #{File.dirname(__FILE__)}/ruby_doc #{RUBYFILE}")
|
|
178
|
+
puts "Ruby documentation feature #{added_or_installed}!"
|
|
149
179
|
end
|
|
150
180
|
|
|
151
181
|
def self.open_links
|
|
152
182
|
@argv << "default" if @argv.empty?
|
|
153
183
|
|
|
154
|
-
|
|
155
|
-
# links, or the default links if none are specified.
|
|
156
|
-
if @argv.any?{|arg| KNOWN_TAGS[:all].include?(arg)}
|
|
184
|
+
if argv_requests?(:all)
|
|
157
185
|
links = @links.values.flatten.uniq
|
|
158
186
|
else
|
|
159
187
|
# Get links for all recognized categories
|
|
@@ -162,94 +190,126 @@ class CheckEverything
|
|
|
162
190
|
links.concat(add_documentation_to_links)
|
|
163
191
|
end
|
|
164
192
|
|
|
165
|
-
|
|
166
|
-
|
|
193
|
+
# Reject any empty strings ("-- " in the link file)
|
|
194
|
+
links.reject!{|link| link.strip.empty?}
|
|
195
|
+
links = add_http(links)
|
|
196
|
+
launch(links)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def self.add_http(links)
|
|
200
|
+
links.map { |url|
|
|
201
|
+
url.start_with?("http") ? "\"#{url}\"" : url = "\"#{"http://" << url}\""
|
|
167
202
|
}.join(" ")
|
|
168
|
-
|
|
203
|
+
end
|
|
169
204
|
|
|
170
|
-
|
|
171
|
-
|
|
205
|
+
def self.launch(urls)
|
|
206
|
+
if !urls.empty?
|
|
207
|
+
system("open #{urls}")
|
|
208
|
+
|
|
209
|
+
puts "\nIt's been a pleasure serving up your websites!"
|
|
210
|
+
puts "Did you know you can use categories to open specific site groups? " +
|
|
172
211
|
"Enter 'check_everything --links' for details.\n" if ARGV.empty?
|
|
212
|
+
else
|
|
213
|
+
puts "You don't seem to have any links for \"#{@argv.join("\" or \"")}\" in " +
|
|
214
|
+
"your file. Enter `check_everything -l` into your command line to " +
|
|
215
|
+
"add some links!"
|
|
216
|
+
end
|
|
173
217
|
end
|
|
174
218
|
|
|
175
219
|
def self.add_documentation_to_links
|
|
176
|
-
[].tap do |
|
|
177
|
-
if
|
|
220
|
+
[].tap do |doc_links|
|
|
221
|
+
if ruby_doc_installed?
|
|
178
222
|
classes = read_file(RUBYFILE).split
|
|
179
223
|
|
|
180
|
-
# Allow arguments of the form "array" or "array#collect"
|
|
181
|
-
class_argv = @argv.map {|arg| arg.split(
|
|
224
|
+
# Allow arguments of the form "array" or "array#collect" or "array::new"
|
|
225
|
+
class_argv = @argv.map {|arg| arg.split(/#|:/)}
|
|
182
226
|
class_matches = classes.map { |class_name|
|
|
183
227
|
class_argv.map { |name|
|
|
184
|
-
# If a match is found, return an array with either 1 element (class)
|
|
185
|
-
# or
|
|
186
|
-
if class_name.downcase == name[0]
|
|
187
|
-
[class_name, name[1]].compact
|
|
188
|
-
end
|
|
228
|
+
# If a match is found, return an array with either 1 element (class) or
|
|
229
|
+
# 2 elements (class, instance method) or 3 elements (class, "", class method)
|
|
230
|
+
[class_name, name[1], name[2]] if class_name.downcase == name[0]
|
|
189
231
|
}.compact
|
|
190
232
|
}.reject(&:empty?).flatten(1)
|
|
191
233
|
|
|
192
234
|
# If matches were found, serve them up!
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
235
|
+
class_matches.each do |klass|
|
|
236
|
+
# Add a method name to the link only if one is specified.
|
|
237
|
+
method = if klass[2]
|
|
238
|
+
# For class methods, use the class method link format.
|
|
239
|
+
"#method-c-#{klass[2]}"
|
|
240
|
+
elsif klass[1]
|
|
241
|
+
# For instance methods, use the instance method link format.
|
|
242
|
+
"#method-i-#{klass[1]}"
|
|
243
|
+
else
|
|
244
|
+
""
|
|
245
|
+
end
|
|
246
|
+
# Create link path and remove extra dashes added
|
|
247
|
+
# in the process of replacing special characters.
|
|
248
|
+
method = method.gsub(/[#{SUB_CHARS.keys}\[\]]/,SUB_CHARS).gsub('--','-')
|
|
249
|
+
method = method[0..-2] if method[-1] == '-'
|
|
250
|
+
doc_links << "ruby-doc.org/core-#{RUBY_VERSION}/#{klass[0]}.html#{method}"
|
|
203
251
|
end
|
|
204
252
|
end
|
|
205
253
|
end
|
|
206
254
|
end
|
|
207
255
|
|
|
208
|
-
def self.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
file.close
|
|
212
|
-
data
|
|
256
|
+
def self.extract_links
|
|
257
|
+
extract_links_from(read_file(LINKFILE).split("\n"))
|
|
258
|
+
extract_ruby_links
|
|
213
259
|
end
|
|
214
260
|
|
|
215
|
-
def self.
|
|
216
|
-
|
|
217
|
-
cur_tags = []
|
|
218
|
-
|
|
261
|
+
def self.extract_links_from(link_file)
|
|
262
|
+
current_categories = []
|
|
219
263
|
@links = {}
|
|
220
264
|
link_file.each do |line|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
265
|
+
case line[0,2]
|
|
266
|
+
when "&&"
|
|
267
|
+
# add categories as keys in @links, and assign to current categories
|
|
268
|
+
current_categories = add_category(line[2..-1].strip)
|
|
269
|
+
when "--"
|
|
270
|
+
# add links to each relevant categories in @links
|
|
271
|
+
current_categories.each { |category|
|
|
272
|
+
@links[category] << line[2..-1].strip
|
|
228
273
|
}
|
|
229
274
|
end
|
|
230
275
|
end
|
|
231
|
-
|
|
232
|
-
@ruby_links = []
|
|
233
|
-
if File.exists?(RUBYFILE)
|
|
234
|
-
classes = read_file(RUBYFILE).split
|
|
235
|
-
classes.each {|class_name| @ruby_links << class_name}
|
|
236
|
-
end
|
|
237
276
|
end
|
|
238
277
|
|
|
239
|
-
# Recursive helper method for extract_links
|
|
240
278
|
def self.add_category(line)
|
|
241
279
|
line.downcase!
|
|
242
|
-
# Add multiple
|
|
280
|
+
# Add multiple categories, if separated by semicolons.
|
|
243
281
|
if line.include?(";")
|
|
244
|
-
line.split(";").map(&:strip).each do |
|
|
245
|
-
add_category(
|
|
282
|
+
line.split(";").map(&:strip).each do |category|
|
|
283
|
+
add_category(category.strip)
|
|
246
284
|
end
|
|
247
285
|
else
|
|
248
286
|
# Note to raise an error if there is an invalid category.
|
|
249
|
-
|
|
250
|
-
|
|
287
|
+
invalid_char = line.match(/[ \-#:\/]/)
|
|
288
|
+
if invalid_char
|
|
289
|
+
@invalid_char_in_links = invalid_char.to_a[0] if invalid_char
|
|
290
|
+
end
|
|
291
|
+
# Optionally instantiate an array for the category if it doesn't exist yet.
|
|
251
292
|
@links[line] ||= []
|
|
252
293
|
[line]
|
|
253
294
|
end
|
|
254
295
|
end
|
|
296
|
+
|
|
297
|
+
def self.extract_ruby_links
|
|
298
|
+
@ruby_links = []
|
|
299
|
+
if ruby_doc_installed?
|
|
300
|
+
classes = read_file(RUBYFILE).split
|
|
301
|
+
classes.each {|class_name| @ruby_links << class_name}
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def self.read_file(file_name)
|
|
306
|
+
file = File.open(file_name, "r")
|
|
307
|
+
data = file.read
|
|
308
|
+
file.close
|
|
309
|
+
data
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
def self.ruby_doc_installed?
|
|
313
|
+
File.exists?(RUBYFILE)
|
|
314
|
+
end
|
|
255
315
|
end
|