pkwde-renum 1.0.2
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/History.txt +18 -0
- data/License.txt +20 -0
- data/Manifest.txt +28 -0
- data/README.txt +1 -0
- data/Rakefile +7 -0
- data/config/hoe.rb +71 -0
- data/config/requirements.rb +17 -0
- data/lib/renum.rb +15 -0
- data/lib/renum/enumerated_value.rb +49 -0
- data/lib/renum/enumerated_value_type_factory.rb +54 -0
- data/lib/renum/version.rb +9 -0
- data/log/debug.log +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/spec/renum_spec.rb +109 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +14 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +26 -0
- data/tasks/website.rake +17 -0
- data/website/index.html +143 -0
- data/website/index.txt +84 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +52 -0
- metadata +87 -0
data/spec/renum_spec.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
enum :Status, [ :NOT_STARTED, :IN_PROGRESS, :COMPLETE ]
|
4
|
+
|
5
|
+
module MyNamespace
|
6
|
+
enum :FooValue, %w( Bar Baz Bat )
|
7
|
+
end
|
8
|
+
|
9
|
+
enum :Color, [ :RED, :GREEN, :BLUE ] do
|
10
|
+
def abbr
|
11
|
+
name[0..0]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
enum :Size do
|
16
|
+
Small("Really really tiny")
|
17
|
+
Medium("Sort of in the middle")
|
18
|
+
Large("Quite big")
|
19
|
+
|
20
|
+
attr_reader :description
|
21
|
+
|
22
|
+
def init description
|
23
|
+
@description = description
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
enum :HairColor do
|
28
|
+
BLONDE()
|
29
|
+
BRUNETTE()
|
30
|
+
RED()
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "basic enum" do
|
34
|
+
|
35
|
+
it "creates a class for the value type" do
|
36
|
+
Status.should be_an_instance_of(Class)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "makes each value an instance of the value type" do
|
40
|
+
Status::NOT_STARTED.should be_an_instance_of(Status)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "exposes array of values" do
|
44
|
+
Status.values.should == [Status::NOT_STARTED, Status::IN_PROGRESS, Status::COMPLETE]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "enumerates over values" do
|
48
|
+
Status.map {|s| s.name}.should == %w[NOT_STARTED IN_PROGRESS COMPLETE]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "indexes values" do
|
52
|
+
Status[2].should == Status::COMPLETE
|
53
|
+
Color[0].should == Color::RED
|
54
|
+
end
|
55
|
+
|
56
|
+
it "provides index lookup on values" do
|
57
|
+
Status::IN_PROGRESS.index.should == 1
|
58
|
+
Color::GREEN.index.should == 1
|
59
|
+
end
|
60
|
+
|
61
|
+
it "provides a reasonable to_s for values" do
|
62
|
+
Status::NOT_STARTED.to_s.should == "Status::NOT_STARTED"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "makes values comparable" do
|
66
|
+
Color::RED.should < Color::GREEN
|
67
|
+
Color::RED.should_not == Status::NOT_STARTED
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "nested enum" do
|
72
|
+
it "is namespaced in the containing module or class" do
|
73
|
+
MyNamespace::FooValue::Bar.class.should == MyNamespace::FooValue
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "enum with a block" do
|
78
|
+
it "can define additional instance methods" do
|
79
|
+
Color::RED.abbr.should == "R"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "enum with no values array and values declared in the block" do
|
84
|
+
it "provides an alternative means of declaring values where extra information can be provided for initialization" do
|
85
|
+
Size::Small.description.should == "Really really tiny"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "works the same as the basic form with respect to ordering" do
|
89
|
+
Size.values.should == [Size::Small, Size::Medium, Size::Large]
|
90
|
+
end
|
91
|
+
|
92
|
+
it "responds as expected to arbitrary method calls, in spite of using method_missing for value definition" do
|
93
|
+
lambda { Size.ExtraLarge() }.should raise_error(NoMethodError)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "supprts there being no extra data and no init() method defined, if you don't need them" do
|
97
|
+
HairColor::BLONDE.name.should == "BLONDE"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# It was reported on my blog that <=> was causing segfaults.
|
102
|
+
# I'd love to figure out why, but first I'd love to fix that.
|
103
|
+
describe "digging into this segfault/illegal instruction issue, renum" do
|
104
|
+
it "doesn't cause the ruby process to bomb!" do
|
105
|
+
Color::RED.should < Color::GREEN
|
106
|
+
Color::RED.should_not > Color::GREEN
|
107
|
+
Color::RED.should < Color::BLUE
|
108
|
+
end
|
109
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
desc 'Release the website and new gem version'
|
2
|
+
task :deploy => [:check_version, :install_gem, :spec_gem, :website, :release] do
|
3
|
+
puts "Remember to create SVN tag:"
|
4
|
+
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
5
|
+
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
6
|
+
puts "Suggested comment:"
|
7
|
+
puts "Tagging release #{CHANGES}"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
11
|
+
task :local_deploy => [:website_generate, :install_gem]
|
12
|
+
|
13
|
+
task :check_version do
|
14
|
+
unless ENV['VERSION']
|
15
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
unless ENV['VERSION'] == VERS
|
19
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
25
|
+
task :install_gem_no_doc => [:clean, :package] do
|
26
|
+
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
27
|
+
end
|
28
|
+
|
29
|
+
namespace :manifest do
|
30
|
+
desc 'Recreate Manifest.txt to include ALL files'
|
31
|
+
task :refresh do
|
32
|
+
`rake check_manifest | patch -p0 > Manifest.txt`
|
33
|
+
end
|
34
|
+
end
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
21
|
+
end
|
22
|
+
|
23
|
+
task :spec_gem do
|
24
|
+
ENV['USE_GEM'] = 'y'
|
25
|
+
Rake::Task[:spec].invoke
|
26
|
+
end
|
data/tasks/website.rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
desc 'Generate website files'
|
2
|
+
task :website_generate => :ruby_env do
|
3
|
+
(Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
|
4
|
+
sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Upload website files to rubyforge'
|
9
|
+
task :website_upload do
|
10
|
+
host = "#{rubyforge_username}@rubyforge.org"
|
11
|
+
remote_dir = "/var/www/gforge-projects/#{PATH}/"
|
12
|
+
local_dir = 'website'
|
13
|
+
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate and upload website files'
|
17
|
+
task :website => [:website_generate, :website_upload, :publish_docs]
|
data/website/index.html
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
7
|
+
<title>
|
8
|
+
renum
|
9
|
+
</title>
|
10
|
+
<script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
|
11
|
+
<style>
|
12
|
+
|
13
|
+
</style>
|
14
|
+
<script type="text/javascript">
|
15
|
+
window.onload = function() {
|
16
|
+
settings = {
|
17
|
+
tl: { radius: 10 },
|
18
|
+
tr: { radius: 10 },
|
19
|
+
bl: { radius: 10 },
|
20
|
+
br: { radius: 10 },
|
21
|
+
antiAlias: true,
|
22
|
+
autoPad: true,
|
23
|
+
validTags: ["div"]
|
24
|
+
}
|
25
|
+
var versionBox = new curvyCorners(settings, document.getElementById("version"));
|
26
|
+
versionBox.applyCornersToAll();
|
27
|
+
}
|
28
|
+
</script>
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="main">
|
32
|
+
|
33
|
+
<h1>renum</h1>
|
34
|
+
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/renum"; return false'>
|
35
|
+
<p>Get Version</p>
|
36
|
+
<a href="http://rubyforge.org/projects/renum" class="numbers">1.0.0</a>
|
37
|
+
</div>
|
38
|
+
<p>Renum provides a readable but terse enum facility for Ruby. Enums are sometimes called object constants and are analogous to the type-safe enum pattern in Java, though obviously Ruby’s flexibility means there’s no such thing as type-safety.</p>
|
39
|
+
|
40
|
+
|
41
|
+
<h2>Installing</h2>
|
42
|
+
|
43
|
+
|
44
|
+
<p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">renum</span></pre></p>
|
45
|
+
|
46
|
+
|
47
|
+
<h2>Demonstration of usage</h2>
|
48
|
+
|
49
|
+
|
50
|
+
<p>Renum allows you to do things like this:</p>
|
51
|
+
|
52
|
+
|
53
|
+
<p><pre class='syntax'><span class="ident">enum</span> <span class="symbol">:Status</span><span class="punct">,</span> <span class="punct">%w(</span><span class="string"> NOT_STARTED IN_PROGRESS COMPLETE </span><span class="punct">)</span>
|
54
|
+
|
55
|
+
<span class="ident">enum</span> <span class="symbol">:Size</span> <span class="keyword">do</span>
|
56
|
+
<span class="constant">Small</span><span class="punct">("</span><span class="string">Really really tiny</span><span class="punct">")</span>
|
57
|
+
<span class="constant">Medium</span><span class="punct">("</span><span class="string">Sort of in the middle</span><span class="punct">")</span>
|
58
|
+
<span class="constant">Large</span><span class="punct">("</span><span class="string">Quite big</span><span class="punct">")</span>
|
59
|
+
|
60
|
+
<span class="ident">attr_reader</span> <span class="symbol">:description</span>
|
61
|
+
|
62
|
+
<span class="keyword">def </span><span class="method">init</span> <span class="ident">description</span>
|
63
|
+
<span class="attribute">@description</span> <span class="punct">=</span> <span class="ident">description</span>
|
64
|
+
<span class="keyword">end</span>
|
65
|
+
<span class="keyword">end</span>
|
66
|
+
|
67
|
+
<span class="keyword">module </span><span class="module">MyNamespace</span>
|
68
|
+
<span class="ident">enum</span> <span class="symbol">:FooValue</span><span class="punct">,</span> <span class="punct">[</span> <span class="symbol">:Bar</span><span class="punct">,</span> <span class="symbol">:Baz</span><span class="punct">,</span> <span class="symbol">:Bat</span> <span class="punct">]</span>
|
69
|
+
<span class="keyword">end</span></pre></p>
|
70
|
+
|
71
|
+
|
72
|
+
<p>Giving you something that satisfies this spec, plus a bit more:</p>
|
73
|
+
|
74
|
+
|
75
|
+
<p><pre class='syntax'><span class="ident">describe</span> <span class="punct">"</span><span class="string">enum</span><span class="punct">"</span> <span class="keyword">do</span>
|
76
|
+
|
77
|
+
<span class="ident">it</span> <span class="punct">"</span><span class="string">creates a class for the value type</span><span class="punct">"</span> <span class="keyword">do</span>
|
78
|
+
<span class="constant">Status</span><span class="punct">.</span><span class="ident">class</span><span class="punct">.</span><span class="ident">should</span> <span class="punct">==</span> <span class="constant">Class</span>
|
79
|
+
<span class="keyword">end</span>
|
80
|
+
|
81
|
+
<span class="ident">it</span> <span class="punct">"</span><span class="string">makes each value an instance of the value type</span><span class="punct">"</span> <span class="keyword">do</span>
|
82
|
+
<span class="constant">Status</span><span class="punct">::</span><span class="constant">NOT_STARTED</span><span class="punct">.</span><span class="ident">class</span><span class="punct">.</span><span class="ident">should</span> <span class="punct">==</span> <span class="constant">Status</span>
|
83
|
+
<span class="keyword">end</span>
|
84
|
+
|
85
|
+
<span class="ident">it</span> <span class="punct">"</span><span class="string">exposes array of values</span><span class="punct">"</span> <span class="keyword">do</span>
|
86
|
+
<span class="constant">Status</span><span class="punct">.</span><span class="ident">values</span><span class="punct">.</span><span class="ident">should</span> <span class="punct">==</span> <span class="punct">[</span><span class="constant">Status</span><span class="punct">::</span><span class="constant">NOT_STARTED</span><span class="punct">,</span> <span class="constant">Status</span><span class="punct">::</span><span class="constant">IN_PROGRESS</span><span class="punct">,</span> <span class="constant">Status</span><span class="punct">::</span><span class="constant">COMPLETE</span><span class="punct">]</span>
|
87
|
+
<span class="keyword">end</span>
|
88
|
+
|
89
|
+
<span class="ident">it</span> <span class="punct">"</span><span class="string">provides an alternative means of declaring values where extra information can be provided for initialization</span><span class="punct">"</span> <span class="keyword">do</span>
|
90
|
+
<span class="constant">Size</span><span class="punct">::</span><span class="constant">Small</span><span class="punct">.</span><span class="ident">description</span><span class="punct">.</span><span class="ident">should</span> <span class="punct">==</span> <span class="punct">"</span><span class="string">Really really tiny</span><span class="punct">"</span>
|
91
|
+
<span class="keyword">end</span>
|
92
|
+
|
93
|
+
<span class="ident">it</span> <span class="punct">"</span><span class="string">enumerates over values</span><span class="punct">"</span> <span class="keyword">do</span>
|
94
|
+
<span class="constant">Status</span><span class="punct">.</span><span class="ident">map</span> <span class="punct">{|</span><span class="ident">s</span><span class="punct">|</span> <span class="ident">s</span><span class="punct">.</span><span class="ident">name</span><span class="punct">}.</span><span class="ident">should</span> <span class="punct">==</span> <span class="punct">%w[</span><span class="string">NOT_STARTED IN_PROGRESS COMPLETE</span><span class="punct">]</span>
|
95
|
+
<span class="keyword">end</span>
|
96
|
+
|
97
|
+
<span class="ident">it</span> <span class="punct">"</span><span class="string">indexes values</span><span class="punct">"</span> <span class="keyword">do</span>
|
98
|
+
<span class="constant">Status</span><span class="punct">[</span><span class="number">2</span><span class="punct">].</span><span class="ident">should</span> <span class="punct">==</span> <span class="constant">Status</span><span class="punct">::</span><span class="constant">COMPLETE</span>
|
99
|
+
<span class="keyword">end</span>
|
100
|
+
|
101
|
+
<span class="ident">it</span> <span class="punct">"</span><span class="string">provides index lookup on values</span><span class="punct">"</span> <span class="keyword">do</span>
|
102
|
+
<span class="constant">Status</span><span class="punct">::</span><span class="constant">IN_PROGRESS</span><span class="punct">.</span><span class="ident">index</span><span class="punct">.</span><span class="ident">should</span> <span class="punct">==</span> <span class="number">1</span>
|
103
|
+
<span class="keyword">end</span>
|
104
|
+
|
105
|
+
<span class="ident">it</span> <span class="punct">"</span><span class="string">provides a reasonable to_s for values</span><span class="punct">"</span> <span class="keyword">do</span>
|
106
|
+
<span class="constant">Status</span><span class="punct">::</span><span class="constant">NOT_STARTED</span><span class="punct">.</span><span class="ident">to_s</span><span class="punct">.</span><span class="ident">should</span> <span class="punct">==</span> <span class="punct">"</span><span class="string">Status::NOT_STARTED</span><span class="punct">"</span>
|
107
|
+
<span class="keyword">end</span>
|
108
|
+
|
109
|
+
<span class="ident">it</span> <span class="punct">"</span><span class="string">makes values comparable</span><span class="punct">"</span> <span class="keyword">do</span>
|
110
|
+
<span class="constant">Status</span><span class="punct">::</span><span class="constant">NOT_STARTED</span><span class="punct">.</span><span class="ident">should</span> <span class="punct"><</span> <span class="constant">Status</span><span class="punct">::</span><span class="constant">COMPLETE</span>
|
111
|
+
<span class="keyword">end</span>
|
112
|
+
|
113
|
+
<span class="ident">it</span> <span class="punct">"</span><span class="string">allows enums to be nested in other modules or classes</span><span class="punct">"</span> <span class="keyword">do</span>
|
114
|
+
<span class="constant">MyNamespace</span><span class="punct">::</span><span class="constant">FooValue</span><span class="punct">::</span><span class="constant">Bar</span><span class="punct">.</span><span class="ident">class</span><span class="punct">.</span><span class="ident">should</span> <span class="punct">==</span> <span class="constant">MyNamespace</span><span class="punct">::</span><span class="constant">FooValue</span>
|
115
|
+
<span class="keyword">end</span>
|
116
|
+
|
117
|
+
<span class="keyword">end</span></pre></p>
|
118
|
+
|
119
|
+
|
120
|
+
<h2>License</h2>
|
121
|
+
|
122
|
+
|
123
|
+
<p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
|
124
|
+
|
125
|
+
|
126
|
+
<h2>Contact</h2>
|
127
|
+
|
128
|
+
|
129
|
+
<p>Renum was created by John D. Hume. Comments are welcome. Send an email to duelin dot markers at gmail or <a href="http://elhumidor.blogspot.com/">contact me via my blog</a>.</p>
|
130
|
+
<p class="coda">
|
131
|
+
<a href="http://elhumidor.blogspot.com/">John D. Hume</a>, 25th January 2008<br>
|
132
|
+
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
133
|
+
</p>
|
134
|
+
</div>
|
135
|
+
|
136
|
+
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
|
137
|
+
</script>
|
138
|
+
<script type="text/javascript">
|
139
|
+
_uacct = "UA-2039575-4";
|
140
|
+
urchinTracker();
|
141
|
+
</script>
|
142
|
+
</body>
|
143
|
+
</html>
|
data/website/index.txt
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
h1. renum
|
2
|
+
|
3
|
+
Renum provides a readable but terse enum facility for Ruby. Enums are sometimes called object constants and are analogous to the type-safe enum pattern in Java, though obviously Ruby's flexibility means there's no such thing as type-safety.
|
4
|
+
|
5
|
+
h2. Installing
|
6
|
+
|
7
|
+
<pre syntax="ruby">sudo gem install renum</pre>
|
8
|
+
|
9
|
+
h2. Demonstration of usage
|
10
|
+
|
11
|
+
Renum allows you to do things like this:
|
12
|
+
|
13
|
+
<pre syntax="ruby">enum :Status, %w( NOT_STARTED IN_PROGRESS COMPLETE )
|
14
|
+
|
15
|
+
enum :Size do
|
16
|
+
Small("Really really tiny")
|
17
|
+
Medium("Sort of in the middle")
|
18
|
+
Large("Quite big")
|
19
|
+
|
20
|
+
attr_reader :description
|
21
|
+
|
22
|
+
def init description
|
23
|
+
@description = description
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module MyNamespace
|
28
|
+
enum :FooValue, [ :Bar, :Baz, :Bat ]
|
29
|
+
end</pre>
|
30
|
+
|
31
|
+
Giving you something that satisfies this spec, plus a bit more:
|
32
|
+
|
33
|
+
<pre syntax="ruby">describe "enum" do
|
34
|
+
|
35
|
+
it "creates a class for the value type" do
|
36
|
+
Status.class.should == Class
|
37
|
+
end
|
38
|
+
|
39
|
+
it "makes each value an instance of the value type" do
|
40
|
+
Status::NOT_STARTED.class.should == Status
|
41
|
+
end
|
42
|
+
|
43
|
+
it "exposes array of values" do
|
44
|
+
Status.values.should == [Status::NOT_STARTED, Status::IN_PROGRESS, Status::COMPLETE]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "provides an alternative means of declaring values where extra information can be provided for initialization" do
|
48
|
+
Size::Small.description.should == "Really really tiny"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "enumerates over values" do
|
52
|
+
Status.map {|s| s.name}.should == %w[NOT_STARTED IN_PROGRESS COMPLETE]
|
53
|
+
end
|
54
|
+
|
55
|
+
it "indexes values" do
|
56
|
+
Status[2].should == Status::COMPLETE
|
57
|
+
end
|
58
|
+
|
59
|
+
it "provides index lookup on values" do
|
60
|
+
Status::IN_PROGRESS.index.should == 1
|
61
|
+
end
|
62
|
+
|
63
|
+
it "provides a reasonable to_s for values" do
|
64
|
+
Status::NOT_STARTED.to_s.should == "Status::NOT_STARTED"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "makes values comparable" do
|
68
|
+
Status::NOT_STARTED.should < Status::COMPLETE
|
69
|
+
end
|
70
|
+
|
71
|
+
it "allows enums to be nested in other modules or classes" do
|
72
|
+
MyNamespace::FooValue::Bar.class.should == MyNamespace::FooValue
|
73
|
+
end
|
74
|
+
|
75
|
+
end</pre>
|
76
|
+
|
77
|
+
h2. License
|
78
|
+
|
79
|
+
This code is free to use under the terms of the MIT license.
|
80
|
+
|
81
|
+
h2. Contact
|
82
|
+
|
83
|
+
Renum was created by John D. Hume. Comments are welcome. Send an email to duelin dot markers at gmail or "contact me via my blog":http://elhumidor.blogspot.com/.
|
84
|
+
|