Class: Gitlab::Git::Patches::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/git/patches/collection.rb

Constant Summary collapse

MAX_PATCH_SIZE =
2.megabytes

Instance Method Summary collapse

Constructor Details

#initialize(one_or_more_patches) ⇒ Collection

Returns a new instance of Collection.


9
10
11
12
13
# File 'lib/gitlab/git/patches/collection.rb', line 9

def initialize(one_or_more_patches)
  @patches = Array(one_or_more_patches).map do |patch_content|
    Gitlab::Git::Patches::Patch.new(patch_content)
  end
end

Instance Method Details

#contentObject


15
16
17
# File 'lib/gitlab/git/patches/collection.rb', line 15

def content
  @patches.map(&:content).join("\n")
end

#sizeObject

rubocop: disable CodeReuse/ActiveRecord `@patches` is not an `ActiveRecord` relation, but an `Enumerable` We're using sum from `ActiveSupport`


26
27
28
# File 'lib/gitlab/git/patches/collection.rb', line 26

def size
  @size ||= @patches.sum(&:size)
end

#valid_size?Boolean

Returns:

  • (Boolean)

19
20
21
# File 'lib/gitlab/git/patches/collection.rb', line 19

def valid_size?
  size < MAX_PATCH_SIZE
end