Module: Ruflet

Defined in:
lib/ruflet/server.rb,
lib/ruflet_server.rb,
lib/ruflet/version.rb,
lib/ruflet/server/wire_codec.rb,
lib/ruflet/server/web_socket_connection.rb

Defined Under Namespace

Classes: Server, WebSocketConnection, WireCodec

Constant Summary collapse

VERSION =
"0.0.14"

Class Method Summary collapse

Class Method Details

.run(entrypoint = nil, host: "0.0.0.0", port: 8550, &block) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ruflet_server.rb', line 9

def run(entrypoint = nil, host: "0.0.0.0", port: 8550, &block)
  callback = entrypoint || block
  raise ArgumentError, "Ruflet.run requires a callable entrypoint or block" unless callback.respond_to?(:call)

  interceptor = run_interceptor
  if interceptor
    result = interceptor.call(entrypoint: callback, host: host, port: port)
    return result unless result == :pass
  end

  Server.new(host: host, port: port) do |page|
    callback.call(page)
  end.start
end