# HG changeset patch # User jittat # Date 2008-03-06 03:44:08 # Node ID 7df73373290be5d51ba3e1aeb158eb9e8d05761f # Parent d108852b6289037b078a1610c0be9a6a9be09fa3 added name_of to TestRequest for dealing with null problem git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@87 6386c4cd-e34a-4fa8-8920-d93eb39b512e diff --git a/app/models/test_request.rb b/app/models/test_request.rb --- a/app/models/test_request.rb +++ b/app/models/test_request.rb @@ -1,3 +1,16 @@ +# +# A TestRequest is a composition of submission with user's testdata. +# +# Note about TestRequest#problem: Usually, A TestRequest has to be +# associated with a problem, so that execution environment can be +# determined. However, to be more flexible, we have to ensure that +# it works as well with problem=nil. In this case, we shall provide +# a "default" execution environment for it. This can be done +# seamlessly by using TestRequest#name_of when retrieving the name +# of the problem: name_of would return problem.name when +# problem!=nil and it would return "default" when problem=nil. +# + require 'fileutils' class TestRequest < Task @@ -39,9 +52,17 @@ test_request end + def self.name_of(problem) + if problem!=nil + problem.name + else + "default" + end + end + protected def self.input_file_name(user,problem) - problem_name = (problem!=nil) ? problem.name : "" + problem_name = TestRequest.name_of(problem) begin tmpname = TEST_REQUEST_INPUT_FILE_DIR + "/#{user.login}/#{problem_name}/#{rand(10000)}" end while File.exists?(tmpname)