Module: Gitlab::License::Boundary

Defined in:
lib/gitlab/license/boundary.rb

Constant Summary collapse

BOUNDARY_START =
/(\A|\r?\n)-*BEGIN .+? LICENSE-*\r?\n/.freeze
BOUNDARY_END =
/\r?\n-*END .+? LICENSE-*(\r?\n|\z)/.freeze

Class Method Summary collapse

Class Method Details

.add_boundary(data, product_name) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/license/boundary.rb', line 8

def add_boundary(data, product_name)
  data = remove_boundary(data)

  product_name.upcase!

  pad = lambda do |message, width|
    total_padding = [width - message.length, 0].max

    padding = total_padding / 2.0
    [
      "-" * padding.ceil,
      message,
      "-" * padding.floor
    ].join
  end

  [
    pad.call("BEGIN #{product_name} LICENSE", 60),
    data.strip,
    pad.call("END #{product_name} LICENSE", 60)
  ].join("\n")
end

.remove_boundary(data) ⇒ Object


31
32
33
34
35
36
# File 'lib/gitlab/license/boundary.rb', line 31

def remove_boundary(data)
  after_boundary  = data.split(BOUNDARY_START).last
  in_boundary     = after_boundary.split(BOUNDARY_END).first

  in_boundary
end