Class: SourceCode
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SourceCode
- Defined in:
- app/models/source_code.rb
Overview
ソースコードを表現するモデル
Instance Method Summary collapse
-
#check_syntax ⇒ Object
シンタックスをチェックする.
-
#digest ⇒ Object
ハッシュ値を計算する.
-
#run(path) ⇒ Object
プログラムを実行する.
Instance Method Details
#check_syntax ⇒ Object
シンタックスをチェックする
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/source_code.rb', line 15 def check_syntax _, stderr_str, status = *open3_capture3_ruby_c return [] if status.success? stderr_str.lines.each.with_object([]) { |line, res| if (md = /^.*:(\d+): (.*)$/.match(line)) res << { row: md[1].to_i, column: 0, message: md[2] } elsif (md = /( +)\^$/.match(line)) res[-1][:column] = md[1].length end } end |
#digest ⇒ Object
ハッシュ値を計算する
37 38 39 |
# File 'app/models/source_code.rb', line 37 def digest Digest::SHA256.hexdigest(data) end |
#run(path) ⇒ Object
プログラムを実行する
29 30 31 32 33 34 |
# File 'app/models/source_code.rb', line 29 def run(path) _, stderr_str, status = *open3_capture3_run_program(path) return [] if status.success? (stderr_str) end |