enumeration 1.1.0 → 1.2.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/Gemfile +3 -0
- data/Gemfile.lock +7 -11
- data/Rakefile +3 -3
- data/enumeration.gemspec +1 -1
- data/lib/enumeration.rb +1 -1
- data/lib/enumeration/collection.rb +1 -1
- data/lib/enumeration/version.rb +1 -1
- data/test/api_test.rb +15 -0
- data/test/collection_test.rb +62 -64
- data/test/helper.rb +6 -3
- data/test/irb.rb +10 -0
- data/test/list_enum_test.rb +38 -36
- data/test/map_enum_test.rb +62 -60
- metadata +18 -20
- data/test/api__test.rb +0 -14
- data/test/env.rb +0 -10
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,25 +1,21 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
enumeration (1.
|
4
|
+
enumeration (1.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
shoulda (2.11.3)
|
14
|
-
test-belt (0.2.1)
|
15
|
-
kelredd-useful (~> 0.4.0)
|
16
|
-
leftright (~> 0.9.0)
|
17
|
-
shoulda (~> 2.11)
|
9
|
+
ansi (1.3.0)
|
10
|
+
assert (0.2.1)
|
11
|
+
ansi (~> 1.3)
|
12
|
+
rake (0.9.2)
|
18
13
|
|
19
14
|
PLATFORMS
|
20
15
|
ruby
|
21
16
|
|
22
17
|
DEPENDENCIES
|
18
|
+
assert (~> 0.2.0)
|
23
19
|
bundler (~> 1.0)
|
24
20
|
enumeration!
|
25
|
-
|
21
|
+
rake (~> 0.9.2)
|
data/Rakefile
CHANGED
data/enumeration.gemspec
CHANGED
data/lib/enumeration.rb
CHANGED
data/lib/enumeration/version.rb
CHANGED
data/test/api_test.rb
ADDED
data/test/collection_test.rb
CHANGED
@@ -1,86 +1,84 @@
|
|
1
|
-
require "
|
1
|
+
require "assert"
|
2
|
+
|
2
3
|
require "enumeration/collection"
|
3
4
|
|
4
|
-
class CollectionAPITest <
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
should "only be created from Arrays or Hashes" do
|
12
|
-
assert_raises ArgumentError do
|
13
|
-
Enumeration::Collection.new('stuff')
|
14
|
-
end
|
15
|
-
assert_nothing_raised do
|
16
|
-
Enumeration::Collection.new([])
|
17
|
-
Enumeration::Collection.new({})
|
18
|
-
end
|
19
|
-
end
|
5
|
+
class CollectionAPITest < Assert::Context
|
6
|
+
desc "Enumeration collection"
|
7
|
+
subject { Enumeration::Collection.new([]) }
|
8
|
+
|
9
|
+
should have_reader :data
|
10
|
+
should have_instance_methods :set, :map?, :list?, :[]
|
20
11
|
|
12
|
+
should "only be created from Arrays or Hashes" do
|
13
|
+
assert_raises ArgumentError do
|
14
|
+
Enumeration::Collection.new('stuff')
|
15
|
+
end
|
16
|
+
assert_nothing_raised do
|
17
|
+
Enumeration::Collection.new([])
|
18
|
+
Enumeration::Collection.new({})
|
19
|
+
end
|
21
20
|
end
|
22
|
-
end
|
23
21
|
|
24
|
-
|
25
|
-
context "List collection" do
|
26
|
-
subject { Enumeration::Collection.new(['one', 'two', 'three']) }
|
22
|
+
end
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
24
|
+
class ListCollectionTest < Assert::Context
|
25
|
+
desc "List collection"
|
26
|
+
subject { Enumeration::Collection.new(['one', 'two', 'three']) }
|
32
27
|
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
should "be a list" do
|
29
|
+
assert_equal true, subject.list?
|
30
|
+
assert_equal false, subject.map?
|
31
|
+
end
|
36
32
|
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
should "know it's data" do
|
34
|
+
assert_equal ['one', 'two', 'three'], subject.data
|
35
|
+
end
|
40
36
|
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
should "know it's set" do
|
38
|
+
assert_equal ['one', 'two', 'three'], subject.set
|
39
|
+
end
|
44
40
|
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
should "lookup value by key" do
|
42
|
+
assert_equal 'two', subject['two']
|
43
|
+
end
|
48
44
|
|
45
|
+
should "lookup key by value" do
|
46
|
+
assert_equal 'three', subject.key('three')
|
49
47
|
end
|
50
|
-
end
|
51
48
|
|
52
|
-
|
53
|
-
context "Map collection" do
|
54
|
-
subject { Enumeration::Collection.new({ :one => 1, :two => 2, :three => 3}) }
|
49
|
+
end
|
55
50
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
51
|
+
class MapCollectionTest < Assert::Context
|
52
|
+
desc "Map collection"
|
53
|
+
subject { Enumeration::Collection.new({ :one => 1, :two => 2, :three => 3}) }
|
60
54
|
|
61
|
-
|
62
|
-
|
63
|
-
|
55
|
+
should "be a map" do
|
56
|
+
assert_equal true, subject.map?
|
57
|
+
assert_equal false, subject.list?
|
58
|
+
end
|
64
59
|
|
65
|
-
|
66
|
-
|
67
|
-
|
60
|
+
should "know it's data" do
|
61
|
+
assert_equal({:one=>1,:two=>2,:three=>3}, subject.data)
|
62
|
+
end
|
68
63
|
|
69
|
-
|
70
|
-
|
71
|
-
|
64
|
+
should "know it's set" do
|
65
|
+
[:one, :two, :three].each{|n| assert subject.set.include?(n)}
|
66
|
+
end
|
72
67
|
|
73
|
-
|
74
|
-
|
75
|
-
|
68
|
+
should "lookup value by key" do
|
69
|
+
assert_equal 2, subject[:two]
|
70
|
+
end
|
76
71
|
|
77
|
-
|
78
|
-
|
79
|
-
|
72
|
+
should "lookup value by value" do
|
73
|
+
assert_equal 2, subject[2]
|
74
|
+
end
|
80
75
|
|
81
|
-
|
82
|
-
|
83
|
-
|
76
|
+
should "lookup key by value" do
|
77
|
+
assert_equal :two, subject.key(2)
|
78
|
+
end
|
84
79
|
|
80
|
+
should "lookup key by key" do
|
81
|
+
assert_equal :two, subject.key(:two)
|
85
82
|
end
|
86
|
-
|
83
|
+
|
84
|
+
end
|
data/test/helper.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
1
|
+
# this file is automatically required in when you require 'assert'
|
2
|
+
# put test helpers here
|
3
|
+
|
4
|
+
# add root dir to the load path
|
5
|
+
$LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
|
6
|
+
|
4
7
|
require 'test/thing'
|
data/test/irb.rb
ADDED
data/test/list_enum_test.rb
CHANGED
@@ -1,49 +1,51 @@
|
|
1
|
-
require "
|
1
|
+
require "assert"
|
2
2
|
|
3
|
-
|
4
|
-
context "instance" do
|
3
|
+
require 'enumeration'
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
Thing.send :include, Enumeration
|
9
|
-
Thing.send(:enum, :word, %w{aye bee see})
|
10
|
-
end
|
5
|
+
class ListEnumTest < Assert::Context
|
6
|
+
desc "instance"
|
11
7
|
|
12
|
-
|
13
|
-
|
8
|
+
subject { @a_thing }
|
9
|
+
before do
|
10
|
+
Thing.send :include, Enumeration
|
11
|
+
Thing.send(:enum, :word, %w{aye bee see})
|
12
|
+
@a_thing = Thing.new
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
Thing.word
|
18
|
-
end
|
19
|
-
end
|
15
|
+
should have_class_methods :word_set, :word_collection
|
16
|
+
should have_accessor :word
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
assert_kind_of ::Array, words
|
25
|
-
assert !words.empty?
|
26
|
-
assert_equal 3, words.size
|
27
|
-
assert_equal ['aye', 'bee', 'see'], Thing.word_set
|
28
|
-
assert_equal Thing.word_set, Thing.word_collection
|
18
|
+
should "not have a class level lookup method" do
|
19
|
+
assert_raises NoMethodError do
|
20
|
+
Thing.word
|
29
21
|
end
|
22
|
+
end
|
30
23
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
24
|
+
should "provide class level access to the enum set" do
|
25
|
+
words = Thing.word_set
|
26
|
+
assert words
|
27
|
+
assert_kind_of ::Array, words
|
28
|
+
assert !words.empty?
|
29
|
+
assert_equal 3, words.size
|
30
|
+
assert_equal ['aye', 'bee', 'see'], Thing.word_set
|
31
|
+
assert_equal Thing.word_set, Thing.word_collection
|
32
|
+
end
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
should "write a value and read the value" do
|
35
|
+
subject.word = "see"
|
36
|
+
assert_equal "see", subject.word
|
37
|
+
end
|
40
38
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
39
|
+
should "write a value and read the key" do
|
40
|
+
subject.word = "see"
|
41
|
+
assert_equal "see", subject.word_key
|
42
|
+
end
|
46
43
|
|
44
|
+
should "write nil for values that aren't in the enum" do
|
45
|
+
subject.word = "bady-bad"
|
46
|
+
assert_equal nil, subject.word
|
47
|
+
assert_equal nil, subject.word_key
|
47
48
|
end
|
49
|
+
|
48
50
|
end
|
49
51
|
|
data/test/map_enum_test.rb
CHANGED
@@ -1,63 +1,65 @@
|
|
1
|
-
require "
|
2
|
-
|
3
|
-
class MapEnumTest < Test::Unit::TestCase
|
4
|
-
context "instance" do
|
5
|
-
|
6
|
-
subject { Thing.new }
|
7
|
-
before do
|
8
|
-
Thing.send :include, Enumeration
|
9
|
-
Thing.send(:enum, :stuff, {
|
10
|
-
:a => "aye",
|
11
|
-
:b => "bee",
|
12
|
-
:c => "see"
|
13
|
-
})
|
14
|
-
end
|
15
|
-
|
16
|
-
should_have_class_methods :stuff, :stuff_set, :stuff_collection
|
17
|
-
should_have_accessor :stuff
|
18
|
-
|
19
|
-
should "provide class level access to the enum set" do
|
20
|
-
stuffs = Thing.stuff_set
|
21
|
-
assert stuffs
|
22
|
-
assert_kind_of ::Array, stuffs
|
23
|
-
assert !stuffs.empty?
|
24
|
-
assert_equal 3, stuffs.size
|
25
|
-
[:a, :b, :c].each{|t| assert Thing.stuff_set.include?(t)}
|
26
|
-
assert_equal({:a=>'aye',:b=>'bee',:c=>'see'}, Thing.stuff_collection)
|
27
|
-
end
|
28
|
-
|
29
|
-
should "provide class level lookup of the enum" do
|
30
|
-
assert_equal "aye", Thing.stuff(:a)
|
31
|
-
end
|
32
|
-
|
33
|
-
should "write a key and read the value and key" do
|
34
|
-
subject.stuff = :b
|
35
|
-
assert_equal "bee", subject.stuff
|
36
|
-
assert_equal :b, subject.stuff_key
|
37
|
-
end
|
38
|
-
|
39
|
-
should "write a value and read the value" do
|
40
|
-
subject.stuff = "see"
|
41
|
-
assert_equal "see", subject.stuff
|
42
|
-
assert_equal :c, subject.stuff_key
|
43
|
-
end
|
44
|
-
|
45
|
-
should "not read keys like you would values" do
|
46
|
-
subject.stuff = :c
|
47
|
-
assert_not_equal :c, subject.stuff
|
48
|
-
end
|
49
|
-
|
50
|
-
should "write nil for keys that aren't in the enum" do
|
51
|
-
subject.stuff = :bad
|
52
|
-
assert_equal nil, subject.stuff
|
53
|
-
assert_equal nil, subject.stuff_key
|
54
|
-
end
|
55
|
-
|
56
|
-
should "write nil for values that aren't in the enum" do
|
57
|
-
subject.stuff = "bady-bad"
|
58
|
-
assert_equal nil, subject.stuff
|
59
|
-
assert_equal nil, subject.stuff_key
|
60
|
-
end
|
1
|
+
require "assert"
|
61
2
|
|
3
|
+
require 'enumeration'
|
4
|
+
|
5
|
+
class MapEnumTest < Assert::Context
|
6
|
+
desc "instance"
|
7
|
+
|
8
|
+
subject { @a_thing }
|
9
|
+
before do
|
10
|
+
Thing.send :include, Enumeration
|
11
|
+
Thing.send(:enum, :stuff, {
|
12
|
+
:a => "aye",
|
13
|
+
:b => "bee",
|
14
|
+
:c => "see"
|
15
|
+
})
|
16
|
+
@a_thing = Thing.new
|
17
|
+
end
|
18
|
+
|
19
|
+
should have_class_methods :stuff, :stuff_set, :stuff_collection
|
20
|
+
should have_accessor :stuff
|
21
|
+
|
22
|
+
should "provide class level access to the enum set" do
|
23
|
+
stuffs = Thing.stuff_set
|
24
|
+
assert stuffs
|
25
|
+
assert_kind_of ::Array, stuffs
|
26
|
+
assert !stuffs.empty?
|
27
|
+
assert_equal 3, stuffs.size
|
28
|
+
[:a, :b, :c].each{|t| assert Thing.stuff_set.include?(t)}
|
29
|
+
assert_equal({:a=>'aye',:b=>'bee',:c=>'see'}, Thing.stuff_collection)
|
30
|
+
end
|
31
|
+
|
32
|
+
should "provide class level lookup of the enum" do
|
33
|
+
assert_equal "aye", Thing.stuff(:a)
|
34
|
+
end
|
35
|
+
|
36
|
+
should "write a key and read the value and key" do
|
37
|
+
subject.stuff = :b
|
38
|
+
assert_equal "bee", subject.stuff
|
39
|
+
assert_equal :b, subject.stuff_key
|
62
40
|
end
|
41
|
+
|
42
|
+
should "write a value and read the value" do
|
43
|
+
subject.stuff = "see"
|
44
|
+
assert_equal "see", subject.stuff
|
45
|
+
assert_equal :c, subject.stuff_key
|
46
|
+
end
|
47
|
+
|
48
|
+
should "not read keys like you would values" do
|
49
|
+
subject.stuff = :c
|
50
|
+
assert_not_equal :c, subject.stuff
|
51
|
+
end
|
52
|
+
|
53
|
+
should "write nil for keys that aren't in the enum" do
|
54
|
+
subject.stuff = :bad
|
55
|
+
assert_equal nil, subject.stuff
|
56
|
+
assert_equal nil, subject.stuff_key
|
57
|
+
end
|
58
|
+
|
59
|
+
should "write nil for values that aren't in the enum" do
|
60
|
+
subject.stuff = "bady-bad"
|
61
|
+
assert_equal nil, subject.stuff
|
62
|
+
assert_equal nil, subject.stuff_key
|
63
|
+
end
|
64
|
+
|
63
65
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumeration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly D. Redding
|
@@ -15,12 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-08-22 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
|
-
name: bundler
|
23
21
|
prerelease: false
|
22
|
+
type: :development
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
26
25
|
requirements:
|
@@ -31,23 +30,23 @@ dependencies:
|
|
31
30
|
- 1
|
32
31
|
- 0
|
33
32
|
version: "1.0"
|
34
|
-
|
33
|
+
name: bundler
|
35
34
|
version_requirements: *id001
|
36
35
|
- !ruby/object:Gem::Dependency
|
37
|
-
name: test-belt
|
38
36
|
prerelease: false
|
37
|
+
type: :development
|
39
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
40
|
requirements:
|
42
|
-
- -
|
41
|
+
- - ~>
|
43
42
|
- !ruby/object:Gem::Version
|
44
|
-
hash:
|
43
|
+
hash: 23
|
45
44
|
segments:
|
46
45
|
- 0
|
47
46
|
- 2
|
48
|
-
-
|
49
|
-
version: 0.2.
|
50
|
-
|
47
|
+
- 0
|
48
|
+
version: 0.2.0
|
49
|
+
name: assert
|
51
50
|
version_requirements: *id002
|
52
51
|
description: add enumerated value attributes to your ruby classes
|
53
52
|
email:
|
@@ -68,14 +67,13 @@ files:
|
|
68
67
|
- lib/enumeration.rb
|
69
68
|
- lib/enumeration/collection.rb
|
70
69
|
- lib/enumeration/version.rb
|
71
|
-
- test/
|
70
|
+
- test/api_test.rb
|
72
71
|
- test/collection_test.rb
|
73
|
-
- test/env.rb
|
74
72
|
- test/helper.rb
|
73
|
+
- test/irb.rb
|
75
74
|
- test/list_enum_test.rb
|
76
75
|
- test/map_enum_test.rb
|
77
76
|
- test/thing.rb
|
78
|
-
has_rdoc: true
|
79
77
|
homepage: http://github.com/kelredd/enumeration
|
80
78
|
licenses: []
|
81
79
|
|
@@ -105,15 +103,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
103
|
requirements: []
|
106
104
|
|
107
105
|
rubyforge_project:
|
108
|
-
rubygems_version: 1.
|
106
|
+
rubygems_version: 1.8.8
|
109
107
|
signing_key:
|
110
108
|
specification_version: 3
|
111
109
|
summary: add enumerated value attributes to your ruby classes
|
112
110
|
test_files:
|
113
|
-
- test/
|
111
|
+
- test/api_test.rb
|
114
112
|
- test/collection_test.rb
|
115
|
-
- test/env.rb
|
116
113
|
- test/helper.rb
|
114
|
+
- test/irb.rb
|
117
115
|
- test/list_enum_test.rb
|
118
116
|
- test/map_enum_test.rb
|
119
117
|
- test/thing.rb
|
data/test/api__test.rb
DELETED
data/test/env.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# Add test and lib paths to the $LOAD_PATH
|
2
|
-
[ File.dirname(__FILE__),
|
3
|
-
File.join(File.dirname(__FILE__), '..', 'lib')
|
4
|
-
].each do |path|
|
5
|
-
full_path = File.expand_path(path)
|
6
|
-
$LOAD_PATH.unshift(full_path) unless $LOAD_PATH.include?(full_path)
|
7
|
-
end
|
8
|
-
|
9
|
-
require 'enumeration'
|
10
|
-
|