Class: Mongoid::Fields::I18n
- Inherits:
-
Object
- Object
- Mongoid::Fields::I18n
- Defined in:
- lib/custom_fields/extensions/mongoid/fields/i18n.rb
Instance Attribute Summary collapse
-
#fallbacks ⇒ Object
Returns the value of attribute fallbacks.
-
#locale ⇒ Object
Returns the value of attribute locale.
Class Method Summary collapse
- .clear_fallbacks ⇒ Object
- .fallbacks ⇒ Object
- .fallbacks? ⇒ Boolean
- .fallbacks_for(locale, fallbacks) ⇒ Object
- .instance ⇒ Object
- .locale ⇒ Object
- .locale=(value) ⇒ Object
- .with_locale(new_locale = nil) ⇒ Object
Instance Attribute Details
#fallbacks ⇒ Object
Returns the value of attribute fallbacks.
9 10 11 |
# File 'lib/custom_fields/extensions/mongoid/fields/i18n.rb', line 9 def fallbacks @fallbacks end |
#locale ⇒ Object
Returns the value of attribute locale.
9 10 11 |
# File 'lib/custom_fields/extensions/mongoid/fields/i18n.rb', line 9 def locale @locale end |
Class Method Details
.clear_fallbacks ⇒ Object
44 45 46 |
# File 'lib/custom_fields/extensions/mongoid/fields/i18n.rb', line 44 def self.clear_fallbacks instance.fallbacks.try(:clear) end |
.fallbacks ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/custom_fields/extensions/mongoid/fields/i18n.rb', line 27 def self.fallbacks if !instance.fallbacks.blank? instance.fallbacks elsif ::I18n.respond_to?(:fallbacks) ::I18n.fallbacks end end |
.fallbacks? ⇒ Boolean
40 41 42 |
# File 'lib/custom_fields/extensions/mongoid/fields/i18n.rb', line 40 def self.fallbacks? !instance.fallbacks.blank? || (::I18n.respond_to?(:fallbacks) && !::I18n.fallbacks.blank?) end |
.fallbacks_for(locale, fallbacks) ⇒ Object
35 36 37 38 |
# File 'lib/custom_fields/extensions/mongoid/fields/i18n.rb', line 35 def self.fallbacks_for(locale, fallbacks) instance.fallbacks ||= {} instance.fallbacks[locale.to_sym] = fallbacks end |
.instance ⇒ Object
11 12 13 |
# File 'lib/custom_fields/extensions/mongoid/fields/i18n.rb', line 11 def self.instance Thread.current[:mongoid_i18n] ||= Mongoid::Fields::I18n.new end |
.locale ⇒ Object
15 16 17 |
# File 'lib/custom_fields/extensions/mongoid/fields/i18n.rb', line 15 def self.locale instance.locale || ::I18n.locale end |
.locale=(value) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/custom_fields/extensions/mongoid/fields/i18n.rb', line 19 def self.locale=(value) instance.locale = begin value.to_sym rescue StandardError nil end end |
.with_locale(new_locale = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/custom_fields/extensions/mongoid/fields/i18n.rb', line 48 def self.with_locale(new_locale = nil) if new_locale current_locale = locale self.locale = new_locale end yield ensure self.locale = current_locale if new_locale end |