Class: Globalize::ActiveRecord::Translation

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/globalize/active_record/translation.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.table_exists?Boolean

Sometimes ActiveRecord queries .table_exists? before the table name has even been set which results in catastrophic failure.

Returns:

  • (Boolean)

11
12
13
# File 'lib/globalize/active_record/translation.rb', line 11

def table_exists?
  table_name.present? && super
end

.translated_localesObject


23
24
25
# File 'lib/globalize/active_record/translation.rb', line 23

def translated_locales
  select('DISTINCT locale').order(:locale).map(&:locale)
end

.with_locales(*locales) ⇒ Object Also known as: with_locale


15
16
17
18
19
20
# File 'lib/globalize/active_record/translation.rb', line 15

def with_locales(*locales)
  # Avoid using "IN" with SQL queries when only using one locale.
  locales = locales.flatten.map(&:to_s)
  locales = locales.first if locales.one?
  where :locale => locales
end

Instance Method Details

#localeObject


28
29
30
31
# File 'lib/globalize/active_record/translation.rb', line 28

def locale
  _locale = read_attribute :locale
  _locale.present? ? _locale.to_sym : _locale
end

#locale=(locale) ⇒ Object


33
34
35
# File 'lib/globalize/active_record/translation.rb', line 33

def locale=(locale)
  write_attribute :locale, locale.to_s
end