Sha256: 96879bf47829db4df854c271ebf8e3bbaa18fcb1c704cd8b91c97db8fab455cc

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

class Language < ActiveRecord::Base
  attr_accessible :name, :native_name, :display_name, :iso_639_1, :iso_639_2,
    :iso_639_3, :note
  include MasterModel
  default_scope order: "languages.position"
  # If you wish to change the field names for brevity, feel free to enable/modify these.
  # alias_attribute :iso1, :iso_639_1
  # alias_attribute :iso2, :iso_639_2
  # alias_attribute :iso3, :iso_639_3

  # Validations
  validates_presence_of :iso_639_1, :iso_639_2, :iso_639_3
  after_save :clear_available_languages_cache
  after_destroy :clear_available_languages_cache

  def self.all_cache
    if Rails.env == 'production'
      Rails.cache.fetch('language_all'){Language.all.to_a}
    else
      Language.all
    end
  end

  def clear_available_languages_cache
    Rails.cache.delete('language_all')
    Rails.cache.delete('available_languages')
  end

  def self.available_languages
    Language.where(:iso_639_1 => I18n.available_locales.map{|l| l.to_s}).order(:position)
  end
end

# == Schema Information
#
# Table name: languages
#
#  id           :integer          not null, primary key
#  name         :string(255)      not null
#  native_name  :string(255)
#  display_name :text
#  iso_639_1    :string(255)
#  iso_639_2    :string(255)
#  iso_639_3    :string(255)
#  note         :text
#  position     :integer
#

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
enju_biblio-0.1.0.pre58 app/models/language.rb
enju_biblio-0.1.0.pre57 app/models/language.rb
enju_biblio-0.1.0.pre56 app/models/language.rb