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)


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

def table_exists?
  table_name.present? && super
end

.translated_localesObject



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

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

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



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

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



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

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

#locale=(locale) ⇒ Object



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

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