check_names 0.2.0 → 0.4.0
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/exe/check_names +34 -18
- data/lib/check_names/version.rb +1 -1
- data/lib/check_names.rb +38 -22
- data/sig/check_names.rbs +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e8b673b887e26b3ec7100c88369de69d82f985a65389b9bbf4d901e0dc76a53
|
4
|
+
data.tar.gz: c5c5d6f4157348de247b653598360cc6da83d56940fa85a0e4a0367b6b13a2c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed35fb48743e2651df7d8d03fccc9394ef69d69ce5268059d11542a84ec941759c03092120b1cedea4c339b4b1426446d5e857a74bcab46a5e8111fb3468f40d
|
7
|
+
data.tar.gz: db674a40f05f65f22705ed8eca975c6452a02bc2322102fe889990e7313d8cbb1d6974f8cba57498ebf875d20a89e0c9c43d99e3180c84aacf3f42989d7f079d
|
data/exe/check_names
CHANGED
@@ -22,40 +22,56 @@ Version #{CheckNames.version}
|
|
22
22
|
Usage:
|
23
23
|
check_names [OPTIONS]... [names]...
|
24
24
|
|
25
|
-
check_names
|
26
|
-
|
27
|
-
of the
|
25
|
+
check_names looks to see whether the names provided are already in use.
|
26
|
+
It outputs the usage (if any) of each name on $STDOUT. It exits with a
|
27
|
+
zero return code if none of the names are already in use. Otherwise it
|
28
|
+
exits with return code 1.
|
28
29
|
|
29
|
-
|
30
|
-
2 You have a github repository of this name
|
31
|
-
3 You have an executable (reachable via \$PATH) with this name
|
32
|
-
4 You have a shell function with this name
|
33
|
-
5 You have an alias with this name
|
34
|
-
6 This name is used by a Ruby standard class
|
30
|
+
check_names checks for each of the following uses:
|
35
31
|
|
36
|
-
|
37
|
-
|
32
|
+
- The name of a Ruby standard class
|
33
|
+
- The name of a gem on RubyGems
|
34
|
+
- The name of one of your Github repositories
|
35
|
+
- The name of a sehll alias
|
36
|
+
- The name of a shell function
|
37
|
+
- The name of an executable (reachable via \$PATH)
|
38
38
|
|
39
39
|
The following options are available:
|
40
40
|
|
41
41
|
--help -h Print this help information
|
42
|
-
--
|
42
|
+
--all -a Report all uses of the name. (Otherwise, check_names stops at
|
43
|
+
the first use it finds.)
|
43
44
|
HELP
|
44
45
|
end
|
45
46
|
|
46
47
|
def main(args)
|
47
48
|
args = args.map { |arg| arg.downcase }
|
48
|
-
|
49
|
-
args.delete_at(
|
49
|
+
all = args.index { |arg| %w{-a --all}.include?(arg) }
|
50
|
+
args.delete_at(all) if all
|
50
51
|
if args.size == 0 || %w{-h --help help}.include?(args.first)
|
51
52
|
show_help
|
52
53
|
exit
|
53
54
|
end
|
55
|
+
|
54
56
|
rc = 0
|
55
|
-
args.each do |arg|
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
args.each.with_index(0) do |arg, i|
|
58
|
+
results = []
|
59
|
+
print "#{arg}: "
|
60
|
+
checks_printed_count = 0
|
61
|
+
(1...(CheckNames.check_methods.size)).each do |check|
|
62
|
+
result = CheckNames.check_name(check, arg)
|
63
|
+
if result[:result]
|
64
|
+
print ", " if checks_printed_count > 0
|
65
|
+
print result[:description]
|
66
|
+
checks_printed_count += 1
|
67
|
+
end
|
68
|
+
if checks_printed_count > 0
|
69
|
+
rc = 1
|
70
|
+
break unless all
|
71
|
+
end
|
72
|
+
end
|
73
|
+
print CheckNames.check_method(0)[:description] unless checks_printed_count > 0
|
74
|
+
puts
|
59
75
|
end
|
60
76
|
exit(rc)
|
61
77
|
end
|
data/lib/check_names/version.rb
CHANGED
data/lib/check_names.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative "check_names/version"
|
|
4
4
|
require 'shellwords'
|
5
5
|
require 'httparty'
|
6
6
|
|
7
|
-
module
|
7
|
+
module CheckNames
|
8
8
|
class Error < StandardError; end
|
9
9
|
|
10
10
|
def self.ruby_gem_exists?(name)
|
@@ -48,29 +48,45 @@ module GemName
|
|
48
48
|
|
49
49
|
def self.standard_class_exists?(name)
|
50
50
|
class_name = name.split('_').map(&:capitalize).join
|
51
|
-
|
51
|
+
# Do it this way so the Class space isn't polluted with the classes of this script
|
52
|
+
command = "ruby -e \"puts Module.const_defined?(\\\"#{class_name}\\\").inspect\""
|
53
|
+
begin
|
54
|
+
eval(`#{command}`.chomp)
|
55
|
+
rescue
|
56
|
+
false
|
57
|
+
end
|
52
58
|
end
|
53
59
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
60
|
+
CHECK_METHODS = [
|
61
|
+
{method: nil, description: "Unused"},
|
62
|
+
{method: :standard_class_exists?, description: "Class"},
|
63
|
+
{method: :ruby_gem_exists?, description: "RubyGem"},
|
64
|
+
{method: :github_repository_exists?, description: "Github repository"},
|
65
|
+
{method: :alias_exists?, description: "Alias"},
|
66
|
+
{method: :function_exists?, description: "Function"},
|
67
|
+
{method: :executable_exists?, description: "Executable"}
|
68
|
+
]
|
69
|
+
|
70
|
+
def self.check_methods
|
71
|
+
CHECK_METHODS
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.check_method(i)
|
75
|
+
CHECK_METHODS[i]
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.unused_result
|
79
|
+
{check: 0, description: CHECK_METHODS[0][:description], result: true}
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.check_name(check, name)
|
83
|
+
method = CHECK_METHODS[check] && CHECK_METHODS[check][:method]
|
84
|
+
if method
|
85
|
+
result = {check: check, description: CHECK_METHODS[check][:description], result: send(method, name)}
|
86
|
+
else
|
87
|
+
result = unused_result.dup
|
73
88
|
end
|
74
|
-
|
89
|
+
result[:name] = name
|
90
|
+
result
|
75
91
|
end
|
76
92
|
end
|
data/sig/check_names.rbs
CHANGED