Module: Sinatra::ServantConfig

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/belphanior/servant/servant_config.rb', line 28

def self.registered(app)
  app.set :servant_config_file, ServantConfigHelper::DEFAULT_CONFIG_PATH
  app.set :servant_config_db, ServantConfigDb.new(
<<EOF
  {
"ip":"127.0.0.1",
"port": "80"
  }
EOF
  )
  
  app.get '/config' do
    BelphaniorServantHelper.text_out_as_json(settings.servant_config_db.to_json)
  end

  app.get '/config/:name' do
    [200, settings.servant_config_db.get(params[:name])]
  end

  app.post '/config/:name' do
    old_value = settings.servant_config_db.get(params[:name])
    begin
      settings.servant_config_db.set(params[:name], request.body.read)
      ServantConfigHelper.write_config_file(
        settings.servant_config_file, settings.servant_config_db)
      return [200, old_value]
    rescue ServantConfigException => e
      return [500, "Could not write config: #{e}"]
    end
  end
end

Instance Method Details

#load_servant_configObject



59
60
61
62
# File 'lib/belphanior/servant/servant_config.rb', line 59

def load_servant_config
  set(:servant_config_db, ServantConfigHelper.prepare_config_file(
    servant_config_file, servant_config_db))
end

#servant_configObject



63
64
65
# File 'lib/belphanior/servant/servant_config.rb', line 63

def servant_config
  servant_config_db
end