lists_constant 0.2.0 → 0.2.1

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 CHANGED
@@ -3,6 +3,8 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .DS_Store
7
+
6
8
  Gemfile.lock
7
9
  InstalledFiles
8
10
  _yardoc
data/README.md CHANGED
@@ -73,8 +73,12 @@ Class-level localization:
73
73
 
74
74
  ``` ruby
75
75
  I18n.locale = :en
76
+
76
77
  MyStateMachine.steps[:first]
77
- # => 'Initialize'
78
+ # => 'Initalize'
79
+
80
+ MyStateMachine.localized_step('second')
81
+ # => 'Validate'
78
82
 
79
83
  MyStateMachine.step_options
80
84
  # => {
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module ListsConstant
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -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.0
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-03 00:00:00.000000000 Z
12
+ date: 2013-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport