Class: LinterServer

Inherits:
Object
  • Object
show all
Defined in:
lib/servers/linter_server.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.start(port) ⇒ Object



46
47
48
49
# File 'lib/servers/linter_server.rb', line 46

def self.start(port)
  log = WEBrick::Log.new $stdout,1
  Rack::Handler::WEBrick.run(LinterServer.new, :Port => port,Logger: log )
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/servers/linter_server.rb', line 12

def call(env)
  req = Rack::Request.new(env)

  case req.path
  when "/configuration"
    if req.post?
      process_form(req)
    elsif req.get?
      configurations_page
    end
  end

end

#configurations_pageObject



26
27
28
29
30
# File 'lib/servers/linter_server.rb', line 26

def configurations_page
  configuration_page = ConfigurationPageFacade.AssemblePage

  return [200, { 'Content-Type' => 'text/html' }, [configuration_page]]
end

#process_form(req) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/servers/linter_server.rb', line 32

def process_form(req)
  new_conf = URI.decode_www_form(req.body.read)
  new_conf_hash = Hash[new_conf.map {|key, value| [key, value]}]

  begin
    ConfigurationPageFacade.ApplyConfigurations(new_conf_hash)
    ConfigurationFileFacade.SaveConfigurations
  rescue StandardError => error
    return [400, { 'Content-Type' => 'text/plain' }, ["Error: #{error.message}"]]
  end

  return [200, { 'Content-Type' => 'text/plain' }, ["Changes saved successfully"]]
end