Class: Mxrb::Uml::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/uml/server.rb

Overview

Loopback-only unified viewer for class, activity, and sequence diagrams. rubocop:disable Metrics

Constant Summary collapse

LOOPBACK_HOSTS =
%w[127.0.0.1 ::1 localhost].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, host: '127.0.0.1', port: 4569) ⇒ Server

Returns a new instance of Server.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
# File 'lib/mxrb/uml/server.rb', line 18

def initialize(source, host: '127.0.0.1', port: 4569)
  @source = File.expand_path(source)
  raise ArgumentError, "MPR not found: #{@source}" unless File.file?(@source)

  @host = host.to_s
  raise ArgumentError, 'UML server must bind to loopback' unless LOOPBACK_HOSTS.include?(@host)

  @port = Integer(port)
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



16
17
18
# File 'lib/mxrb/uml/server.rb', line 16

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



16
17
18
# File 'lib/mxrb/uml/server.rb', line 16

def port
  @port
end

#sourceObject (readonly)

Returns the value of attribute source.



16
17
18
# File 'lib/mxrb/uml/server.rb', line 16

def source
  @source
end

Instance Method Details

#shutdownObject



33
# File 'lib/mxrb/uml/server.rb', line 33

def shutdown = @server&.shutdown

#startObject



28
29
30
31
# File 'lib/mxrb/uml/server.rb', line 28

def start
  @server = Http::Server.new(host:, port:) { dispatch(_1, _2) }
  @server.start { yield(_1) if block_given? }
end