Sha256: 22ab45c8c30dcd4aea1f505b88739047331212f332c426fa49e7c153d4247b62

Contents?: true

Size: 926 Bytes

Versions: 9

Compression:

Stored size: 926 Bytes

Contents

# frozen_string_literal: true

module LokaliseManager
  module Utils
    # Common helper methods for hashes
    module HashUtils
      refine Hash do
        # Deeply merges two hashes
        # Taken from https://github.com/rails/rails/blob/83217025a171593547d1268651b446d3533e2019/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
        def deep_merge(other_hash, &block)
          dup.deep_merge!(other_hash, &block)
        end

        # Same as +deep_merge+, but modifies +self+.
        def deep_merge!(other_hash, &block)
          merge!(other_hash) do |key, this_val, other_val|
            if this_val.is_a?(Hash) && other_val.is_a?(Hash)
              this_val.deep_merge(other_val, &block)
            elsif block
              yield(key, this_val, other_val)
            else
              other_val
            end
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lokalise_manager-6.0.0 lib/lokalise_manager/utils/hash_utils.rb
lokalise_manager-5.1.2 lib/lokalise_manager/utils/hash_utils.rb
lokalise_manager-5.1.0 lib/lokalise_manager/utils/hash_utils.rb
lokalise_manager-5.0.0 lib/lokalise_manager/utils/hash_utils.rb
lokalise_manager-4.0.0 lib/lokalise_manager/utils/hash_utils.rb
lokalise_manager-3.3.0 lib/lokalise_manager/utils/hash_utils.rb
lokalise_manager-3.2.0 lib/lokalise_manager/utils/hash_utils.rb
lokalise_manager-3.1.0 lib/lokalise_manager/utils/hash_utils.rb
lokalise_manager-3.0.0 lib/lokalise_manager/utils/hash_utils.rb