Sha256: f3deb6f2cb544b03378259bd21fe26d80b25a0cfcd6a3d63cd2e830cfeabc219

Contents?: true

Size: 717 Bytes

Versions: 17

Compression:

Stored size: 717 Bytes

Contents

module Spotlight
  # A language for an exhibit
  class Language < ActiveRecord::Base
    belongs_to :exhibit
    has_many :pages, ->(page) { where(locale: page.locale) }, through: :exhibit
    has_many :translations, ->(translation) { where(locale: translation.locale) }, through: :exhibit
    validates :locale, presence: true

    # Doing this instead of dependent: :destroy because
    # has_many :through can't associate a has_many reflection
    after_destroy do
      pages.map(&:destroy)
      translations.map(&:destroy)
    end

    def to_native
      Spotlight::Engine.config.i18n_locales[locale.to_sym] || ''
    end

    def self.default_instance
      new(locale: I18n.default_locale)
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
blacklight-spotlight-2.4.1 app/models/spotlight/language.rb
blacklight-spotlight-2.4.0 app/models/spotlight/language.rb
blacklight-spotlight-2.3.3 app/models/spotlight/language.rb
blacklight-spotlight-2.3.2 app/models/spotlight/language.rb
blacklight-spotlight-2.3.1 app/models/spotlight/language.rb
blacklight-spotlight-2.3.0 app/models/spotlight/language.rb
blacklight-spotlight-2.2.1 app/models/spotlight/language.rb
blacklight-spotlight-2.2.0 app/models/spotlight/language.rb
blacklight-spotlight-2.1.0 app/models/spotlight/language.rb
blacklight-spotlight-2.0.2 app/models/spotlight/language.rb
blacklight-spotlight-2.0.1 app/models/spotlight/language.rb
blacklight-spotlight-2.0.0 app/models/spotlight/language.rb
blacklight-spotlight-2.0.0.rc6 app/models/spotlight/language.rb
blacklight-spotlight-2.0.0.rc5 app/models/spotlight/language.rb
blacklight-spotlight-2.0.0.rc4 app/models/spotlight/language.rb
blacklight-spotlight-2.0.0.rc3 app/models/spotlight/language.rb
blacklight-spotlight-2.0.0.rc2 app/models/spotlight/language.rb