Sha256: 9459eac6f9d9e6a2d0178cf1f635446a4c5248e3ea6371ab59d66c025e5004fe

Contents?: true

Size: 800 Bytes

Versions: 12

Compression:

Stored size: 800 Bytes

Contents

# frozen_string_literal: true

# rubocop:disable Style/ClassAndModuleChildren
module Maglev::Site::LocalesConcern
  extend ActiveSupport::Concern

  included do
    ## serializers ##
    serialize :locales, LocalesSerializer

    ## validation ##
    validates :locales, 'maglev/collection': true, length: { minimum: 1 }
  end

  def default_locale
    locales.first
  end

  def default_locale_prefix
    default_locale.prefix.to_sym
  end

  def locale_prefixes
    locales.map { |locale| locale.prefix.to_sym }
  end

  class LocalesSerializer
    def self.dump(array)
      (array || []).map(&:as_json)
    end

    def self.load(array)
      (array || []).map { |attributes| Maglev::Site::Locale.new(**attributes.symbolize_keys) }
    end
  end
end
# rubocop:enable Style/ClassAndModuleChildren

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
maglevcms-1.1.7 app/models/maglev/site/locales_concern.rb
maglevcms-1.1.6 app/models/maglev/site/locales_concern.rb
maglevcms-1.1.5 app/models/maglev/site/locales_concern.rb
maglevcms-1.1.4 app/models/maglev/site/locales_concern.rb
maglevcms-1.1.3 app/models/maglev/site/locales_concern.rb
maglevcms-1.1.2 app/models/maglev/site/locales_concern.rb
maglevcms-1.1.1 app/models/maglev/site/locales_concern.rb
maglevcms-1.1.0 app/models/maglev/site/locales_concern.rb
maglevcms-1.0.0 app/models/maglev/site/locales_concern.rb
maglevcms-1.0.0.rc3 app/models/maglev/site/locales_concern.rb
maglevcms-1.0.0.rc2 app/models/maglev/site/locales_concern.rb
maglevcms-1.0.0.rc1 app/models/maglev/site/locales_concern.rb