Module: Sinatra::Servant

Defined in:
lib/belphanior/servant/servant.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



10
11
12
13
14
# File 'lib/belphanior/servant/servant.rb', line 10

def self.registered(app)
  if ENV.has_key? "BELPHANIOR_CONFIG_FILE"
    app.set :servant_config_file, ENV["BELPHANIOR_CONFIG_FILE"]
  end
end

Instance Method Details

#servant_initObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/belphanior/servant/servant.rb', line 16

def servant_init
  load_servant_config
  # readonly because changing them involves rebooting the server, so the
  # change cannot be honored.
  servant_config.set_readonly "bind"
  servant_config.set_readonly "port"

  set :bind, servant_config.get("bind")
  set :port, servant_config.get("port")

  # To simplify functionality, we make every request handle synchronously.
  enable :lock

  # default handler for top-level index. A user-defined top-level index
  # created before servant.init is called would override this.
  get '/' do
    server_name = servant_config.get("server_name") || "<TODO: set name>"
    <<EOF
<html>
  <head>
  <title>Belphanior Servant: #{server_name}</title>
  </head>
  <body>
<h1>Belphanior Servant Online</h1>
<h2>#{server_name}</h2>
<p>Hello! I am #{server_name}, and I am happy to serve you.</p>
<p>To learn more about what I can do, check my
   <a href="/protocol">protocol</a>.</p>
<p>Want to know my settings? Check my <a href="/config">config</a>.
  </body>
EOF
  end
end