Sha256: 52fa8e23540e3ec3df4c098418ea0a12ba43b878d87495a9dc5d8ea3ede4b526

Contents?: true

Size: 1.3 KB

Versions: 35

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module I18n
  module Utils
    class << self
      if Hash.method_defined?(:except)
        def except(hash, *keys)
          hash.except(*keys)
        end
      else
        def except(hash, *keys)
          hash = hash.dup
          keys.each { |k| hash.delete(k) }
          hash
        end
      end

      def deep_merge(hash, other_hash, &block)
        deep_merge!(hash.dup, other_hash, &block)
      end

      def deep_merge!(hash, other_hash, &block)
        hash.merge!(other_hash) do |key, this_val, other_val|
          if this_val.is_a?(Hash) && other_val.is_a?(Hash)
            deep_merge(this_val, other_val, &block)
          elsif block_given?
            yield key, this_val, other_val
          else
            other_val
          end
        end
      end

      def deep_symbolize_keys(hash)
        hash.each_with_object({}) do |(key, value), result|
          result[key.respond_to?(:to_sym) ? key.to_sym : key] = deep_symbolize_keys_in_object(value)
          result
        end
      end

      private

      def deep_symbolize_keys_in_object(value)
        case value
        when Hash
          deep_symbolize_keys(value)
        when Array
          value.map { |e| deep_symbolize_keys_in_object(e) }
        else
          value
        end
      end
    end
  end
end

Version data entries

35 entries across 31 versions & 12 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/i18n-1.14.5/lib/i18n/utils.rb
i18n-1.14.6 lib/i18n/utils.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/i18n-1.14.5/lib/i18n/utils.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/i18n-1.14.1/lib/i18n/utils.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/i18n-1.14.1/lib/i18n/utils.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/i18n-1.14.1/lib/i18n/utils.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/i18n-1.14.5/lib/i18n/utils.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/i18n-1.14.5/lib/i18n/utils.rb
i18n-1.14.5 lib/i18n/utils.rb
i18n-1.14.4 lib/i18n/utils.rb
i18n-1.14.3 lib/i18n/utils.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/i18n-1.14.1/lib/i18n/utils.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/i18n-1.14.1/lib/i18n/utils.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/i18n-1.12.0/lib/i18n/utils.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/i18n-1.10.0/lib/i18n/utils.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/i18n-1.14.1/lib/i18n/utils.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/i18n-1.14.1/lib/i18n/utils.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/i18n-1.14.1/lib/i18n/utils.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/i18n-1.14.1/lib/i18n/utils.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/i18n-1.10.0/lib/i18n/utils.rb