Module: Mongoid::Localized::Accessor
- Defined in:
- lib/mongoid-localized-accessor.rb,
lib/mongoid-localized-accessor/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mongoid-localized-accessor.rb', line 6 def method_missing method if (match_data = method.to_s.match(/(?<method>.*)_(?<lang>\w\w)/)) method = match_data['method'] lang = match_data['lang'] if self.respond_to? method.to_sym if self.try(:[],method.to_sym) self.try(:[],method.to_sym).try(:[],lang) else if self.try(method.to_sym) self.try(method.to_sym).try(:[],lang) end end else super end else super end end |