Class: RubyQueryHook
- Inherits:
-
Mumukit::Templates::FileHook
- Object
- Mumukit::Templates::FileHook
- RubyQueryHook
- Defined in:
- lib/query_hook.rb
Instance Method Summary collapse
- #build_state(cookie) ⇒ Object
- #command_line(filename) ⇒ Object
- #compile_cookie(cookie) ⇒ Object
- #compile_file_content(r) ⇒ Object
- #compile_query(query) ⇒ Object
- #error_patterns ⇒ Object
- #runtime_error_regexp ⇒ Object
- #syntax_error_regexp ⇒ Object
- #tempfile_extension ⇒ Object
Instance Method Details
#build_state(cookie) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/query_hook.rb', line 51 def build_state() (||[]).map do |statement| <<ruby begin #{statement} rescue end ruby end end |
#command_line(filename) ⇒ Object
32 33 34 |
# File 'lib/query_hook.rb', line 32 def command_line(filename) "ruby #{filename}" end |
#compile_cookie(cookie) ⇒ Object
62 63 64 |
# File 'lib/query_hook.rb', line 62 def () build_state().join("\n") end |
#compile_file_content(r) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/query_hook.rb', line 9 def compile_file_content(r) <<ruby require 'set' class MumukiConsole def self.write(string) end def self.enter_cookie! @@old_stdout = $stdout $stdout = MumukiConsole end def self.exit_cookie! $stdout = @@old_stdout end end #{r.extra} #{r.content} MumukiConsole.enter_cookie! #{(r.)} MumukiConsole.exit_cookie! #{compile_query(r.query)} ruby end |
#compile_query(query) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/query_hook.rb', line 43 def compile_query(query) if query.start_with? 'def ' "#{query}\nputs \"=> nil\"" else "puts('=> ' + (#{query}).inspect)" end end |
#error_patterns ⇒ Object
36 37 38 39 40 41 |
# File 'lib/query_hook.rb', line 36 def error_patterns [ Mumukit::ErrorPattern::Failed.new(runtime_error_regexp), Mumukit::ErrorPattern::Errored.new(syntax_error_regexp) ] end |
#runtime_error_regexp ⇒ Object
66 67 68 69 70 71 |
# File 'lib/query_hook.rb', line 66 def runtime_error_regexp # Matches lines like: # * from /tmp/mumuki.compile20170404-3221-1db8ntk.rb:17:in `<main>' # * /tmp/mumuki.compile20170404-3221-1db8ntk.rb:17:in `respond_to?': /(from )?(.)+\.rb:(\d)+:in `([\w|<|>|?|!|+|*|-|\/|=]+)'(:)?/ end |
#syntax_error_regexp ⇒ Object
73 74 75 |
# File 'lib/query_hook.rb', line 73 def syntax_error_regexp /.+?\.rb:\d+: (?m)(?=.*syntax error)/ end |
#tempfile_extension ⇒ Object
5 6 7 |
# File 'lib/query_hook.rb', line 5 def tempfile_extension '.rb' end |