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.61 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.60 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.59 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.58 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.54 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.52 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.51 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.49 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.48 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.47 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.46 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.45 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.44 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.43 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.42 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.41 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.40 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.39 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.38 app/models/activeadmin_selleo_cms/locale.rb
activeadmin-selleo-cms-0.0.37 app/models/activeadmin_selleo_cms/locale.rb