Sha256: c4417fd4179deb0c591bc2db4ee32f54b4ed5e49ab371fb5a37cefbfdaca5fa2

Contents?: true

Size: 914 Bytes

Versions: 1

Compression:

Stored size: 914 Bytes

Contents

require 'active_support/hash_with_indifferent_access'

module HashWithIndifferentAccessDuplicateWarning::HashWithIndifferentAccess
  def initialize(constructor = {})
    super

    warning_duplicate_keys(constructor) if constructor.respond_to?(:to_hash)
  end

  private

  def warning_duplicate_keys(original)
    original.to_hash.keys.each do |k|
      # if string key and symbol key exist, show warning
      # (if symbol key exist, check there is string key we don't need other direction check)
      next unless k.is_a?(Symbol)

      converted_key = convert_key(k)
      next unless original.key?(converted_key)

      msg = "warning: key :#{k} and '#{converted_key}' is duplicated and overwritten"
      HashWithIndifferentAccessDuplicateWarning.write_error_log(msg)
    end
  end
end

::ActiveSupport::HashWithIndifferentAccess.prepend(HashWithIndifferentAccessDuplicateWarning::HashWithIndifferentAccess)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hash_with_indifferent_access_duplicate_warning-0.1.0 lib/hash_with_indifferent_access_duplicate_warning/active_support/hash_with_indifferent_access.rb