Class: CodersDojo

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

Instance Method Summary collapse

Constructor Details

#initialize(params, hostname = "http://www.codersdojo.com") ⇒ CodersDojo

Returns a new instance of CodersDojo.



11
12
13
14
# File 'lib/codersdojo.rb', line 11

def initialize params, hostname = "http://www.codersdojo.com"
  @params = params
  @hostname = hostname
end

Instance Method Details

#called_from_spec?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/codersdojo.rb', line 50

def called_from_spec?
  @params and @params[0] == "spec"
end

#handle_internal_server_error(view, exception) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/codersdojo.rb', line 16

def handle_internal_server_error view, exception
  log_file_name = 'error.log'
  File.open(log_file_name, 'w') do |f|  
    f.puts "### Error ###"
     f.puts exception.message 
     f.puts
     f.puts "### Client backtrace ###"
    f.puts exception.backtrace
     f.puts
     f.puts "### HTTP Body ###"     
     f.puts exception.http_body
   end  
  view.show_internal_server_error exception, log_file_name
end

#runObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/codersdojo.rb', line 31

def run
if called_from_spec? then return end
shell = ShellWrapper.new
scaffolder = Scaffolder.new shell
view = ConsoleView.new scaffolder

begin
  command_config = CommandConfiguration.new shell, view, scaffolder, @hostname
  arg_parser = ArgumentParser.new command_config.commands
  command = arg_parser.parse @params
rescue ShellArgumentException => e
  view.show_unknwon_command_message e.command
rescue PropertyFileMissingException => e
  view.show_properties_file_missing_error e.filename
rescue RestClient::InternalServerError => e
  handle_internal_server_error view, e
end
end