Module: Mobility::Backends::ActiveRecord::Table::TranslationsHasManyExtension

Defined in:
lib/mobility/backends/active_record/table.rb

Instance Method Summary collapse

Instance Method Details

#destroy_empty_translations(required_attributes) ⇒ Object

Destroys translations with all empty values


300
301
302
303
# File 'lib/mobility/backends/active_record/table.rb', line 300

def destroy_empty_translations(required_attributes)
  empty_translations = select{ |t| required_attributes.map(&t.method(:send)).none? }
  destroy(empty_translations) if empty_translations.any?
end

#in_locale(locale) ⇒ Object

Returns translation in a given locale, or nil if none exist

Parameters:

  • locale (Symbol, String)

294
295
296
297
# File 'lib/mobility/backends/active_record/table.rb', line 294

def in_locale(locale)
  locale = locale.to_s
  find { |t| t.locale == locale }
end