Sha256: 70a3aacb426e77d5c9e8800ce5e4ab65363ace52d46094f49596938b36faa233

Contents?: true

Size: 915 Bytes

Versions: 1

Compression:

Stored size: 915 Bytes

Contents

require 'optparse'
require_relative 'addr'
require_relative 'value'

module Kamerling
  class Settings < Value
    vals db: String, host: String, http: Integer, tcp: Integer, udp: Integer

    def initialize(args)
      super db: 'sqlite::memory:', host: '127.0.0.1'
      OptionParser.new do |opt|
        opt.on("--db #{db}", String, 'database') { |db|   self.db   = db   }
        opt.on("--host #{host}", String, 'host') { |host| self.host = host }
        opt.on('--http 0', Integer, 'HTTP port') { |http| self.http = http }
        opt.on('--tcp 0',  Integer, 'TCP port')  { |tcp|  self.tcp  = tcp  }
        opt.on('--udp 0',  Integer, 'UDP port')  { |udp|  self.udp  = udp  }
      end.parse! args
    end

    def server_addrs
      {
        http: Addr[host, http, :TCP],
        tcp:  Addr[host, tcp,  :TCP],
        udp:  Addr[host, udp,  :UDP],
      }.select { |_, addr| addr.port }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kamerling-0.0.3 lib/kamerling/settings.rb