Sha256: f4c3a27e622f5c878ac70bf2c056a0652974a362680ef6ff0ba902a60cb7cbf9

Contents?: true

Size: 875 Bytes

Versions: 15

Compression:

Stored size: 875 Bytes

Contents

# frozen_string_literal: true

module Maglev
  # Change the locales of a site.
  # The new locales are an array of maps with 2 required keys: :name & :prefix.
  class ChangeSiteLocales
    include Injectable

    argument :site
    argument :locales

    def call
      return if locales.blank?

      if default_locale_changed? && !all_paths_translated?
        raise 'The translations for the new default locale are incomplete'
      end

      site.update(locales: locales)
    end

    protected

    def new_default_locale_prefix
      locales.first.prefix.to_sym
    end

    def default_locale_changed?
      new_default_locale_prefix != site.default_locale_prefix
    end

    def all_paths_translated?
      Maglev::PagePath.where(locale: site.default_locale_prefix).count ==
        Maglev::PagePath.where(locale: new_default_locale_prefix).count
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
maglevcms-1.2.2 app/services/maglev/change_site_locales.rb
maglevcms-1.2.1 app/services/maglev/change_site_locales.rb
maglevcms-1.2.0 app/services/maglev/change_site_locales.rb
maglevcms-1.1.7 app/services/maglev/change_site_locales.rb
maglevcms-1.1.6 app/services/maglev/change_site_locales.rb
maglevcms-1.1.5 app/services/maglev/change_site_locales.rb
maglevcms-1.1.4 app/services/maglev/change_site_locales.rb
maglevcms-1.1.3 app/services/maglev/change_site_locales.rb
maglevcms-1.1.2 app/services/maglev/change_site_locales.rb
maglevcms-1.1.1 app/services/maglev/change_site_locales.rb
maglevcms-1.1.0 app/services/maglev/change_site_locales.rb
maglevcms-1.0.0 app/services/maglev/change_site_locales.rb
maglevcms-1.0.0.rc3 app/services/maglev/change_site_locales.rb
maglevcms-1.0.0.rc2 app/services/maglev/change_site_locales.rb
maglevcms-1.0.0.rc1 app/services/maglev/change_site_locales.rb