enumerate_it 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -0
- data/VERSION +1 -1
- data/enumerate_it.gemspec +2 -2
- data/lib/enumerate_it.rb +8 -0
- data/spec/enumerate_it_spec.rb +6 -0
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -66,6 +66,10 @@ This will create some nice stuff:
|
|
66
66
|
|
67
67
|
RelationshipStatus.to_a # [["Divorced", 4],["Married", 2],["Single", 1],["Widow", 3]]
|
68
68
|
|
69
|
+
* You can retrive a list with values for a group of enumeration constants.
|
70
|
+
|
71
|
+
RelationshipStatus.valus_for %w(MARRIED SINGLE) # [2, 1]
|
72
|
+
|
69
73
|
* You can manipulate the hash used to create the enumeration:
|
70
74
|
|
71
75
|
RelationshipStatus.enumeration # returns the exact hash used to define the enumeration
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.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.7.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["C\303\241ssio Marques"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-08}
|
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
@@ -66,6 +66,10 @@
|
|
66
66
|
#
|
67
67
|
# RelationshipStatus.to_a # [["Divorced", 4],["Married", 2],["Single", 1],["Widow", 3]]
|
68
68
|
#
|
69
|
+
# You can retrive a list with values for a group of enumeration constants
|
70
|
+
#
|
71
|
+
# RelationshipStatus.valus_for %w(MARRIED SINGLE) # [2, 1]
|
72
|
+
#
|
69
73
|
# - You can manipulate the has used to create the enumeration:
|
70
74
|
#
|
71
75
|
# RelationshipStatus.enumeration # returns the exact hash used to define the enumeration
|
@@ -200,6 +204,10 @@ module EnumerateIt
|
|
200
204
|
def self.to_a
|
201
205
|
@@registered_enumerations[self].values.map {|value| [translate(value[1]), value[0]] }.sort_by { |value| value[0] }
|
202
206
|
end
|
207
|
+
|
208
|
+
def self.values_for(values)
|
209
|
+
values.map { |v| self.const_get(v.to_sym) }
|
210
|
+
end
|
203
211
|
|
204
212
|
def self.translate(value)
|
205
213
|
return value unless value.is_a? Symbol
|
data/spec/enumerate_it_spec.rb
CHANGED
@@ -135,6 +135,12 @@ describe EnumerateIt do
|
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
|
+
describe ".values_for" do
|
139
|
+
it "returns an array with the corresponding values for a string array representing some of the enumeration's values" do
|
140
|
+
TestEnumeration.values_for(%w(VALUE_1 VALUE_2)).should == [TestEnumeration::VALUE_1, TestEnumeration::VALUE_2]
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
138
144
|
context "when included in ActiveRecord::Base" do
|
139
145
|
before :each do
|
140
146
|
class ActiveRecordStub
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumerate_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 7
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.7.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "C\xC3\xA1ssio Marques"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-08 00:00:00 -02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|