Sha256: 68cd40310b9d238f898d42d7c25b8a610de4e6fc0c283db2dea3ac723cf9a7cd

Contents?: true

Size: 811 Bytes

Versions: 18

Compression:

Stored size: 811 Bytes

Contents

module Datacaster
  module I18nValues
    class Key < Base
      attr_reader :keys

      def initialize(keys_or_key, args = {})
        keys = Array(keys_or_key)
        @keys = keys
        @args = args
      end

      def ==(other)
        super && @keys == other.keys
      end

      def resolve
        keys = @keys.select { |x| x[0] != '.' }
        if keys.empty?
          raise RuntimeError.new("No absolute keys among #{@keys.inspect}. Use #i18n_key in addition to #i18n_scope.")
        end
        key = keys.find(&Config.i18n_exists?) || keys.first
        Config.i18n_t.(key, **@args)
      end

      def with_args(args)
        self.class.new(@keys, @args.merge(args))
      end

      def inspect
        "#<#{self.class.name}(#{@keys.inspect}) #{@args.inspect}>"
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
datacaster-4.1.0 lib/datacaster/i18n_values/key.rb
datacaster-4.0.1 lib/datacaster/i18n_values/key.rb
datacaster-3.3.1 lib/datacaster/i18n_values/key.rb
datacaster-3.3.0 lib/datacaster/i18n_values/key.rb
datacaster-3.2.7 lib/datacaster/i18n_values/key.rb
datacaster-3.2.6 lib/datacaster/i18n_values/key.rb
datacaster-3.2.5 lib/datacaster/i18n_values/key.rb
datacaster-3.2.4 lib/datacaster/i18n_values/key.rb
datacaster-3.2.3 lib/datacaster/i18n_values/key.rb
datacaster-3.2.2 lib/datacaster/i18n_values/key.rb
datacaster-3.2.1 lib/datacaster/i18n_values/key.rb
datacaster-3.2.0 lib/datacaster/i18n_values/key.rb
datacaster-3.1.5 lib/datacaster/i18n_values/key.rb
datacaster-3.1.3 lib/datacaster/i18n_values/key.rb
datacaster-3.1.2 lib/datacaster/i18n_values/key.rb
datacaster-3.1.1 lib/datacaster/i18n_values/key.rb
datacaster-3.1.0 lib/datacaster/i18n_values/key.rb
datacaster-3.0.0 lib/datacaster/i18n_values/key.rb