duelinmarkers-renum 1.0.2 → 1.1.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.
- data/README.textile +19 -0
- data/VERSION +1 -1
- data/lib/renum/enumerated_value_type_factory.rb +4 -3
- data/renum.gemspec +46 -0
- data/spec/renum_spec.rb +70 -32
- metadata +3 -4
- data/License.txt +0 -20
- data/lib/renum/version.rb +0 -9
data/README.textile
CHANGED
@@ -115,6 +115,25 @@ h2. License
|
|
115
115
|
|
116
116
|
This code is free to use under the terms of the MIT license.
|
117
117
|
|
118
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
119
|
+
a copy of this software and associated documentation files (the
|
120
|
+
"Software"), to deal in the Software without restriction, including
|
121
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
122
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
123
|
+
permit persons to whom the Software is furnished to do so, subject to
|
124
|
+
the following conditions:
|
125
|
+
|
126
|
+
The above copyright notice and this permission notice shall be
|
127
|
+
included in all copies or substantial portions of the Software.
|
128
|
+
|
129
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
130
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
131
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
132
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
133
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
134
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
135
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
136
|
+
|
118
137
|
h2. Contact
|
119
138
|
|
120
139
|
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/.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
@@ -18,9 +18,10 @@ module Renum
|
|
18
18
|
setup_for_definition_in_block(klass) if values == :defined_in_block
|
19
19
|
klass.class_eval &block if block_given?
|
20
20
|
if values == :defined_in_block
|
21
|
-
klass.block_defined_values.each do |value_name, init_args|
|
21
|
+
klass.block_defined_values.each do |value_name, init_args, instance_block|
|
22
22
|
value = klass.new(value_name)
|
23
23
|
klass.const_set(value_name, value)
|
24
|
+
value.instance_eval &instance_block if instance_block
|
24
25
|
value.init *init_args if init_args.any?
|
25
26
|
end
|
26
27
|
teardown_from_definition_in_block(klass)
|
@@ -37,8 +38,8 @@ module Renum
|
|
37
38
|
@block_defined_values ||= []
|
38
39
|
end
|
39
40
|
|
40
|
-
def self.method_missing value_name, *init_args
|
41
|
-
block_defined_values << [value_name, init_args]
|
41
|
+
def self.method_missing value_name, *init_args, &instance_block
|
42
|
+
block_defined_values << [value_name, init_args, instance_block]
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
data/renum.gemspec
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{renum}
|
5
|
+
s.version = "1.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["John Hume"]
|
9
|
+
s.date = %q{2009-07-07}
|
10
|
+
s.description = %q{provides a readable but terse enum facility for Ruby}
|
11
|
+
s.email = %q{duelin.markers@gmail.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"README.textile"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
"README.textile",
|
17
|
+
"Rakefile",
|
18
|
+
"VERSION",
|
19
|
+
"lib/renum.rb",
|
20
|
+
"lib/renum/enumerated_value.rb",
|
21
|
+
"lib/renum/enumerated_value_type_factory.rb",
|
22
|
+
"renum.gemspec",
|
23
|
+
"spec/renum_spec.rb",
|
24
|
+
"spec/spec_helper.rb"
|
25
|
+
]
|
26
|
+
s.has_rdoc = true
|
27
|
+
s.homepage = %q{http://github.com/duelinmarkers/renum}
|
28
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
29
|
+
s.require_paths = ["lib"]
|
30
|
+
s.rubygems_version = %q{1.3.1}
|
31
|
+
s.summary = %q{provides a readable but terse enum facility for Ruby}
|
32
|
+
s.test_files = [
|
33
|
+
"spec/renum_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
|
37
|
+
if s.respond_to? :specification_version then
|
38
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
39
|
+
s.specification_version = 2
|
40
|
+
|
41
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
42
|
+
else
|
43
|
+
end
|
44
|
+
else
|
45
|
+
end
|
46
|
+
end
|
data/spec/renum_spec.rb
CHANGED
@@ -2,34 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
enum :Status, [ :NOT_STARTED, :IN_PROGRESS, :COMPLETE ]
|
4
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
5
|
describe "basic enum" do
|
34
6
|
|
35
7
|
it "creates a class for the value type" do
|
@@ -67,18 +39,46 @@ describe "basic enum" do
|
|
67
39
|
end
|
68
40
|
end
|
69
41
|
|
42
|
+
module MyNamespace
|
43
|
+
enum :FooValue, %w( Bar Baz Bat )
|
44
|
+
end
|
45
|
+
|
70
46
|
describe "nested enum" do
|
71
47
|
it "is namespaced in the containing module or class" do
|
72
48
|
MyNamespace::FooValue::Bar.class.should == MyNamespace::FooValue
|
73
49
|
end
|
74
50
|
end
|
75
51
|
|
52
|
+
enum :Color, [ :RED, :GREEN, :BLUE ] do
|
53
|
+
def abbr
|
54
|
+
name[0..0]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
76
58
|
describe "enum with a block" do
|
77
59
|
it "can define additional instance methods" do
|
78
60
|
Color::RED.abbr.should == "R"
|
79
61
|
end
|
80
62
|
end
|
81
63
|
|
64
|
+
enum :Size do
|
65
|
+
Small("Really really tiny")
|
66
|
+
Medium("Sort of in the middle")
|
67
|
+
Large("Quite big")
|
68
|
+
|
69
|
+
attr_reader :description
|
70
|
+
|
71
|
+
def init description
|
72
|
+
@description = description
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
enum :HairColor do
|
77
|
+
BLONDE()
|
78
|
+
BRUNETTE()
|
79
|
+
RED()
|
80
|
+
end
|
81
|
+
|
82
82
|
describe "enum with no values array and values declared in the block" do
|
83
83
|
it "provides an alternative means of declaring values where extra information can be provided for initialization" do
|
84
84
|
Size::Small.description.should == "Really really tiny"
|
@@ -97,12 +97,50 @@ describe "enum with no values array and values declared in the block" do
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
|
101
|
-
|
102
|
-
|
100
|
+
enum :Rating do
|
101
|
+
NotRated()
|
102
|
+
|
103
|
+
ThumbsDown do
|
104
|
+
def description
|
105
|
+
"real real bad"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
ThumbsUp do
|
110
|
+
def description
|
111
|
+
"so so good"
|
112
|
+
end
|
113
|
+
|
114
|
+
def thumbs_up_only_method
|
115
|
+
"this method is only defined on ThumbsUp"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def description
|
120
|
+
raise NotImplementedError
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "an enum with instance-specific method definitions" do
|
125
|
+
it "allows each instance to have its own behavior" do
|
126
|
+
Rating::ThumbsDown.description.should == "real real bad"
|
127
|
+
Rating::ThumbsUp.description.should == "so so good"
|
128
|
+
end
|
129
|
+
|
130
|
+
it "uses the implementation given at the top level if no alternate definition is given for an instance" do
|
131
|
+
lambda { Rating::NotRated.description }.should raise_error(NotImplementedError)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "allows definition of a method on just one instance" do
|
135
|
+
Rating::ThumbsUp.thumbs_up_only_method.should == "this method is only defined on ThumbsUp"
|
136
|
+
lambda { Rating::NotRated.thumbs_up_only_method }.should raise_error(NoMethodError)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "<=> comparison issue that at one time was causing segfaults on MRI" do
|
103
141
|
it "doesn't cause the ruby process to bomb!" do
|
104
142
|
Color::RED.should < Color::GREEN
|
105
143
|
Color::RED.should_not > Color::GREEN
|
106
144
|
Color::RED.should < Color::BLUE
|
107
145
|
end
|
108
|
-
end
|
146
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duelinmarkers-renum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hume
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-07 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,14 +22,13 @@ extensions: []
|
|
22
22
|
extra_rdoc_files:
|
23
23
|
- README.textile
|
24
24
|
files:
|
25
|
-
- License.txt
|
26
25
|
- README.textile
|
27
26
|
- Rakefile
|
28
27
|
- VERSION
|
29
28
|
- lib/renum.rb
|
30
29
|
- lib/renum/enumerated_value.rb
|
31
30
|
- lib/renum/enumerated_value_type_factory.rb
|
32
|
-
-
|
31
|
+
- renum.gemspec
|
33
32
|
- spec/renum_spec.rb
|
34
33
|
- spec/spec_helper.rb
|
35
34
|
has_rdoc: true
|
data/License.txt
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2007 John D. Hume
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|