vmpooler/lib/vmpooler/api.rb
Colin 1408f35867 (QENG-1906) Refactor initialize to allow config passing
Prior to this commit, several pieces of vmpooler performed configuration
and initialization steps within 'initialize'. This made it difficult to
pass in mock objects for testing purposes.

This commit performs a single configuration and passes the results to
the various pieces of vmpooler.
2015-03-30 14:23:06 -07:00

47 lines
940 B
Ruby

module Vmpooler
class API < Sinatra::Base
def initialize
super
end
set :environment, :production
not_found do
content_type :json
result = {
ok: false
}
JSON.pretty_generate(result)
end
get '/' do
erb :dashboard, locals: {
site_name: $config[:config]['site_name'] || '<b>vmpooler</b>'
}
end
%w( dashboard reroute v1 ).each do |lib|
begin
require "api/#{lib}"
rescue LoadError
require File.expand_path(File.join(File.dirname(__FILE__), 'api', lib))
end
end
use Vmpooler::API::Dashboard
use Vmpooler::API::Reroute
use Vmpooler::API::V1
def configure(config, redis, environment = :production)
self.settings.set :config, config
self.settings.set :redis, redis
self.settings.set :environment, environment
end
def execute!
self.settings.run!
end
end
end