File: chain.rb

package info (click to toggle)
ruby-fast-gettext 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 720 kB
  • ctags: 301
  • sloc: ruby: 3,092; makefile: 3
file content (48 lines) | stat: -rw-r--r-- 1,013 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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{|c|c.available_locales}.flatten.uniq
      end

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

      def [](key)
        chain.each do |c|
          result = c[key] and return result
        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