class HstoreTranslations::TranslationsLookup
Attributes
attribute[R]
model[R]
Public Class Methods
new(model, attribute, locale = nil)
click to toggle source
# File lib/hstore_translations/translations_lookup.rb, line 5 def initialize(model, attribute, locale = nil) @model, @attribute, @locale = model, attribute, locale @locale = locale end
Public Instance Methods
value()
click to toggle source
# File lib/hstore_translations/translations_lookup.rb, line 10 def value if @locale try_locale(@locale) else fallbacks.inject(nil) do |_, locale| value = try_locale(locale) return value if value.present? end end end
Private Instance Methods
fallbacks()
click to toggle source
# File lib/hstore_translations/translations_lookup.rb, line 23 def fallbacks HstoreTranslations.fallbacks(@locale || HstoreTranslations.locale) end
try_locale(locale)
click to toggle source
# File lib/hstore_translations/translations_lookup.rb, line 27 def try_locale(locale) model.read_translated_attribute(attribute, locale) end