Class: Adsf::Server

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

Instance Method Summary collapse

Constructor Details

#initialize(root:, live: false, host: '127.0.0.1', port: 3000, index_filenames: ['index.html'], auto_extensions: [], handler: nil) ⇒ Server

Returns a new instance of Server.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/adsf/server.rb', line 5

def initialize(
  root:,
  live: false,
  host: '127.0.0.1',
  port: 3000,
  index_filenames: ['index.html'],
  auto_extensions: [],
  handler: nil
)
  @root = root
  @live = live
  @index_filenames = index_filenames
  @auto_extensions = auto_extensions
  @host = host
  @port = port
  @handler = handler

  @q = SizedQueue.new(1)
end

Instance Method Details

#runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/adsf/server.rb', line 25

def run
  handler = build_handler
  app = build_app(
    root: @root,
    index_filenames: @index_filenames,
    auto_extensions: @auto_extensions,
  )
  start_watcher if @live

  url = "http://#{@host}:#{@port}/"
  puts "View the site at #{url}"

  handler.run(app, Host: @host, Port: @port) do |server|
    wait_for_stop_async(server)
  end
end

#stopObject



42
43
44
# File 'lib/adsf/server.rb', line 42

def stop
  @q << true
end