Sha256: c0928a67a06309a48f4ff595b4c2baa0a2d47c1608375e75b850c5409b40adc7
Contents?: true
Size: 1022 Bytes
Versions: 2
Compression:
Stored size: 1022 Bytes
Contents
class Riemann::Dash require 'multi_json' require 'fileutils' require 'set' WS_CONFIG_FILE = "config/config.json" 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 end post '/config' do # Read update request.body.rewind update = MultiJson.decode(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) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
riemann-dash-0.2.1 | lib/riemann/dash/controller/index.rb |
riemann-dash-0.2.0 | lib/riemann/dash/controller/index.rb |