Sha256: 6ed39ab2a1e72df0e8d08f8430c0fb4cd83dd216eb053c2f0361a7a76173378e

Contents?: true

Size: 1.07 KB

Versions: 8

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require 'fast_gettext/translation_repository/base'

module FastGettext
  module TranslationRepository
    # Responsibility:
    #  - delegate calls to members of the chain in turn
    # TODO cache should be expired after a repo was added
    class Chain < Base
      attr_accessor :chain

      def initialize(name, options = {})
        super
        self.chain = options[:chain]
      end

      def available_locales
        chain.map(&:available_locales).flatten.uniq
      end

      def pluralisation_rule
        chain.each do |c|
          if result = c.pluralisation_rule
            return result
          end
        end
        nil
      end

      def [](key)
        chain.each do |c|
          if result = c[key]
            return result
          end
        end
        nil
      end

      def plural(*keys)
        chain.each do |c|
          result = c.plural(*keys)
          return result unless result.compact.empty?
        end
        []
      end

      def reload
        chain.each(&:reload)
        super
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fast_gettext-3.1.0 lib/fast_gettext/translation_repository/chain.rb
fast_gettext-2.3.0 lib/fast_gettext/translation_repository/chain.rb
fast_gettext-2.2.0 lib/fast_gettext/translation_repository/chain.rb
fast_gettext-2.1.0 lib/fast_gettext/translation_repository/chain.rb
fast_gettext-2.0.3 lib/fast_gettext/translation_repository/chain.rb
fast_gettext-2.0.2 lib/fast_gettext/translation_repository/chain.rb
fast_gettext-2.0.1 lib/fast_gettext/translation_repository/chain.rb
fast_gettext-2.0.0 lib/fast_gettext/translation_repository/chain.rb