Class: Gitlab::Utils::SafeInlineHash

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/utils/safe_inline_hash.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, prefix: nil, connector: '.') ⇒ SafeInlineHash

Validates the hash size using ‘Gitlab::Utils::DeepSize` before merging keys using `Gitlab::Utils::InlineHash`



7
8
9
# File 'lib/gitlab/utils/safe_inline_hash.rb', line 7

def initialize(hash, prefix: nil, connector: '.')
  @hash = hash
end

Class Method Details

.merge_keys!(hash, prefix: nil, connector: '.') ⇒ Object



11
12
13
# File 'lib/gitlab/utils/safe_inline_hash.rb', line 11

def self.merge_keys!(hash, prefix: nil, connector: '.')
  new(hash).merge_keys!(prefix: prefix, connector: connector)
end

Instance Method Details

#merge_keys!(prefix:, connector:) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
# File 'lib/gitlab/utils/safe_inline_hash.rb', line 15

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