class Sidedock::Ports

Public Class Methods

new(machine_id, port_mapping) click to toggle source
# File lib/sidedock/ports.rb, line 5
def initialize(machine_id, port_mapping)
  @port_mapping = port_mapping
  @machine_id = machine_id
  define_port_accessors if @port_mapping.present?
end

Public Instance Methods

define_port_accessors() click to toggle source
# File lib/sidedock/ports.rb, line 11
def define_port_accessors
  @port_mapping.each do |name, port_number|
    raise "#{name} cannot be used as port mapping key" if respond_to? :name

    port = find do |port|
      port.internal == port_number
    end

    raise "Port #{port_number} not exposed by Dockerfile, " \
          "change or remove it in the `port_mapping` option. "\
          "Available: #{each.to_h}" unless port.present?

    define_singleton_method name do
      port.external
    end
  end
end
each(&block) click to toggle source
# File lib/sidedock/ports.rb, line 29
def each(&block)
  ports.each &block
end
ports() click to toggle source
# File lib/sidedock/ports.rb, line 33
def ports
  @ports ||= raw_configuration_lines.map do |raw_configuration|
    PortConfiguration.new raw_configuration
  end
end
raw_configuration_lines() click to toggle source
# File lib/sidedock/ports.rb, line 39
def raw_configuration_lines
  @raw_configuration_lines ||= machine.execute("port #{@machine_id}").strip.split("\n")
end