Class: SourceCode
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SourceCode
- Includes:
- RubyToBlock
- Defined in:
- app/models/source_code.rb
Overview
ソースコードを表現するモデル
Constant Summary
Constants included from RubyToBlock
RubyToBlock::SUCCESS_DATA_MOCK, RubyToBlock::SUCCESS_XML_MOCK
Instance Method Summary collapse
-
#check_syntax ⇒ Object
シンタックスをチェックする.
-
#digest ⇒ Object
ハッシュ値を計算する.
-
#run(path) ⇒ Object
プログラムを実行する.
Methods included from RubyToBlock
Instance Method Details
#check_syntax ⇒ Object
シンタックスをチェックする
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/source_code.rb', line 18 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
ハッシュ値を計算する
40 41 42 |
# File 'app/models/source_code.rb', line 40 def digest Digest::SHA256.hexdigest(data) end |
#run(path) ⇒ Object
プログラムを実行する
32 33 34 35 36 37 |
# File 'app/models/source_code.rb', line 32 def run(path) _, stderr_str, status = *open3_capture3_run_program(path) return [] if status.success? (stderr_str) end |