classnamer 3.0.9 → 3.0.12
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.
- data/LICENSE.txt +1 -1
- data/{README.rdoc → README.txt} +8 -22
- data/bin/classnamer +5 -5
- data/lib/classnamer.rb +37 -19
- data/test/classnamer_test.rb +83 -34
- metadata +52 -31
- checksums.yaml +0 -7
- data/classnamer.gemspec +0 -20
data/LICENSE.txt
CHANGED
data/{README.rdoc → README.txt}
RENAMED
@@ -1,24 +1,21 @@
|
|
1
|
-
|
1
|
+
Classnamer
|
2
2
|
|
3
|
-
Classnamer randomly generates
|
4
|
-
|
5
|
-
|
3
|
+
Classnamer randomly generates facetious class names suitable for
|
4
|
+
object-oriented programming languages like C++ and Java. It includes a Ruby
|
5
|
+
library and command-line program.
|
6
6
|
|
7
|
-
This code is packaged as a RubyGem and tested on the following branches of
|
8
|
-
MRI (Matz's Ruby Interpreter): 1.8.7, 1.9.3, 2.0.0, 2.1.x, and 2.2.x.
|
9
7
|
|
10
|
-
|
11
|
-
== Using the command-line program
|
8
|
+
Using the command-line program
|
12
9
|
|
13
10
|
$ classnamer
|
14
11
|
PrioritizedUploadWrapper
|
15
12
|
|
16
13
|
|
17
|
-
|
14
|
+
Using in Ruby code
|
18
15
|
|
19
16
|
You can generate a random class name like this:
|
20
17
|
|
21
|
-
require
|
18
|
+
require "classnamer"
|
22
19
|
puts Classnamer.generate # => PrioritizedUploadWrapper
|
23
20
|
|
24
21
|
You can customize how class names are generated. Classnamer will generate
|
@@ -41,17 +38,6 @@ a Classnamer::Generator object for that.
|
|
41
38
|
generator.generate # => BarQux
|
42
39
|
|
43
40
|
|
44
|
-
|
45
|
-
|
46
|
-
This was written by Aaron Beckerman.
|
47
|
-
|
48
|
-
|
49
|
-
== Acknowledgements
|
41
|
+
Acknowledgements
|
50
42
|
|
51
43
|
Thanks to Luiz Signorelli and Marta Paciorkowska for their suggestions.
|
52
|
-
|
53
|
-
|
54
|
-
== Copyright
|
55
|
-
|
56
|
-
This code is distributed under the MIT License (also known as the Expat
|
57
|
-
License). See the LICENSE.txt file for details.
|
data/bin/classnamer
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "optparse"
|
4
|
+
require "classnamer"
|
5
5
|
|
6
6
|
OptionParser.new do |opts|
|
7
|
-
opts.banner =
|
7
|
+
opts.banner = "Usage: classnamer [options]"
|
8
8
|
|
9
|
-
opts.on_tail
|
9
|
+
opts.on_tail "-v", "--version", "Show version number" do
|
10
10
|
puts Classnamer::VERSION
|
11
11
|
exit
|
12
12
|
end
|
13
13
|
|
14
|
-
opts.on_tail
|
14
|
+
opts.on_tail "-h", "--help", "Show this message" do
|
15
15
|
puts opts
|
16
16
|
exit
|
17
17
|
end
|
data/lib/classnamer.rb
CHANGED
@@ -1,15 +1,21 @@
|
|
1
|
+
##
|
1
2
|
# This module randomly generates class names, such as
|
2
3
|
# "PrioritizedUploadWrapper". It does this by concatenating several parts
|
3
4
|
# ("Prioritized", "Upload", and "Wrapper", in this case), which are strings
|
4
|
-
# randomly selected from arrays of candidates
|
5
|
-
# "Wrapper" were each selected from a different array.
|
5
|
+
# randomly selected from arrays of candidates ("Prioritized", "Upload", and
|
6
|
+
# "Wrapper" were each selected from a different array). An array of such arrays
|
6
7
|
# is called a part candidate matrix.
|
8
|
+
|
7
9
|
module Classnamer
|
8
10
|
|
11
|
+
##
|
9
12
|
# The library's version string.
|
10
|
-
VERSION = '3.0.9'
|
11
13
|
|
14
|
+
VERSION = "3.0.12"
|
15
|
+
|
16
|
+
##
|
12
17
|
# The default part candidate matrix, used by generate.
|
18
|
+
|
13
19
|
PART_CANDIDATE_MATRIX = [
|
14
20
|
%w{Threadsafe Optimized Stable Automatic Abstract Serializable Writable
|
15
21
|
Readable Blocking Nonblocking Scriptable Smart Basic Remote Simple
|
@@ -36,36 +42,48 @@ module Classnamer
|
|
36
42
|
Constraint Module Migrator Descriptor Process}
|
37
43
|
]
|
38
44
|
|
45
|
+
##
|
39
46
|
# The default index generator, used by generate.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
# argument
|
50
|
-
|
51
|
-
|
47
|
+
|
48
|
+
PRNG = ::Kernel.method :rand
|
49
|
+
|
50
|
+
##
|
51
|
+
# Randomly generates a class name and returns it. This method takes two
|
52
|
+
# arguments, both optional: a part candidate matrix (+matrix+) and an index
|
53
|
+
# generator (+prng+). If +matrix+ is not specified, the module's default part
|
54
|
+
# candidate matrix (PART_CANDIDATE_MATRIX) is used. If +prng+ is not
|
55
|
+
# specified, Kernel::rand is used. +matrix+ must act like an array of arrays
|
56
|
+
# of strings. +prng+ will be sent call messages with one integer argument
|
57
|
+
# (an array length) and must act like Kernel::rand with an integer argument.
|
58
|
+
|
59
|
+
def self.generate matrix = PART_CANDIDATE_MATRIX, prng = PRNG
|
60
|
+
matrix.map { |a| a[prng.call a.length] }.join ""
|
52
61
|
end
|
53
62
|
|
63
|
+
##
|
54
64
|
# A class name generator that always uses the specified part candidate matrix
|
55
65
|
# and index generator.
|
66
|
+
|
56
67
|
class Generator
|
68
|
+
|
69
|
+
##
|
57
70
|
# Creates a class name generator with the specified part candidate matrix
|
58
71
|
# and index generator.
|
59
|
-
|
60
|
-
|
72
|
+
|
73
|
+
def initialize matrix = PART_CANDIDATE_MATRIX, prng = PRNG
|
61
74
|
@matrix = matrix
|
62
75
|
@prng = prng
|
76
|
+
nil
|
63
77
|
end
|
64
78
|
|
65
|
-
|
66
|
-
#
|
79
|
+
##
|
80
|
+
# Generates and returns a class name using the part candidate matrix and
|
81
|
+
# index generator specified when the generator was created.
|
82
|
+
|
67
83
|
def generate
|
68
84
|
Classnamer.generate @matrix, @prng
|
69
85
|
end
|
86
|
+
|
70
87
|
end
|
88
|
+
|
71
89
|
end
|
data/test/classnamer_test.rb
CHANGED
@@ -1,20 +1,48 @@
|
|
1
|
-
|
1
|
+
# Sections that create local variables are in class definitions so that later
|
2
|
+
# sections cannot accidentally reference those local variables.
|
2
3
|
|
3
|
-
|
4
|
+
require "classnamer"
|
4
5
|
|
5
|
-
|
6
|
+
# Classnamer should be a module.
|
7
|
+
fail "" unless Module.equal? Classnamer.class
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
# The version constant should be a string.
|
10
|
+
fail "" unless String.equal? Classnamer::VERSION.class
|
9
11
|
|
10
|
-
|
12
|
+
# The default part candidate matrix should be an array.
|
13
|
+
fail "" unless Array.equal? Classnamer::PART_CANDIDATE_MATRIX.class
|
11
14
|
|
12
|
-
|
15
|
+
# The default part candidate matrix should have three sections.
|
16
|
+
fail "" unless 3 == Classnamer::PART_CANDIDATE_MATRIX.length
|
13
17
|
|
14
|
-
|
15
|
-
|
18
|
+
# The default part candidate matrix should contain only arrays.
|
19
|
+
fail "" unless Classnamer::PART_CANDIDATE_MATRIX.
|
20
|
+
all? { |elem| ::Array.equal? elem.class }
|
16
21
|
|
17
|
-
|
22
|
+
# Each default part candidate should start with an uppercase English letter.
|
23
|
+
fail "" unless Classnamer::PART_CANDIDATE_MATRIX.flatten(1).
|
24
|
+
all? { |part_candidate| /\A[A-Z]/ =~ part_candidate }
|
25
|
+
|
26
|
+
# The default index generator should be a wrapper around Kernel.rand.
|
27
|
+
fail "" unless Kernel.method(:rand) == Classnamer::PRNG
|
28
|
+
|
29
|
+
# The default index generator should return a valid index when a call message
|
30
|
+
# is sent to it with a length argument.
|
31
|
+
fail "" unless 0 == Classnamer::PRNG.call(1)
|
32
|
+
|
33
|
+
# Classnamer should say it responds to generate messages.
|
34
|
+
fail "" unless Classnamer.respond_to? :generate
|
35
|
+
|
36
|
+
# Classnamer.generate should return a string.
|
37
|
+
fail "" unless String.equal? Classnamer.generate.class
|
38
|
+
|
39
|
+
# Classnamer.generate should convert all the parts to strings.
|
40
|
+
fail "" unless "42ObjecttrueSymbolFoo" ==
|
41
|
+
Classnamer.generate([[42], [Object], [nil], [true], [:Symbol], ["Foo"]])
|
42
|
+
|
43
|
+
# Classnamer.generate should send the expected messages to the index generator
|
44
|
+
# given as an argument.
|
45
|
+
class ::Object
|
18
46
|
matrix = [%w{A B C}, [], %w{A B}, %w{A}]
|
19
47
|
prng_args = []
|
20
48
|
prng = lambda { |n|
|
@@ -22,52 +50,73 @@ lambda do
|
|
22
50
|
0
|
23
51
|
}
|
24
52
|
Classnamer.generate matrix, prng
|
25
|
-
[3, 0, 2, 1] == prng_args
|
26
|
-
end
|
53
|
+
fail "" unless [3, 0, 2, 1] == prng_args
|
54
|
+
end
|
27
55
|
|
28
|
-
|
56
|
+
# Classnamer should return the expected string when sent a generate message
|
57
|
+
# with a deterministic index generator as an argument.
|
58
|
+
class ::Object
|
29
59
|
matrix = [%w{Foo0 Foo1 Foo2}, %w{Bar0 Bar1 Bar2}, %w{Baz0 Baz1 Baz2}]
|
30
60
|
indices = [0, 2, 1]
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
'Foo' == Classnamer.generate([['Foo']]) or fail
|
36
|
-
|
37
|
-
'' == Classnamer.generate([]) or fail
|
61
|
+
fail "" unless "Foo0Bar2Baz1" ==
|
62
|
+
Classnamer.generate(matrix, lambda { |_| indices.shift })
|
63
|
+
end
|
38
64
|
|
39
|
-
|
65
|
+
# Classnamer.generate should return the expected strings when given part
|
66
|
+
# candidate matrices consisting of empty and single-element arrays.
|
67
|
+
fail "" unless "Foo" == Classnamer.generate([["Foo"]])
|
68
|
+
fail "" unless "" == Classnamer.generate([])
|
69
|
+
fail "" unless "" == Classnamer.generate([[], [], []])
|
70
|
+
|
71
|
+
# Classnamer.generate should create a new string and not modify any parts.
|
72
|
+
class ::Object
|
73
|
+
a = "a"
|
74
|
+
b = "b"
|
75
|
+
name = Classnamer.generate [[a], [b]]
|
76
|
+
fail "" if a.equal? name
|
77
|
+
fail "" if b.equal? name
|
78
|
+
fail "" unless "a" == a
|
79
|
+
fail "" unless "b" == b
|
80
|
+
end
|
40
81
|
|
82
|
+
# Classnamer.generate should raise an exception when given a part candidate
|
83
|
+
# matrix that does not conform to the expected interface as an argument.
|
41
84
|
begin
|
42
85
|
Classnamer.generate nil
|
43
86
|
rescue NoMethodError
|
44
87
|
else
|
45
|
-
fail
|
88
|
+
fail ""
|
46
89
|
end
|
47
|
-
|
48
90
|
begin
|
49
|
-
Classnamer.generate
|
91
|
+
Classnamer.generate [["Foo"], nil]
|
50
92
|
rescue NoMethodError
|
51
93
|
else
|
52
|
-
fail
|
94
|
+
fail ""
|
53
95
|
end
|
54
96
|
|
97
|
+
# Classnamer.generate should raise an exception when given an index generator
|
98
|
+
# that does not conform to the expected interface as an argument.
|
55
99
|
begin
|
56
|
-
Classnamer.generate
|
100
|
+
Classnamer.generate Classnamer::PART_CANDIDATE_MATRIX, nil
|
57
101
|
rescue NoMethodError
|
58
102
|
else
|
59
|
-
fail
|
103
|
+
fail ""
|
60
104
|
end
|
61
105
|
|
62
|
-
|
106
|
+
# Classnamer::Generator.new should return a generator of the expected class.
|
107
|
+
fail "" unless Classnamer::Generator.equal? Classnamer::Generator.new.class
|
63
108
|
|
64
|
-
|
109
|
+
# A generator should say it responds to generate messages.
|
110
|
+
fail "" unless Classnamer::Generator.new.respond_to? :generate
|
65
111
|
|
66
|
-
|
112
|
+
# A generator with a deterministic index generator should return the expected
|
113
|
+
# name when sent a generate message.
|
114
|
+
class ::Object
|
67
115
|
matrix = [%w{Foo0 Foo1 Foo2}, %w{Bar0 Bar1 Bar2}, %w{Baz0 Baz1 Baz2}]
|
68
116
|
indices = [0, 2, 1]
|
69
|
-
generator = Classnamer::Generator.new
|
70
|
-
|
71
|
-
end
|
117
|
+
generator = Classnamer::Generator.new matrix, lambda { |_| indices.shift }
|
118
|
+
fail "" unless "Foo0Bar2Baz1" == generator.generate
|
119
|
+
end
|
72
120
|
|
73
|
-
|
121
|
+
# If this message doesn't get written, there was a problem.
|
122
|
+
puts "Test finished: #{__FILE__}"
|
metadata
CHANGED
@@ -1,52 +1,73 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: classnamer
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
- 12
|
10
|
+
version: 3.0.12
|
5
11
|
platform: ruby
|
6
|
-
authors:
|
12
|
+
authors:
|
7
13
|
- Aaron Beckerman
|
8
|
-
autorequire:
|
14
|
+
autorequire:
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
|
-
|
17
|
+
|
18
|
+
date: 2025-05-16 00:00:00 -07:00
|
19
|
+
default_executable:
|
12
20
|
dependencies: []
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
executables:
|
21
|
+
|
22
|
+
description: Classnamer randomly generates facetious class names suitable for object-oriented programming languages like C++ and Java. It includes a library and command-line program.
|
23
|
+
email:
|
24
|
+
executables:
|
18
25
|
- classnamer
|
19
26
|
extensions: []
|
27
|
+
|
20
28
|
extra_rdoc_files: []
|
21
|
-
|
29
|
+
|
30
|
+
files:
|
22
31
|
- LICENSE.txt
|
23
|
-
- README.
|
32
|
+
- README.txt
|
24
33
|
- bin/classnamer
|
25
|
-
- classnamer.gemspec
|
26
34
|
- lib/classnamer.rb
|
27
35
|
- test/classnamer_test.rb
|
28
|
-
|
29
|
-
|
36
|
+
has_rdoc: true
|
37
|
+
homepage:
|
38
|
+
licenses:
|
30
39
|
- MIT
|
31
|
-
|
32
|
-
post_install_message:
|
40
|
+
post_install_message:
|
33
41
|
rdoc_options: []
|
34
|
-
|
42
|
+
|
43
|
+
require_paths:
|
35
44
|
- lib
|
36
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
-
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
38
48
|
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 57
|
51
|
+
segments:
|
52
|
+
- 1
|
53
|
+
- 8
|
54
|
+
- 7
|
40
55
|
version: 1.8.7
|
41
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
-
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
43
59
|
- - ">="
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
46
65
|
requirements: []
|
47
|
-
|
48
|
-
|
49
|
-
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.6.2
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
50
71
|
summary: A random class name generator.
|
51
|
-
test_files:
|
52
|
-
|
72
|
+
test_files: []
|
73
|
+
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA256:
|
3
|
-
metadata.gz: d27a21e3575373a7dd8339fc51f8f06fa691ec94575523da070ccd4afe8608cc
|
4
|
-
data.tar.gz: 1de71f5634a0f8ab76f4cdafd584489e8cbe10ea14de32f8cfb264291c512037
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: e3b75eee842eb2de0866e81c81e9457db9622e4fbe7ab8c914fc954c23393c54371eb69a722cc23d00cd490148aca40762d743f1a15c04c157ae5cce9f046469
|
7
|
-
data.tar.gz: 3e14a92ade9675a6e15210a7f14e7d17a3d09ac764d6e61fe101c0f61cf9dea733c2707f56458a1d65c3af04522d8e4b14eb7cf1e8393c7c6ae156ea68a6826e
|
data/classnamer.gemspec
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "classnamer"
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = "classnamer"
|
8
|
-
s.version = Classnamer::VERSION
|
9
|
-
s.author = "Aaron Beckerman"
|
10
|
-
s.summary = %q{A random class name generator.}
|
11
|
-
s.description = %q{Classnamer randomly generates tongue-in-cheek class names suitable for enterprise-friendly object-oriented programming languages like C++ and Java. It includes a library and a command-line program.}
|
12
|
-
s.license = "MIT"
|
13
|
-
s.platform = Gem::Platform::RUBY
|
14
|
-
s.required_ruby_version = ">= 1.8.7"
|
15
|
-
s.bindir = "bin"
|
16
|
-
s.files = ["LICENSE.txt", "README.rdoc", "bin/classnamer", "classnamer.gemspec", "lib/classnamer.rb", "test/classnamer_test.rb"]
|
17
|
-
s.test_files = ["test/classnamer_test.rb"]
|
18
|
-
s.executables = ["classnamer"]
|
19
|
-
s.require_paths = ["lib"]
|
20
|
-
end
|