lib/code.rb in code-ruby-0.8.5 vs lib/code.rb in code-ruby-0.9.0

- old
+ new

@@ -1,58 +1,42 @@ # frozen_string_literal: true class Code - EMPTY_STRING = "" GLOBALS = %i[output error context object].freeze DEFAULT_TIMEOUT = 0 def initialize( input, output: StringIO.new, error: StringIO.new, - timeout: DEFAULT_TIMEOUT, - ruby: {} + timeout: DEFAULT_TIMEOUT ) @input = input - @parsed = Timeout.timeout(timeout) { ::Code::Parser.parse(input).to_raw } @output = output @error = error @timeout = timeout || DEFAULT_TIMEOUT - @ruby = ::Code::Ruby.to_code(ruby || {}).code_to_context + @context = Object::Context.new end def self.evaluate( input, - context = EMPTY_STRING, output: StringIO.new, error: StringIO.new, - timeout: DEFAULT_TIMEOUT, - ruby: {} + timeout: DEFAULT_TIMEOUT ) - new(input, output:, error:, timeout:, ruby:).evaluate(context) + new(input, output:, error:, timeout:).evaluate end - def evaluate(context = EMPTY_STRING) + def evaluate Timeout.timeout(timeout) do - context = - if context == EMPTY_STRING - Object::Context.new - else - Code.evaluate( - context, - timeout:, - output:, - error:, - ruby: - ).code_to_context - end - - context = ruby.merge(context) - - Node::Code.new(parsed).evaluate(context:, output:, error:) + Node::Code.new(::Code::Parser.parse(input).to_raw).evaluate( + context:, + output:, + error: + ) end end private - attr_reader :input, :parsed, :timeout, :output, :error, :ruby + attr_reader :input, :timeout, :output, :error, :context end