Class: Gitlab::RepositorySizeChecker

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

Overview

Centralized class for repository size related calculations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_size_proc:, limit:, enabled: true) ⇒ RepositorySizeChecker

Returns a new instance of RepositorySizeChecker.

Parameters:

  • current_size_proc (Proc)

    returns repository size in bytes


9
10
11
12
13
# File 'lib/gitlab/repository_size_checker.rb', line 9

def initialize(current_size_proc:, limit:, enabled: true)
  @current_size_proc = current_size_proc
  @limit = limit
  @enabled = enabled && limit != 0
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit


6
7
8
# File 'lib/gitlab/repository_size_checker.rb', line 6

def limit
  @limit
end

Instance Method Details

#above_size_limit?Boolean

Returns:

  • (Boolean)

24
25
26
27
28
# File 'lib/gitlab/repository_size_checker.rb', line 24

def above_size_limit?
  return false unless enabled?

  current_size > limit
end

#changes_will_exceed_size_limit?(change_size) ⇒ Boolean

Parameters:

  • change_size (int)

    in bytes

Returns:

  • (Boolean)

31
32
33
34
35
# File 'lib/gitlab/repository_size_checker.rb', line 31

def changes_will_exceed_size_limit?(change_size)
  return false unless enabled?

  change_size > limit || exceeded_size(change_size) > 0
end

#current_sizeInteger

Returns bytes.

Returns:

  • (Integer)

    bytes


16
17
18
# File 'lib/gitlab/repository_size_checker.rb', line 16

def current_size
  @current_size ||= @current_size_proc.call
end

#enabled?Boolean

Returns:

  • (Boolean)

20
21
22
# File 'lib/gitlab/repository_size_checker.rb', line 20

def enabled?
  @enabled
end

#error_messageObject


42
43
44
# File 'lib/gitlab/repository_size_checker.rb', line 42

def error_message
  @error_message_object ||= Gitlab::RepositorySizeErrorMessage.new(self)
end

#exceeded_size(change_size = 0) ⇒ Object

Parameters:

  • change_size (int) (defaults to: 0)

    in bytes


38
39
40
# File 'lib/gitlab/repository_size_checker.rb', line 38

def exceeded_size(change_size = 0)
  current_size + change_size - limit
end