Class: Madness::ServerBase

Inherits:
Sinatra::Application
  • Object
show all
Defined in:
lib/madness/server_base.rb

Overview

The base class for the sinatra server. Initialize what we can here, but since there are values that will become known only later, the #prepare method is provided.

Direct Known Subclasses

Server

Class Method Summary collapse

Class Method Details

.configObject



47
48
49
# File 'lib/madness/server_base.rb', line 47

def self.config
  Settings.instance
end

.prepareObject

Since we cannot use any config values in the main body of the class, since they will be updated later, we need to set anything that relys on the config values just before running the server. The CommandLine class and the test suite should both call ‘Server.prepare` before calling Server.run!



25
26
27
28
29
30
31
32
# File 'lib/madness/server_base.rb', line 25

def self.prepare
  use Madness::Static, root: "#{config.path}/", urls: %w[/], cascade: true
  set :bind, config.bind
  set :port, config.port

  set_basic_auth if config.auth
  set_tempalate_locations
end

.set_basic_authObject



41
42
43
44
45
# File 'lib/madness/server_base.rb', line 41

def self.set_basic_auth
  use Rack::Auth::Basic, config.auth_realm do |username, password|
    config.auth.split(':') == [username, password]
  end
end

.set_tempalate_locationsObject



34
35
36
37
38
39
# File 'lib/madness/server_base.rb', line 34

def self.set_tempalate_locations
  theme = Theme.new config.theme
  
  set :views, theme.views_path
  set :public_folder, theme.public_path
end