Class: Traco::LocalizedReader

Inherits:
Object
  • Object
show all
Defined in:
lib/traco/localized_reader.rb

Constant Summary collapse

FALLBACK_OPTIONS =
[
  DEFAULT_FALLBACK = :default,
  ANY_FALLBACK = :any,
  NO_FALLBACK = false,
]

Instance Method Summary collapse

Constructor Details

#initialize(record, attribute, options) ⇒ LocalizedReader

Returns a new instance of LocalizedReader.



9
10
11
12
13
14
# File 'lib/traco/localized_reader.rb', line 9

def initialize(record, attribute, options)
  @record = record
  @attribute = attribute
  @fallback = options[:fallback]
  validate_fallback
end

Instance Method Details

#valueObject



16
17
18
19
20
21
22
23
# File 'lib/traco/localized_reader.rb', line 16

def value
  locales_to_try.each do |locale|
    value = @record.send("#{@attribute}_#{Traco.locale_suffix(locale)}")
    return value if value.present?
  end

  nil
end