Class: Kamerling::Settings

Inherits:
Value
  • Object
show all
Defined in:
lib/kamerling/settings.rb

Instance Method Summary collapse

Methods inherited from Value

vals

Constructor Details

#initialize(args) ⇒ Settings

Returns a new instance of Settings.



9
10
11
12
13
14
15
16
17
18
# File 'lib/kamerling/settings.rb', line 9

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

Instance Method Details

#server_addrsObject



20
21
22
23
24
25
26
# File 'lib/kamerling/settings.rb', line 20

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