Sha256: ed3608926926ffc6aaf63b8245e85de51dd936055623aeaa3a93a7a5fe96f440

Contents?: true

Size: 1003 Bytes

Versions: 24

Compression:

Stored size: 1003 Bytes

Contents

module ActiveadminSelleoCms
  class Locale < ActiveRecord::Base
    attr_protected :id

    validates :name, presence: true
    validates :code, presence: true, uniqueness: true

    scope :enabled, where(enabled: true)
    scope :available_locales, enabled
    scope :exclude, ->(codes){ where("code NOT IN (?)", Array(codes)) }

    scope :popular, where(code: %w(da de el en es fr hu it lt lv nl no pl pt ru sk sl sv))

    def to_s
      code
    end

    def code
      read_attribute(:code).to_sym
    end

    def url
      "/#{to_s}"
    end

    class << self
      def except(locale_codes)
        locale_codes = [locale_codes] unless locale_codes.is_a? Array
        enabled.where("code NOT IN (?)", locale_codes).map(&:code)
      end

      def available_locale_codes
        enabled.map(&:to_s)
      end

      def method_missing(sym, *args)
        if sym.to_s =~ /^[a-z]{2}$/
          Locale.where(code: sym).first
        else
          super
        end
      end
    end

  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
activeadmin-selleo-cms-0.0.36 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.35 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.34 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.33 app/models/activeadmin_selleo_cms/locale.rb