lib/riemann/dash/controller/index.rb in riemann-dash-0.2.1 vs lib/riemann/dash/controller/index.rb in riemann-dash-0.2.3
- old
+ new
@@ -1,50 +1,20 @@
-class Riemann::Dash
- require 'multi_json'
- require 'fileutils'
- require 'set'
-
- WS_CONFIG_FILE = "config/config.json"
-
+class Riemann::Dash::App
get '/' do
erb :index, :layout => false
end
get '/config', :provides => 'json' do
- if File.exists? WS_CONFIG_FILE
- send_file WS_CONFIG_FILE, :type => :json
- else
- MultiJson.encode({})
- end
+ content_type "application/json"
+ config.read_ws_config
end
post '/config' do
# Read update
request.body.rewind
- update = MultiJson.decode(request.body.read)
+ config.update_ws_config(request.body.read)
- # Read old config
- if File.exists? WS_CONFIG_FILE
- old = MultiJson.decode File.read WS_CONFIG_FILE
- else
- old = {}
- end
-
- new = {}
-
- # Server
- new['server'] = update['server'] or old['server']
-
- p update['workspaces']
- new['workspaces'] = update['workspaces'] or old['workspaces']
-
- # Save new config
- FileUtils.mkdir_p 'config'
- File.open(WS_CONFIG_FILE, 'w') do |f|
- f.write(MultiJson.encode(new))
- end
-
# Return current config
content_type "application/json"
- MultiJson.encode(new)
+ config.read_ws_config
end
-end
+end
\ No newline at end of file