check_names 0.1.4 → 0.3.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 +29 -10
- data/lib/check_names/version.rb +1 -1
- data/lib/check_names.rb +59 -13
- 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: 4cb09b3fed90bd9fa021f047530c0caa584f03b077c73a048dfd60fe6e059a97
|
4
|
+
data.tar.gz: d90ea5f678f36bd1e6144fba95cfcb9a5136dcd7f63b3ef31a60fbe8e89ab74b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b4baf708e2ef476305f901103ec360809a4ca79c299a81ed6b4d241c19649d6e0600ee8eba41820f506a9329cf1d230ab1a11cd16845748f0615e74bdb25918
|
7
|
+
data.tar.gz: 730e74250b8f7c7ddb87fcc42fb683edc60e80fb1b25001e6c399b9705d95643c5798e20daa2170772b4cb3117b590b9a4e58f248c6ef400aeebf52b491a123e
|
data/exe/check_names
CHANGED
@@ -31,33 +31,52 @@ of the following meanings:
|
|
31
31
|
3 You have an executable (reachable via \$PATH) with this name
|
32
32
|
4 You have a shell function with this name
|
33
33
|
5 You have an alias with this name
|
34
|
+
6 This name is used by a Ruby standard class
|
34
35
|
|
35
36
|
If more than one name was given, the return code is the maximum return code
|
36
37
|
received for any name.
|
37
38
|
|
38
39
|
The following options are available:
|
39
40
|
|
40
|
-
--help
|
41
|
-
--
|
42
|
-
|
41
|
+
--help -h Print this help information
|
42
|
+
--quiet -q Suppress messages about the status of the name check
|
43
|
+
--all -a Normally, check_names stops at the first use it finds.
|
44
|
+
With --all, it checks and reports every use
|
43
45
|
HELP
|
44
46
|
end
|
45
47
|
|
46
48
|
def main(args)
|
47
49
|
args = args.map { |arg| arg.downcase }
|
48
|
-
|
49
|
-
args.delete_at(
|
50
|
+
quiet = args.index { |arg| %w{-q --quiet}.include?(arg) }
|
51
|
+
args.delete_at(quiet) if quiet
|
52
|
+
all = args.index { |arg| %w{-a --all}.include?(arg) }
|
53
|
+
args.delete_at(all) if all
|
50
54
|
if args.size == 0 || %w{-h --help help}.include?(args.first)
|
51
55
|
show_help
|
52
56
|
exit
|
53
57
|
end
|
54
|
-
|
58
|
+
|
59
|
+
if all
|
60
|
+
results = GemName.check_names_all(*args)
|
61
|
+
else
|
62
|
+
results = GemName.check_names(*args)
|
63
|
+
end
|
64
|
+
|
55
65
|
rc = 0
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
66
|
+
|
67
|
+
types = []
|
68
|
+
results.each.with_index(1) do |result, count|
|
69
|
+
types << result[:description] if result[:result]
|
70
|
+
rc = result[:check] if result[:check] > rc
|
71
|
+
if count >= results.size || results[count][:name] != result[:name]
|
72
|
+
unless quiet
|
73
|
+
types << "Unused" if types.size == 0
|
74
|
+
puts "#{result[:name]}: #{types.join(', ')}"
|
75
|
+
end
|
76
|
+
types = []
|
77
|
+
end
|
60
78
|
end
|
79
|
+
rc = 1 if rc > 0 && (all || args.size > 1)
|
61
80
|
exit(rc)
|
62
81
|
end
|
63
82
|
|
data/lib/check_names/version.rb
CHANGED
data/lib/check_names.rb
CHANGED
@@ -46,23 +46,69 @@ module GemName
|
|
46
46
|
system("zsh -lic 'alias #{Shellwords.escape(name)}' >/dev/null")
|
47
47
|
end
|
48
48
|
|
49
|
-
def self.
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
def self.standard_class_exists?(name)
|
50
|
+
class_name = name.split('_').map(&:capitalize).join
|
51
|
+
Module.const_defined?(class_name)
|
52
|
+
end
|
53
|
+
|
54
|
+
CHECK_METHODS = [
|
55
|
+
{method: nil, description: "Unused"}, # 0
|
56
|
+
{method: :ruby_gem_exists?, description: "RubyGem"}, # 1
|
57
|
+
{method: :github_repository_exists?, description: "Github repository"}, # 2
|
58
|
+
{method: :executable_exists?, description: "Executable"}, # 3
|
59
|
+
{method: :function_exists?, description: "Function"}, # 4
|
60
|
+
{method: :alias_exists?, description: "Alias"}, # 5
|
61
|
+
{method: :standard_class_exists?, description: "Class"} # 6
|
62
|
+
]
|
63
|
+
|
64
|
+
def self.unused_result
|
65
|
+
{check: 0, description: CHECK_METHODS[0][:description], result: true}
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.check_name_once(check, name)
|
69
|
+
method = CHECK_METHODS[check] && CHECK_METHODS[check][:method]
|
70
|
+
if method
|
71
|
+
result = {check: check, description: CHECK_METHODS[check][:description], result: send(method, name)}
|
72
|
+
else
|
73
|
+
result = unused_result.dup
|
53
74
|
end
|
54
|
-
|
55
|
-
|
75
|
+
result[:name] = name
|
76
|
+
result
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.check_name(name)
|
80
|
+
name = name.downcase
|
81
|
+
result = unused_result.dup
|
82
|
+
(1...(CHECK_METHODS.size)).each do |check|
|
83
|
+
res = check_name_once(check, name)
|
84
|
+
if res[:result]
|
85
|
+
result = res
|
86
|
+
break
|
87
|
+
end
|
56
88
|
end
|
57
|
-
|
58
|
-
|
89
|
+
result[:name] = name
|
90
|
+
result
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.check_name_all(name)
|
94
|
+
(1...(CHECK_METHODS.size)).map do |check|
|
95
|
+
check_name_once(check, name)
|
59
96
|
end
|
60
|
-
|
61
|
-
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.check_names(*names)
|
100
|
+
results = []
|
101
|
+
names.each do |name|
|
102
|
+
results << check_name(name)
|
62
103
|
end
|
63
|
-
|
64
|
-
|
104
|
+
results
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.check_names_all(*names)
|
108
|
+
results = []
|
109
|
+
names.each do |name|
|
110
|
+
results += check_name_all(name)
|
65
111
|
end
|
66
|
-
|
112
|
+
results
|
67
113
|
end
|
68
114
|
end
|