lists_constant 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/README.md +5 -1
- data/lib/lists_constant/lookups/class.rb +10 -1
- data/lib/lists_constant/version.rb +1 -1
- data/test/lib/lists_constant/lookups/class_test.rb +5 -0
- metadata +2 -2
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -14,6 +14,7 @@ module ListsConstant
|
|
14
14
|
def extended base
|
15
15
|
add_lookup_query_method base
|
16
16
|
add_localized_hash_method base
|
17
|
+
add_localization_method base
|
17
18
|
add_inverted_hash_method base
|
18
19
|
end
|
19
20
|
|
@@ -33,12 +34,20 @@ module ListsConstant
|
|
33
34
|
|
34
35
|
base.define_singleton_method field do
|
35
36
|
const_get(field.upcase).inject({}) do |hash, value|
|
36
|
-
hash[value] = ListsConstant::Lookup.new(self, field).lookup(value)
|
37
|
+
hash[value.to_sym] = ListsConstant::Lookup.new(self, field).lookup(value)
|
37
38
|
hash
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
43
|
+
def add_localization_method base
|
44
|
+
field = @field
|
45
|
+
|
46
|
+
base.define_singleton_method "localized_#{field.singularize}" do |value|
|
47
|
+
send(field)[value.to_sym] unless value.nil?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
42
51
|
def add_inverted_hash_method base
|
43
52
|
field = @field
|
44
53
|
|
@@ -44,6 +44,11 @@ describe ListsConstant::Lookups::Class do
|
|
44
44
|
}
|
45
45
|
end
|
46
46
|
|
47
|
+
it "localizes passed values" do
|
48
|
+
assert_equal Lister.localized_color(:red), @translations[:red]
|
49
|
+
assert_equal Lister.localized_color('blue'), @translations[:blue]
|
50
|
+
end
|
51
|
+
|
47
52
|
it "generates an inverted hash for option helpers" do
|
48
53
|
assert_equal Lister.color_options, {
|
49
54
|
@translations[:red] => :red,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lists_constant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|