simple_enum 0.3.0 → 0.9.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/VERSION.yml +1 -1
- data/lib/simple_enum.rb +15 -0
- data/lib/simple_enum/enum_hash.rb +1 -1
- data/locales/en.yml +9 -1
- data/simple_enum.gemspec +5 -4
- data/test/class_methods_test.rb +7 -0
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/simple_enum.rb
CHANGED
@@ -179,6 +179,12 @@ module SimpleEnum
|
|
179
179
|
return class_variable_get(:@@SE_#{self_name.upcase}) if sym.nil?
|
180
180
|
class_variable_get(:@@SE_#{self_name.upcase})[sym]
|
181
181
|
end
|
182
|
+
|
183
|
+
def self.#{self_name}_for_select(&block)
|
184
|
+
self.#{self_name}.map do |k,v|
|
185
|
+
[block_given? ? yield(k,v) : self.human_enum_name(#{self_name.inspect}, k), v]
|
186
|
+
end.sort { |a,b| a[1] <=> b[1] }
|
187
|
+
end
|
182
188
|
EOM
|
183
189
|
|
184
190
|
# only create if :slim is not defined
|
@@ -207,6 +213,15 @@ module SimpleEnum
|
|
207
213
|
end
|
208
214
|
|
209
215
|
include Validation
|
216
|
+
|
217
|
+
def human_enum_name(enum, key, options = {})
|
218
|
+
defaults = self_and_descendants_from_active_record.map { |klass| :"#{klass.name.underscore}.#{enum}.#{key}" }
|
219
|
+
defaults << :"#{enum}.#{key}"
|
220
|
+
defaults << options.delete(:default) if options[:default]
|
221
|
+
defaults << "#{key}".humanize
|
222
|
+
options[:count] ||= 1
|
223
|
+
I18n.translate(defaults.shift, options.merge(:default => defaults.flatten, :scope => [:activerecord, :enums]))
|
224
|
+
end
|
210
225
|
|
211
226
|
protected
|
212
227
|
# Returns enum definitions as defined by each call to
|
data/locales/en.yml
CHANGED
data/simple_enum.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{simple_enum}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.9.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Lukas Westermann"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-12-01}
|
13
13
|
s.email = %q{lukas.westermann@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.rdoc"
|
@@ -72,3 +72,4 @@ Gem::Specification.new do |s|
|
|
72
72
|
else
|
73
73
|
end
|
74
74
|
end
|
75
|
+
|
data/test/class_methods_test.rb
CHANGED
@@ -91,4 +91,11 @@ class ClassMethodsTest < ActiveSupport::TestCase
|
|
91
91
|
assert_same 0, with_upcase.GENDERS.male
|
92
92
|
assert_same 1, with_upcase.GENDERS[:female]
|
93
93
|
end
|
94
|
+
|
95
|
+
test "that the human_enum_name method returns translated/humanized values" do
|
96
|
+
assert_equal :male.to_s.humanize, Dummy.human_enum_name(:genders, :male)
|
97
|
+
assert_equal "Girl", Dummy.human_enum_name(:genders, :female)
|
98
|
+
assert_equal "Foo", Dummy.human_enum_name(:didums, :foo)
|
99
|
+
assert_equal "Foos", Dummy.human_enum_name(:didums, :foo, :count => 5)
|
100
|
+
end
|
94
101
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Westermann
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-01 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|