Class: WebTools::Workspace

Inherits:
Tool
  • Object
show all
Defined in:
lib/web_tools/workspace.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tool

display_name, dont_show!, dont_show?, file_name, inherited, subclasses

Methods included from Support::ServiceHelper

included

Class Method Details

.descriptionObject



6
7
8
# File 'lib/web_tools/workspace.rb', line 6

def self.description
  'Code workspace'
end

Instance Method Details

#debug_on_exceptionObject

Run block in a separate thread, which gets suspended if an error occurs.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/web_tools/workspace.rb', line 44

def debug_on_exception
  response = nil
  client = Thread.start do
    begin
      response = yield
    rescue Exception => e
      entry = Support::ErrorLog.add :thread => Thread.current, :exception => e
      response = json("errorType" => entry.exception.class.inspect,
                      "description" => entry.exception.message,
                      "oop" => entry.object_id)
      Thread.stop
    end
  end
  sleep 0.2 until client.stop?
  response
end

#run_evaluation(text) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/web_tools/workspace.rb', line 61

def run_evaluation(text)
  value = eval(params["text"])
  result = { "klass" => value.class.inspect,
    "string" => value.inspect }
  if value.is_a? Module
    result["dict"] = ""
    result["name"] = value.inspect
    result["cat"]  = ""
  end
  json(result)
rescue SyntaxError => e
  json("errorType" => "compileError",
       "errorDetails" => [[1031, 1, e.message, nil, nil]])
end