simple_enum 0.9.0 → 1.0.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/.gitignore +1 -0
- data/README.rdoc +3 -0
- data/VERSION.yml +3 -2
- data/lib/simple_enum.rb +4 -3
- data/lib/simple_enum/enum_hash.rb +1 -1
- data/test/class_methods_test.rb +5 -0
- metadata +2 -3
- data/simple_enum.gemspec +0 -75
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -124,6 +124,9 @@ useful when creating queries, displaying option elements or similar:
|
|
124
124
|
Message.statuses.unread # => 0
|
125
125
|
Message.statuses.unread(true) # => :unread
|
126
126
|
|
127
|
+
# or useful for IN queries
|
128
|
+
Messages.statuses(:unread, :read) # => [0, 1]
|
129
|
+
|
127
130
|
* As a default an <tt>ArgumentError</tt> is raised if the user tries to set the field to an invalid enumeration value, to change this
|
128
131
|
behaviour use the <tt>:whiny</tt> option:
|
129
132
|
|
data/VERSION.yml
CHANGED
data/lib/simple_enum.rb
CHANGED
@@ -175,9 +175,10 @@ module SimpleEnum
|
|
175
175
|
self_name.upcase! if options[:upcase]
|
176
176
|
class_variable_set :"@@SE_#{self_name.upcase}", values
|
177
177
|
class_eval(<<-EOM, __FILE__, __LINE__ + 1)
|
178
|
-
def self.#{self_name}(
|
179
|
-
return
|
180
|
-
|
178
|
+
def self.#{self_name}(*args)
|
179
|
+
return @@SE_#{self_name.upcase} if args.first.nil?
|
180
|
+
return @@SE_#{self_name.upcase}[args.first] if args.size == 1
|
181
|
+
args.inject([]) { |ary, sym| ary << @@SE_#{self_name.upcase}[sym]; ary }
|
181
182
|
end
|
182
183
|
|
183
184
|
def self.#{self_name}_for_select(&block)
|
data/test/class_methods_test.rb
CHANGED
@@ -11,6 +11,11 @@ class ClassMethodsTest < ActiveSupport::TestCase
|
|
11
11
|
assert_nil Dummy.genders(:inexistent)
|
12
12
|
assert_nil Dummy.genders[:inexistent]
|
13
13
|
end
|
14
|
+
|
15
|
+
test "that Klass.genders(:sym_a, :sym_b) returns an array of values, useful for IN clauses" do
|
16
|
+
assert_equal [0, 1], Dummy.genders(:male, :female)
|
17
|
+
assert_equal [1, 0], Dummy.genders(:female, :male)
|
18
|
+
end
|
14
19
|
|
15
20
|
test "generation of value shortcuts on class" do
|
16
21
|
g = Dummy.new
|
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: 1.0.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:
|
12
|
+
date: 2010-01-07 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -35,7 +35,6 @@ files:
|
|
35
35
|
- lib/simple_enum/validation.rb
|
36
36
|
- lib/simple_enum/version.rb
|
37
37
|
- locales/en.yml
|
38
|
-
- simple_enum.gemspec
|
39
38
|
- test/array_conversions_test.rb
|
40
39
|
- test/class_methods_test.rb
|
41
40
|
- test/enum_hash_test.rb
|
data/simple_enum.gemspec
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{simple_enum}
|
8
|
-
s.version = "0.9.0"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Lukas Westermann"]
|
12
|
-
s.date = %q{2009-12-01}
|
13
|
-
s.email = %q{lukas.westermann@gmail.com}
|
14
|
-
s.extra_rdoc_files = [
|
15
|
-
"README.rdoc"
|
16
|
-
]
|
17
|
-
s.files = [
|
18
|
-
".gitignore",
|
19
|
-
"LICENCE",
|
20
|
-
"README.rdoc",
|
21
|
-
"Rakefile",
|
22
|
-
"VERSION.yml",
|
23
|
-
"init.rb",
|
24
|
-
"lib/simple_enum.rb",
|
25
|
-
"lib/simple_enum/array_support.rb",
|
26
|
-
"lib/simple_enum/enum_hash.rb",
|
27
|
-
"lib/simple_enum/object_support.rb",
|
28
|
-
"lib/simple_enum/validation.rb",
|
29
|
-
"lib/simple_enum/version.rb",
|
30
|
-
"locales/en.yml",
|
31
|
-
"simple_enum.gemspec",
|
32
|
-
"test/array_conversions_test.rb",
|
33
|
-
"test/class_methods_test.rb",
|
34
|
-
"test/enum_hash_test.rb",
|
35
|
-
"test/finders_test.rb",
|
36
|
-
"test/models.rb",
|
37
|
-
"test/object_backed_test.rb",
|
38
|
-
"test/object_support_test.rb",
|
39
|
-
"test/prefixes_test.rb",
|
40
|
-
"test/se_array_support_test.rb",
|
41
|
-
"test/simple_enum_test.rb",
|
42
|
-
"test/test_helper.rb",
|
43
|
-
"test/without_shortcuts_test.rb"
|
44
|
-
]
|
45
|
-
s.homepage = %q{http://github.com/lwe/simple_enum}
|
46
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
47
|
-
s.require_paths = ["lib"]
|
48
|
-
s.rubygems_version = %q{1.3.5}
|
49
|
-
s.summary = %q{Simple enum-like field support for ActiveRecord (including validations and i18n)}
|
50
|
-
s.test_files = [
|
51
|
-
"test/array_conversions_test.rb",
|
52
|
-
"test/class_methods_test.rb",
|
53
|
-
"test/enum_hash_test.rb",
|
54
|
-
"test/finders_test.rb",
|
55
|
-
"test/models.rb",
|
56
|
-
"test/object_backed_test.rb",
|
57
|
-
"test/object_support_test.rb",
|
58
|
-
"test/prefixes_test.rb",
|
59
|
-
"test/se_array_support_test.rb",
|
60
|
-
"test/simple_enum_test.rb",
|
61
|
-
"test/test_helper.rb",
|
62
|
-
"test/without_shortcuts_test.rb"
|
63
|
-
]
|
64
|
-
|
65
|
-
if s.respond_to? :specification_version then
|
66
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
67
|
-
s.specification_version = 3
|
68
|
-
|
69
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
70
|
-
else
|
71
|
-
end
|
72
|
-
else
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|