Sha256: 358eea4103ef3fbb458178b7b8ea1740a8159a8608cba318ad34f83a886a6c03

Contents?: true

Size: 748 Bytes

Versions: 76

Compression:

Stored size: 748 Bytes

Contents

# frozen_string_literal: true

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

76 entries across 76 versions & 1 rubygems

Version Path
blacklight-spotlight-4.3.6 app/models/spotlight/language.rb
blacklight-spotlight-4.3.5 app/models/spotlight/language.rb
blacklight-spotlight-4.3.4 app/models/spotlight/language.rb
blacklight-spotlight-4.3.3 app/models/spotlight/language.rb
blacklight-spotlight-4.3.2 app/models/spotlight/language.rb
blacklight-spotlight-4.3.1 app/models/spotlight/language.rb
blacklight-spotlight-4.3.0 app/models/spotlight/language.rb
blacklight-spotlight-4.2.0 app/models/spotlight/language.rb
blacklight-spotlight-4.1.2 app/models/spotlight/language.rb
blacklight-spotlight-4.1.1 app/models/spotlight/language.rb
blacklight-spotlight-4.1.0 app/models/spotlight/language.rb
blacklight-spotlight-4.0.3 app/models/spotlight/language.rb
blacklight-spotlight-4.0.2 app/models/spotlight/language.rb
blacklight-spotlight-4.0.1 app/models/spotlight/language.rb
blacklight-spotlight-4.0.0 app/models/spotlight/language.rb
blacklight-spotlight-3.6.0.beta10 app/models/spotlight/language.rb
blacklight-spotlight-3.6.0.beta9 app/models/spotlight/language.rb
blacklight-spotlight-3.6.0.beta8 app/models/spotlight/language.rb
blacklight-spotlight-3.5.0.4 app/models/spotlight/language.rb
blacklight-spotlight-3.6.0.beta7 app/models/spotlight/language.rb