Class: Baha::ContainerOptions::ExposedPorts

Inherits:
Option
  • Object
show all
Defined in:
lib/baha/container_options/exposed_ports.rb

Constant Summary

Constants inherited from Option

Option::KEYS

Instance Attribute Summary

Attributes inherited from Option

#config_key, #key, #value

Instance Method Summary collapse

Methods inherited from Option

#eql?, #inspect

Constructor Details

#initialize(*args) ⇒ ExposedPorts

Returns a new instance of ExposedPorts.



6
7
8
# File 'lib/baha/container_options/exposed_ports.rb', line 6

def initialize(*args)
  super(:exposedports,*args)
end

Instance Method Details

#apply(config) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/baha/container_options/exposed_ports.rb', line 9

def apply(config)
  unless config.has_key?('ExposedPorts')
    config['ExposedPorts'] = {}
  end
  @value.each do |port|
    case port
      when Fixnum
        config['ExposedPorts']["#{port}/tcp"] = {}
      when String
        if port.match(/^\d+$/)
          config['ExposedPorts']["#{port}/tcp"] = {}
        else
          config['ExposedPorts'][port] = {}
        end
    end
  end
end

#validate!Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/baha/container_options/exposed_ports.rb', line 27

def validate!
  raise ERROR("should be an array") unless @value.kind_of?(Array)
  @value.each_with_index do |item,index|
    if item.kind_of?(String)
      unless /(\d+)(\/(tcp|udp))?/ =~ item
        raise ERROR("#{index}: '#{item}' should be in the form 8080/tcp")
      end
    end
  end
end