Sha256: 4efcf8f231baf144b6e31273b5955d06d5ab871a01b5c3c5c5611ece92508006

Contents?: true

Size: 1.08 KB

Versions: 158

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'i18n'
require 'eac_ruby_utils/patches/class/common_constructor'
require 'eac_ruby_utils/patches/object/to_pathname'

module EacRubyUtils
  module Locales
    class FromGem
      class << self
        def include_all(i18n_obj = nil)
          ::Gem::Specification.each { |gemspec| new(gemspec, i18n_obj).include }
        end
      end

      LOCALES_DIR_SUBPATH = 'locale'
      LOCALES_FILES_GLOB_PATTERNS = %w[*.yaml *.yml].freeze

      common_constructor :gemspec, :i18n_obj, default: [nil] do
        self.i18n_obj ||= ::I18n
      end

      # @return [Boolean]
      delegate :exist?, to: :path

      # @return [Pathname, nil]
      def include
        return nil unless exist?

        ::I18n.load_path += paths_to_load.map(&:to_path)
        path
      end

      # @return [Pathname]
      def path
        gemspec.gem_dir.to_pathname.join(LOCALES_DIR_SUBPATH)
      end

      # @return [Pathname]
      def paths_to_load
        return [] unless exist?

        LOCALES_FILES_GLOB_PATTERNS.inject([]) { |a, e| a + path.glob(e) }
      end
    end
  end
end

Version data entries

158 entries across 158 versions & 3 rubygems

Version Path
eac_tools-0.60.2 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.60.1 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.60.0 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.59.0 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.58.0 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.57.0 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.56.1 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.56.0 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.55.7 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.55.6 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.55.5 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.55.4 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.55.3 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.55.2 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_ruby_utils-0.112.0 lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.55.1 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_ruby_utils-0.111.0 lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.55.0 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.54.0 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb
eac_tools-0.53.0 sub/eac_ruby_utils/lib/eac_ruby_utils/locales/from_gem.rb