Sha256: 88bca91ebd7815510132950521744f3400c070b5797fbde36e13ac07eb7afaf3

Contents?: true

Size: 969 Bytes

Versions: 1

Compression:

Stored size: 969 Bytes

Contents

# frozen_string_literal: true

module ScriptEngine
  class << self
    def engine
      @engine ||= ScriptCore::Engine.new Rails.root.join("mruby/bin")
    end

    def run(string, payload: nil, instruction_quota_start: nil)
      sources = [
        %w[preparing prepare],
        ["user", string],
        %w[packing_output pack_output]
      ]

      engine.eval sources,
                  input: {
                    configuration: {
                      time_zone_offset: Time.zone.formatted_offset(false)
                    },
                    payload: payload
                  },
                  instruction_quota_start: instruction_quota_start,
                  environment_variables: {"TZ" => Time.zone.name}
    end

    def run_inline(string, payload: nil, instruction_quota_start: nil)
      run "Output.value = module Main\n#{string}\nend",
          payload: payload,
          instruction_quota_start: instruction_quota_start
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
script_core-0.1.0 spec/dummy/app/lib/script_engine.rb