summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/build/port.rb
blob: 6c4656ffea23de20158ad36b8bf2af122979d623 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

module Gitlab
  module Ci
    module Build
      class Port
        DEFAULT_PORT_NAME = 'default_port'.freeze
        DEFAULT_PORT_PROTOCOL = 'http'.freeze

        attr_reader :number, :protocol, :name

        def initialize(port)
          @name = DEFAULT_PORT_NAME
          @protocol = DEFAULT_PORT_PROTOCOL

          case port
          when Integer
            @number = port
          when Hash
            @number = port[:number]
            @protocol = port.fetch(:protocol, @protocol)
            @name = port.fetch(:name, @name)
          end
        end

        def valid?
          @number.present?
        end
      end
    end
  end
end