Class: Gitlab::Utils::DeepSize

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

Constant Summary collapse

Error =
Class.new(StandardError)
TooMuchDataError =
Class.new(Error)
DEFAULT_MAX_SIZE =
1.megabyte
DEFAULT_MAX_DEPTH =
100

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, max_size: DEFAULT_MAX_SIZE, max_depth: DEFAULT_MAX_DEPTH) ⇒ DeepSize

Returns a new instance of DeepSize.


14
15
16
17
18
19
20
21
22
# File 'lib/gitlab/utils/deep_size.rb', line 14

def initialize(root, max_size: DEFAULT_MAX_SIZE, max_depth: DEFAULT_MAX_DEPTH)
  @root = root
  @max_size = max_size || DEFAULT_MAX_SIZE
  @max_depth = max_depth || DEFAULT_MAX_DEPTH
  @size = 0
  @depth = 0

  evaluate
end

Class Method Details

.human_default_max_sizeObject


28
29
30
# File 'lib/gitlab/utils/deep_size.rb', line 28

def self.human_default_max_size
  ActiveSupport::NumberHelper.number_to_human_size(DEFAULT_MAX_SIZE)
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)

24
25
26
# File 'lib/gitlab/utils/deep_size.rb', line 24

def valid?
  !too_big? && !too_deep?
end