class RubyQueryHook

Public Instance Methods

build_state(cookie) click to toggle source
# File lib/query_hook.rb, line 51
  def build_state(cookie)
    (cookie||[]).map do |statement|
    <<ruby
  begin
    #{statement}
  rescue
  end
ruby
    end
  end
command_line(filename) click to toggle source
# File lib/query_hook.rb, line 32
def command_line(filename)
  "ruby #{filename}"
end
compile_file_content(r) click to toggle source
# 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!
    #{compile_cookie(r.cookie)}
    MumukiConsole.exit_cookie!
    #{compile_query(r.query)}
ruby
  end
compile_query(query) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/query_hook.rb, line 73
def syntax_error_regexp
  /.+?\.rb:\d+: (?m)(?=.*syntax error)/
end
tempfile_extension() click to toggle source
# File lib/query_hook.rb, line 5
def tempfile_extension
  '.rb'
end