check_names 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cb09b3fed90bd9fa021f047530c0caa584f03b077c73a048dfd60fe6e059a97
4
- data.tar.gz: d90ea5f678f36bd1e6144fba95cfcb9a5136dcd7f63b3ef31a60fbe8e89ab74b
3
+ metadata.gz: 8e8b673b887e26b3ec7100c88369de69d82f985a65389b9bbf4d901e0dc76a53
4
+ data.tar.gz: c5c5d6f4157348de247b653598360cc6da83d56940fa85a0e4a0367b6b13a2c7
5
5
  SHA512:
6
- metadata.gz: 8b4baf708e2ef476305f901103ec360809a4ca79c299a81ed6b4d241c19649d6e0600ee8eba41820f506a9329cf1d230ab1a11cd16845748f0615e74bdb25918
7
- data.tar.gz: 730e74250b8f7c7ddb87fcc42fb683edc60e80fb1b25001e6c399b9705d95643c5798e20daa2170772b4cb3117b590b9a4e58f248c6ef400aeebf52b491a123e
6
+ metadata.gz: ed35fb48743e2651df7d8d03fccc9394ef69d69ce5268059d11542a84ec941759c03092120b1cedea4c339b4b1426446d5e857a74bcab46a5e8111fb3468f40d
7
+ data.tar.gz: db674a40f05f65f22705ed8eca975c6452a02bc2322102fe889990e7313d8cbb1d6974f8cba57498ebf875d20a89e0c9c43d99e3180c84aacf3f42989d7f079d
data/exe/check_names CHANGED
@@ -22,33 +22,30 @@ Version #{CheckNames.version}
22
22
  Usage:
23
23
  check_names [OPTIONS]... [names]...
24
24
 
25
- check_names exits with a zero return code (success) if no conflicting gem
26
- name exists. Otherwise it exits with a non-zero return code, with one
27
- of the following meanings:
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
- 1 A gem exists on Rubygems with this name
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
- If more than one name was given, the return code is the maximum return code
37
- received for any name.
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
- --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
42
+ --all -a Report all uses of the name. (Otherwise, check_names stops at
43
+ the first use it finds.)
45
44
  HELP
46
45
  end
47
46
 
48
47
  def main(args)
49
48
  args = args.map { |arg| arg.downcase }
50
- quiet = args.index { |arg| %w{-q --quiet}.include?(arg) }
51
- args.delete_at(quiet) if quiet
52
49
  all = args.index { |arg| %w{-a --all}.include?(arg) }
53
50
  args.delete_at(all) if all
54
51
  if args.size == 0 || %w{-h --help help}.include?(args.first)
@@ -56,27 +53,26 @@ def main(args)
56
53
  exit
57
54
  end
58
55
 
59
- if all
60
- results = GemName.check_names_all(*args)
61
- else
62
- results = GemName.check_names(*args)
63
- end
64
-
65
56
  rc = 0
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(', ')}"
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
75
71
  end
76
- types = []
77
72
  end
73
+ print CheckNames.check_method(0)[:description] unless checks_printed_count > 0
74
+ puts
78
75
  end
79
- rc = 1 if rc > 0 && (all || args.size > 1)
80
76
  exit(rc)
81
77
  end
82
78
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CheckNames
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
 
6
6
  def self.version
7
7
  VERSION
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 GemName
7
+ module CheckNames
8
8
  class Error < StandardError; end
9
9
 
10
10
  def self.ruby_gem_exists?(name)
@@ -48,24 +48,38 @@ module GemName
48
48
 
49
49
  def self.standard_class_exists?(name)
50
50
  class_name = name.split('_').map(&:capitalize).join
51
- Module.const_defined?(class_name)
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
60
  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
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"}
62
68
  ]
63
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
+
64
78
  def self.unused_result
65
79
  {check: 0, description: CHECK_METHODS[0][:description], result: true}
66
80
  end
67
81
 
68
- def self.check_name_once(check, name)
82
+ def self.check_name(check, name)
69
83
  method = CHECK_METHODS[check] && CHECK_METHODS[check][:method]
70
84
  if method
71
85
  result = {check: check, description: CHECK_METHODS[check][:description], result: send(method, name)}
@@ -75,40 +89,4 @@ module GemName
75
89
  result[:name] = name
76
90
  result
77
91
  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
88
- end
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)
96
- end
97
- end
98
-
99
- def self.check_names(*names)
100
- results = []
101
- names.each do |name|
102
- results << check_name(name)
103
- end
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)
111
- end
112
- results
113
- end
114
92
  end
data/sig/check_names.rbs CHANGED
@@ -1,4 +1,4 @@
1
- module GemName
1
+ module CheckNames
2
2
  VERSION: String
3
3
  # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: check_names
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard LeBer