Class: ModelLanguage::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/model_language.rb

Instance Method Summary collapse

Constructor Details

#initialize(wasm_path = nil) ⇒ Engine

Returns a new instance of Engine.



13
14
15
16
17
18
19
20
# File 'lib/model_language.rb', line 13

def initialize(wasm_path = nil)
  wasm_path ||= ENV["MODEL_LANGUAGE_WASM"] || bundled_wasm ||
                File.expand_path("../../../wasm/dist/model_language.wasm", __dir__)
  @engine = Wasmtime::Engine.new
  @module = Wasmtime::Module.from_file(@engine, wasm_path)
  @linker = Wasmtime::Linker.new(@engine)
  Wasmtime::WASI::P1.add_to_linker_sync(@linker)
end

Instance Method Details

#parse(template) ⇒ Object



31
32
33
# File 'lib/model_language.rb', line 31

def parse(template)
  invoke("op" => "parse", "template" => template)
end

#render(template, data: {}, schema: [], options: {}) ⇒ Object



22
23
24
25
# File 'lib/model_language.rb', line 22

def render(template, data: {}, schema: [], options: {})
  invoke("op" => "render", "template" => template, "data" => data,
         "schema" => schema, "options" => options)
end

#validate(template, schema: [], options: {}) ⇒ Object



27
28
29
# File 'lib/model_language.rb', line 27

def validate(template, schema: [], options: {})
  invoke("op" => "validate", "template" => template, "schema" => schema, "options" => options)
end