Sha256: 33d9bdb65b17e5e8dd459f19b6f17b4fd4da88f81df4d92f0894d59b1a1f9412

Contents?: true

Size: 454 Bytes

Versions: 3

Compression:

Stored size: 454 Bytes

Contents

# encoding: utf-8

class Localization < ActiveRecord::Base
  belongs_to :localizable, polymorphic: true, optional: true

  class << self
    def locales
      order("locale ASC").pluck("DISTINCT locale")
    end

    def names
      order("name ASC").pluck("DISTINCT name")
    end
  end

  def to_s
    value || ""
  end

  delegate :empty?, to: :to_s

  def translate(locale)
    localizable.localizations.find_by(name: name, locale: locale)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
localizable_model-0.6.1 app/models/localization.rb
localizable_model-0.6.0 app/models/localization.rb
localizable_model-0.5.5 app/models/localization.rb