Class: GobstonesPrecompileHook
- Inherits:
-
Mumukit::Templates::FileHook
- Object
- Mumukit::Templates::FileHook
- GobstonesPrecompileHook
- Defined in:
- lib/precompile_hook.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
2
Instance Attribute Summary collapse
-
#batch ⇒ Object
Returns the value of attribute batch.
Instance Method Summary collapse
- #add_missing_headers!(request) ⇒ Object
- #command_line(filename) ⇒ Object
- #compile(request) ⇒ Object
- #compile_file_content(request) ⇒ Object
- #locale_argument ⇒ Object
- #post_process_file(_file, result, status) ⇒ Object
- #tempfile_extension ⇒ Object
- #timeout ⇒ Object
- #timeout_argument ⇒ Object
Instance Attribute Details
#batch ⇒ Object
Returns the value of attribute batch.
2 3 4 |
# File 'lib/precompile_hook.rb', line 2 def batch @batch end |
Instance Method Details
#add_missing_headers!(request) ⇒ Object
38 39 40 |
# File 'lib/precompile_hook.rb', line 38 def add_missing_headers!(request) request.test.gsub! /(.*(initial_board|final_board): \|.*\n)(?!.*GBB\/1\.0.*)/, "\\1 GBB/1.0\\3\n" end |
#command_line(filename) ⇒ Object
13 14 15 |
# File 'lib/precompile_hook.rb', line 13 def command_line(filename) "gobstones-cli --batch #{filename} #{locale_argument} #{timeout_argument}" end |
#compile(request) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/precompile_hook.rb', line 29 def compile(request) add_missing_headers! request @locale = request[:locale] file = super request struct request.to_h.merge precompiled_batch: @batch, precompiled_result: run!(file) end |
#compile_file_content(request) ⇒ Object
42 43 44 45 |
# File 'lib/precompile_hook.rb', line 42 def compile_file_content(request) @batch = Gobstones::BatchParser.parse(request) @batch.to_json end |
#locale_argument ⇒ Object
17 18 19 |
# File 'lib/precompile_hook.rb', line 17 def locale_argument "--language #{@locale}" if @locale end |
#post_process_file(_file, result, status) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/precompile_hook.rb', line 47 def post_process_file(_file, result, status) if status.passed? result = result.parse_as_json status = :aborted if is_timeout? result and !expects_timeout? end [result, status] end |
#tempfile_extension ⇒ Object
9 10 11 |
# File 'lib/precompile_hook.rb', line 9 def tempfile_extension '.json' end |
#timeout ⇒ Object
25 26 27 |
# File 'lib/precompile_hook.rb', line 25 def timeout (ENV['MUMUKI_GOBSTONES_TIMEOUT'] || DEFAULT_TIMEOUT).to_i * 1000 end |
#timeout_argument ⇒ Object
21 22 23 |
# File 'lib/precompile_hook.rb', line 21 def timeout_argument "--timeout " + timeout.to_s end |