enumerate_it 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -0
- data/VERSION +1 -1
- data/enumerate_it.gemspec +3 -3
- data/lib/enumerate_it.rb +11 -1
- data/spec/enumerate_it_spec.rb +18 -0
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -82,6 +82,8 @@ or not.
|
|
82
82
|
has_enumeration_for :relationship_status, :with => RelationshipStatus
|
83
83
|
end
|
84
84
|
|
85
|
+
The :with option is not required. If you ommit it, EnumerateIt will try to load an enumeration class based on the camelized attribute name.
|
86
|
+
|
85
87
|
This will create:
|
86
88
|
|
87
89
|
* A humanized description for the values of the enumerated attribute:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/enumerate_it.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{enumerate_it}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["
|
12
|
-
s.date = %q{2010-
|
11
|
+
s.authors = ["C\303\241ssio Marques"]
|
12
|
+
s.date = %q{2010-04-10}
|
13
13
|
s.description = %q{Have a legacy database and need some enumerations in your models to match those stupid '4 rows/2 columns' tables with foreign keys and stop doing joins just to fetch a simple description? Or maybe use some integers instead of strings as the code for each value of your enumerations? Here's EnumerateIt.}
|
14
14
|
s.email = %q{cassiommc@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/enumerate_it.rb
CHANGED
@@ -82,6 +82,9 @@
|
|
82
82
|
# has_enumeration_for :relationship_status, :with => RelationshipStatus
|
83
83
|
# end
|
84
84
|
#
|
85
|
+
# The :with option is not required. If you ommit it, EnumerateIt will try to load an
|
86
|
+
# enumeration class based on the camelized attribute name.
|
87
|
+
#
|
85
88
|
# This will create:
|
86
89
|
#
|
87
90
|
# - A humanized description for the values of the enumerated attribute:
|
@@ -194,7 +197,8 @@ module EnumerateIt
|
|
194
197
|
end
|
195
198
|
|
196
199
|
module ClassMethods
|
197
|
-
def has_enumeration_for(attribute, options)
|
200
|
+
def has_enumeration_for(attribute, options = {})
|
201
|
+
define_enumeration_class attribute, options
|
198
202
|
if self.respond_to? :validates_inclusion_of
|
199
203
|
validates_inclusion_of attribute, :in => options[:with].list, :allow_blank => true
|
200
204
|
end
|
@@ -223,6 +227,12 @@ module EnumerateIt
|
|
223
227
|
end
|
224
228
|
end
|
225
229
|
end
|
230
|
+
|
231
|
+
def define_enumeration_class(attribute, options)
|
232
|
+
if options[:with].blank?
|
233
|
+
options[:with] = attribute.to_s.camelize.constantize
|
234
|
+
end
|
235
|
+
end
|
226
236
|
end
|
227
237
|
|
228
238
|
def self.included(receiver)
|
data/spec/enumerate_it_spec.rb
CHANGED
@@ -60,6 +60,24 @@ describe EnumerateIt do
|
|
60
60
|
@target.foobar_humanize.should == 'Value Two'
|
61
61
|
end
|
62
62
|
end
|
63
|
+
|
64
|
+
context "without passing the enumeration class" do
|
65
|
+
before :each do
|
66
|
+
class FooBar
|
67
|
+
include EnumerateIt
|
68
|
+
attr_accessor :test_enumeration
|
69
|
+
has_enumeration_for :test_enumeration
|
70
|
+
def initialize(test_enumeration_value)
|
71
|
+
@test_enumeration = test_enumeration_value
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should find out which enumeration class to use" do
|
77
|
+
target = FooBar.new(TestEnumeration::VALUE_1)
|
78
|
+
target.test_enumeration_humanize.should == 'Hey, I am 1!'
|
79
|
+
end
|
80
|
+
end
|
63
81
|
end
|
64
82
|
|
65
83
|
context "using the option :create_helpers option" do
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 4
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.4.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "C\xC3\xA1ssio Marques"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-04-10 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|