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 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 (org = method.to_s.split(/_\w\w$/)).length == 2
8
- if self.respond_to? org[0].to_sym
9
- if self.try(:[],org[0].to_sym)
10
- self.try(:[],org[0].to_sym).try(:[],org[1])
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(org[0].to_sym)
13
- self.try(org[0].to_sym).try(:[],org[1])
14
+ if self.try(method.to_sym)
15
+ self.try(method.to_sym).try(:[],lang)
14
16
  end
15
17
  end
16
18
  else
@@ -1,7 +1,7 @@
1
1
  module Mongoid
2
2
  module Localized
3
3
  module Accessor
4
- VERSION = "0.0.1"
4
+ VERSION = "0.1.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-localized-accessor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: