localizable 1.1 → 1.2

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.
@@ -40,7 +40,7 @@ module Localizable
40
40
  module ClassMethods
41
41
 
42
42
  def localized_key (fieldname, type = String)
43
- key fieldname, Hash
43
+ key fieldname, Localizable::Hash
44
44
  localized_type[fieldname] = type
45
45
 
46
46
  self.class_eval <<-end_eval
@@ -77,6 +77,8 @@ module Localizable
77
77
  end
78
78
 
79
79
  def store_localized_values (fieldname, mapping)
80
+ self[fieldname] ||= Localizable::Hash.new
81
+
80
82
  mapping.each do |locale, value|
81
83
  self[fieldname][locale] = localized_type[fieldname].to_mongo(value)
82
84
  end
@@ -89,4 +91,6 @@ module Localizable
89
91
 
90
92
  end
91
93
 
94
+ autoload :Hash, File.dirname(__FILE__) + "/localizable/hash"
95
+
92
96
  end
@@ -0,0 +1,19 @@
1
+ module Localizable
2
+
3
+ class Hash < ::Hash
4
+
5
+ def method_missing (symbol, *args)
6
+ if args.length == 0
7
+ if key?(symbol.to_s)
8
+ self[symbol.to_s]
9
+ else
10
+ ''
11
+ end
12
+ else
13
+ super symbol, *args
14
+ end
15
+ end
16
+
17
+ end
18
+
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localizable
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -17,6 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - lib/localizable/hash.rb
20
21
  - lib/localizable.rb
21
22
  - README
22
23
  homepage: