simple_enum 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/Gemfile.lock +16 -15
- data/README.rdoc +10 -1
- data/lib/simple_enum.rb +4 -4
- data/test/class_methods_test.rb +10 -2
- metadata +6 -6
data/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
source :rubygems
|
2
2
|
|
3
|
-
gem "activesupport", "~> 3.0
|
4
|
-
gem "activerecord", "~> 3.0
|
3
|
+
gem "activesupport", "~> 3.0", :require => "active_support"
|
4
|
+
gem "activerecord", "~> 3.0", :require => "active_record"
|
5
5
|
|
6
6
|
gem "sqlite3-ruby", :require => "sqlite3", :platforms => :ruby
|
7
7
|
gem "jdbc-sqlite3", :require => "jdbcsqlite3", :platforms => :jruby
|
data/Gemfile.lock
CHANGED
@@ -1,28 +1,29 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activemodel (3.0.
|
5
|
-
activesupport (= 3.0.
|
4
|
+
activemodel (3.0.5)
|
5
|
+
activesupport (= 3.0.5)
|
6
6
|
builder (~> 2.1.2)
|
7
|
-
i18n (~> 0.4
|
8
|
-
activerecord (3.0.
|
9
|
-
activemodel (= 3.0.
|
10
|
-
activesupport (= 3.0.
|
11
|
-
arel (~>
|
7
|
+
i18n (~> 0.4)
|
8
|
+
activerecord (3.0.5)
|
9
|
+
activemodel (= 3.0.5)
|
10
|
+
activesupport (= 3.0.5)
|
11
|
+
arel (~> 2.0.2)
|
12
12
|
tzinfo (~> 0.3.23)
|
13
|
-
activesupport (3.0.
|
14
|
-
arel (
|
15
|
-
activesupport (~> 3.0.0)
|
13
|
+
activesupport (3.0.5)
|
14
|
+
arel (2.0.9)
|
16
15
|
builder (2.1.2)
|
17
|
-
i18n (0.
|
18
|
-
sqlite3
|
19
|
-
|
16
|
+
i18n (0.5.0)
|
17
|
+
sqlite3 (1.3.3)
|
18
|
+
sqlite3-ruby (1.3.3)
|
19
|
+
sqlite3 (>= 1.3.3)
|
20
|
+
tzinfo (0.3.24)
|
20
21
|
|
21
22
|
PLATFORMS
|
22
23
|
ruby
|
23
24
|
|
24
25
|
DEPENDENCIES
|
25
|
-
activerecord (~> 3.0
|
26
|
-
activesupport (~> 3.0
|
26
|
+
activerecord (~> 3.0)
|
27
|
+
activesupport (~> 3.0)
|
27
28
|
jdbc-sqlite3
|
28
29
|
sqlite3-ruby
|
data/README.rdoc
CHANGED
@@ -133,7 +133,15 @@ useful when creating queries, displaying option elements or similar:
|
|
133
133
|
class User < ActiveRecord::Base
|
134
134
|
as_enum :gender, [:male, :female], :whiny => false
|
135
135
|
end
|
136
|
-
|
136
|
+
|
137
|
+
* Need translated keys et al in your forms? SimpleEnum provides a <tt><enum>_for_select</tt> method:
|
138
|
+
|
139
|
+
# on the gender field
|
140
|
+
<%= select("user", "gender", User.genders_for_select) %>
|
141
|
+
|
142
|
+
# or on the '_cd' field
|
143
|
+
<%= select("user", "gender_cd", User.genders_for_select(:value))
|
144
|
+
|
137
145
|
* To define any option globally, like setting <tt>:whiny</tt> to +false+, or globally enable <tt>:prefix</tt>; all default options
|
138
146
|
are stored in <tt>SimpleEnum.default_options</tt>, this hash can be easily changed in your initializers or wherever:
|
139
147
|
|
@@ -187,6 +195,7 @@ or <em>b)</em> a custom method to convert an object to a symbolized form named +
|
|
187
195
|
* dmitry - bugfixes and other improvements
|
188
196
|
* tarsolya - implemented all the ruby 1.9 and rails 3 goodness!
|
189
197
|
* dbalatero - rails 2.3.5 bugfix
|
198
|
+
* johnthethird - feature for <tt>_for_select</tt> to return the values
|
190
199
|
|
191
200
|
== Licence & Copyright
|
192
201
|
Copyright (c) 2009 by Lukas Westermann, Licenced under MIT Licence (see LICENCE file)
|
data/lib/simple_enum.rb
CHANGED
@@ -21,7 +21,7 @@ require 'simple_enum/validation'
|
|
21
21
|
module SimpleEnum
|
22
22
|
|
23
23
|
# +SimpleEnum+ version string.
|
24
|
-
VERSION = "1.3.
|
24
|
+
VERSION = "1.3.2".freeze
|
25
25
|
|
26
26
|
class << self
|
27
27
|
|
@@ -189,10 +189,10 @@ module SimpleEnum
|
|
189
189
|
args.inject([]) { |ary, sym| ary << read_inheritable_attribute(#{enum_attr.inspect})[sym]; ary }
|
190
190
|
end
|
191
191
|
|
192
|
-
def self.#{attr_name}_for_select(&block)
|
192
|
+
def self.#{attr_name}_for_select(attr = :key, &block)
|
193
193
|
self.#{attr_name}.map do |k,v|
|
194
|
-
[block_given? ? yield(k,v) : self.human_enum_name(#{attr_name.inspect}, k), k]
|
195
|
-
end
|
194
|
+
[block_given? ? yield(k,v) : self.human_enum_name(#{attr_name.inspect}, k), attr == :value ? v : k]
|
195
|
+
end
|
196
196
|
end
|
197
197
|
RUBY
|
198
198
|
|
data/test/class_methods_test.rb
CHANGED
@@ -109,7 +109,15 @@ class ClassMethodsTest < ActiveSupport::TestCase
|
|
109
109
|
|
110
110
|
test "enum_for_select class method" do
|
111
111
|
for_select = Dummy.genders_for_select
|
112
|
-
|
113
|
-
assert_equal
|
112
|
+
genders = Dummy.genders
|
113
|
+
assert_equal genders.first.first, for_select.first.second
|
114
|
+
assert_equal ["Male", :male], for_select.first
|
115
|
+
assert_equal ["Girl", :female], for_select.last
|
116
|
+
end
|
117
|
+
|
118
|
+
test "enum_for_select(:value) class method" do
|
119
|
+
for_select = Dummy.genders_for_select(:value)
|
120
|
+
assert_equal ["Male", 0], for_select.first
|
121
|
+
assert_equal ["Girl", 1], for_select.last
|
114
122
|
end
|
115
123
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 1.3.
|
9
|
+
- 2
|
10
|
+
version: 1.3.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lukas Westermann
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-03-08 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
requirements: []
|
84
84
|
|
85
85
|
rubyforge_project:
|
86
|
-
rubygems_version: 1.
|
86
|
+
rubygems_version: 1.4.1
|
87
87
|
signing_key:
|
88
88
|
specification_version: 3
|
89
89
|
summary: Simple enum-like field support for ActiveRecord (including validations and i18n)
|