Sha256: ed0913c3e26ebd02e9f88b0c743ea41a8a3337fe34923e795888990743ebc330

Contents?: true

Size: 757 Bytes

Versions: 18

Compression:

Stored size: 757 Bytes

Contents

module Datacaster
  module ContextNodes
    class I18nKeysMapper < Datacaster::ContextNode
      def initialize(base, mapping)
        super(base)
        @mapping = mapping
        @from_keys = @mapping.keys
      end

      private

      def transform_errors(errors)
        return errors unless errors.length == 1 && errors.is_a?(Array)

        error = errors.first
        return errors unless error.is_a?(I18nValues::Key) || error.is_a?(I18nValues::Key)

        keys = error.respond_to?(:keys) ? error.keys : [error.key]
        key_to_remap = keys.find { |x| @from_keys.include?(x) }
        return errors if key_to_remap.nil?
        new_key = @mapping[key_to_remap]

        [I18nValues::Key.new(new_key, error.args)]
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

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