File: eval.rb

package info (click to toggle)
groonga 15.2.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 188,332 kB
  • sloc: ansic: 772,759; cpp: 52,395; ruby: 40,554; javascript: 10,250; yacc: 7,045; sh: 5,627; python: 2,821; makefile: 1,679
file content (36 lines) | stat: -rw-r--r-- 906 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module Groonga
  module Ruby
    class EvalCommand < Command
      register("ruby_eval",
               [
                 "script",
               ])

      def run_body(input)
        script = input[:script]
        unless script.is_a?(String)
          message = "script must be a string: <#{script.inspect}>"
          raise Groonga::InvalidArgument, message
        end

        eval_context = EvalContext.new
        begin
          result = eval_context.eval(script)
        rescue Exception => error
          writer.map("result", 1) do
            writer.write("exception")
            writer.map("exception", 1) do
              writer.write("message")
              writer.write(error.message)
            end
          end
        else
          writer.map("result", 1) do
            writer.write("value")
            writer.write(result)
          end
        end
      end
    end
  end
end