rap_enum 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rap_enum.rb +3 -3
- data/test/test_rap_enum.rb +31 -0
- metadata +5 -4
data/lib/rap_enum.rb
CHANGED
@@ -28,11 +28,11 @@ module RapEnum
|
|
28
28
|
end
|
29
29
|
|
30
30
|
|
31
|
-
class <<
|
31
|
+
class << RapEnum
|
32
32
|
|
33
33
|
def included(klass)
|
34
34
|
super
|
35
|
-
klass.extend(
|
35
|
+
klass.extend(RapEnumClassMethods)
|
36
36
|
klass.private_class_method :new, :allocate, :create
|
37
37
|
klass.instance_eval do
|
38
38
|
@finder_attrs = [:id, :aliases] # Attribute names to use to find keys for the find index.
|
@@ -41,7 +41,7 @@ class << RapEnumerable
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
module
|
44
|
+
module RapEnumClassMethods
|
45
45
|
|
46
46
|
attr_reader :finder_attrs
|
47
47
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
require 'rap_enum'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TestRapEnum < Test::Unit::TestCase
|
6
|
+
|
7
|
+
class Gender
|
8
|
+
include RapEnum
|
9
|
+
find_by :name
|
10
|
+
|
11
|
+
create(:id => 1, :name => 'male', :aliases => ['m', 'man'])
|
12
|
+
create(:id => 2, :name => 'female', :aliases => ['f', 'w', 'woman'])
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def test_find
|
17
|
+
m = Gender.find('m')
|
18
|
+
assert m
|
19
|
+
assert_equal m, Gender.find('male')
|
20
|
+
assert m.male?
|
21
|
+
assert m.m?
|
22
|
+
assert m.man?
|
23
|
+
assert !m.f?
|
24
|
+
assert !m.female?
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_all
|
28
|
+
assert_equal 2, Gender.all.size
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rap_enum
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-10-
|
6
|
+
version: 0.0.2
|
7
|
+
date: 2007-10-12 00:00:00 -07:00
|
8
8
|
summary: Module to facilitate the creation of enumeration classes.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -30,9 +30,10 @@ authors:
|
|
30
30
|
- Jeremy Lizt
|
31
31
|
files:
|
32
32
|
- lib/rap_enum.rb
|
33
|
+
- test/test_rap_enum.rb
|
33
34
|
- README
|
34
|
-
test_files:
|
35
|
-
|
35
|
+
test_files:
|
36
|
+
- test/test_rap_enum.rb
|
36
37
|
rdoc_options: []
|
37
38
|
|
38
39
|
extra_rdoc_files:
|