Class: HstoreTranslations::TranslationsLookup

Inherits:
Object
  • Object
show all
Defined in:
lib/hstore_translations/translations_lookup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, attribute, locale = nil) ⇒ TranslationsLookup

Returns a new instance of TranslationsLookup.



5
6
7
8
# File 'lib/hstore_translations/translations_lookup.rb', line 5

def initialize(model, attribute, locale = nil)
  @model, @attribute, @locale = model, attribute, locale
  @locale = locale
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



3
4
5
# File 'lib/hstore_translations/translations_lookup.rb', line 3

def attribute
  @attribute
end

#modelObject (readonly)

Returns the value of attribute model.



3
4
5
# File 'lib/hstore_translations/translations_lookup.rb', line 3

def model
  @model
end

Instance Method Details

#valueObject



10
11
12
13
14
15
16
17
18
19
# 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