debian-mirror-gitlab/lib/gitlab/utils/safe_inline_hash.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
775 B
Ruby
Raw Permalink Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
module Gitlab
module Utils
class SafeInlineHash
# Validates the hash size using `Gitlab::Utils::DeepSize` before merging keys using `Gitlab::Utils::InlineHash`
def initialize(hash, prefix: nil, connector: '.')
@hash = hash
end
def self.merge_keys!(hash, prefix: nil, connector: '.')
new(hash).merge_keys!(prefix: prefix, connector: connector)
end
def merge_keys!(prefix:, connector:)
raise ArgumentError, 'The Hash is too big' unless valid?
Gitlab::Utils::InlineHash.merge_keys(hash, prefix: prefix, connector: connector)
end
private
attr_reader :hash
def valid?
Gitlab::Utils::DeepSize.new(hash).valid?
end
end
end
end