mongoid-localized-accessor 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -1
- data/lib/mongoid-localized-accessor.rb +8 -6
- data/lib/mongoid-localized-accessor/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -17,7 +17,10 @@ Or install it yourself as:
|
|
17
17
|
$ gem install mongoid-localized-accessor
|
18
18
|
|
19
19
|
## Usage
|
20
|
-
|
20
|
+
Include this into the model defitition
|
21
|
+
```ruby
|
22
|
+
include Mongoid::Localized::Accessor
|
23
|
+
```
|
21
24
|
Field definition
|
22
25
|
```ruby
|
23
26
|
field :name, type: String, localize: true
|
@@ -4,13 +4,15 @@ module Mongoid
|
|
4
4
|
module Localized
|
5
5
|
module Accessor
|
6
6
|
def method_missing method
|
7
|
-
if (
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
if (match_data = method.to_s.match(/(?<method>.*)_(?<lang>\w\w)/))
|
8
|
+
method = match_data['method']
|
9
|
+
lang = match_data['lang']
|
10
|
+
if self.respond_to? method.to_sym
|
11
|
+
if self.try(:[],method.to_sym)
|
12
|
+
self.try(:[],method.to_sym).try(:[],lang)
|
11
13
|
else
|
12
|
-
if self.try(
|
13
|
-
self.try(
|
14
|
+
if self.try(method.to_sym)
|
15
|
+
self.try(method.to_sym).try(:[],lang)
|
14
16
|
end
|
15
17
|
end
|
16
18
|
else
|