Sha256: 3d4007b71087b31581ff083758220d48883d4235e875aba639d4fce750550049

Contents?: true

Size: 726 Bytes

Versions: 1

Compression:

Stored size: 726 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.downcase.to_sym] || ''
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blacklight-spotlight-2.0.0.rc1 app/models/spotlight/language.rb