Class: Mobility::Plugins::LocaleAccessors
- Inherits:
-
Module
- Object
- Module
- Mobility::Plugins::LocaleAccessors
- Defined in:
- lib/mobility/plugins/locale_accessors.rb
Overview
Defines methods for a set of locales to access translated attributes in those locales directly with a method call, using a suffix including the locale:
article.title_pt_br
If no locales are passed as an option to the initializer,
I18n.available_locales will be used by default.
Class Method Summary collapse
-
.apply(attributes, option) ⇒ Object
Apply locale accessors plugin to attributes.
Instance Method Summary collapse
-
#initialize(*attribute_names, locales: I18n.available_locales) ⇒ LocaleAccessors
constructor
A new instance of LocaleAccessors.
Constructor Details
#initialize(*attribute_names, locales: I18n.available_locales) ⇒ LocaleAccessors
Returns a new instance of LocaleAccessors.
44 45 46 47 48 49 50 51 |
# File 'lib/mobility/plugins/locale_accessors.rb', line 44 def initialize(*attribute_names, locales: I18n.available_locales) attribute_names.each do |name| locales.each do |locale| define_reader(name, locale) define_writer(name, locale) end end end |
Class Method Details
.apply(attributes, option) ⇒ Object
Apply locale accessors plugin to attributes.
35 36 37 38 39 40 |
# File 'lib/mobility/plugins/locale_accessors.rb', line 35 def self.apply(attributes, option) if accessor_locales = option accessor_locales = Mobility.config.default_accessor_locales if accessor_locales == true attributes.model_class.include new(*attributes.names, locales: accessor_locales) end end |