Class: Shrub::CodeRunner
- Inherits:
-
Object
- Object
- Shrub::CodeRunner
- Defined in:
- lib/drb_shrub_server.rb
Instance Method Summary collapse
-
#initialize(ruby_exe) ⇒ CodeRunner
constructor
A new instance of CodeRunner.
- #run_code(username, pwd, code) ⇒ Object
Constructor Details
#initialize(ruby_exe) ⇒ CodeRunner
Returns a new instance of CodeRunner.
5 6 7 8 9 10 |
# File 'lib/drb_shrub_server.rb', line 5 def initialize(ruby_exe) @ruby_exe = ruby_exe @users = { 'root' => 'qwedsa' } end |
Instance Method Details
#run_code(username, pwd, code) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/drb_shrub_server.rb', line 12 def run_code(username, pwd, code) raise 'Invalid username and pwd' if @users[username] == nil || @users[username] != pwd io = IO.popen("#{@ruby_exe} 2>&1", "w+") io.write code io.close_write result = io.readlines.join io.close_read return result end |