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
- #tempfile_extension ⇒ Object
Instance Method Details
#build_state(cookie) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/query_hook.rb', line 42 def build_state() (||[]).map do |statement| <<ruby begin #{statement} rescue end ruby end end |
#command_line(filename) ⇒ Object
30 31 32 |
# File 'lib/query_hook.rb', line 30 def command_line(filename) "ruby #{filename}" end |
#compile_cookie(cookie) ⇒ Object
53 54 55 |
# File 'lib/query_hook.rb', line 53 def () build_state().join("\n") end |
#compile_file_content(r) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/query_hook.rb', line 8 def compile_file_content(r) <<ruby 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
34 35 36 37 38 39 40 |
# File 'lib/query_hook.rb', line 34 def compile_query(query) if query.start_with? 'def ' "#{query}\nputs \"=> nil\"" else "print('=> ' + (#{query}).inspect)" end end |
#tempfile_extension ⇒ Object
4 5 6 |
# File 'lib/query_hook.rb', line 4 def tempfile_extension '.rb' end |