Class: GoodGuide::Gibbon::Context

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/goodguide/gibbon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#hash_to_ruby, #obj_to_js, #obj_to_ruby

Constructor Details

#initialize(js = {}) ⇒ Context

Returns a new instance of Context.



382
383
384
385
386
387
388
389
390
# File 'lib/goodguide/gibbon.rb', line 382

def initialize(js={})
  if js.is_a? Hash
    js = JS.new(js)
  end

  @js = js
  @defer = js[:setTimeout]
  @gibbon = js.gibbon
end

Instance Attribute Details

#gibbonObject (readonly)

Returns the value of attribute gibbon.



380
381
382
# File 'lib/goodguide/gibbon.rb', line 380

def gibbon
  @gibbon
end

#jsObject (readonly)

Returns the value of attribute js.



381
382
383
# File 'lib/goodguide/gibbon.rb', line 381

def js
  @js
end

Instance Method Details

#analyze(syntax, global_table, static_client) ⇒ Object



406
407
408
409
410
411
412
# File 'lib/goodguide/gibbon.rb', line 406

def analyze(syntax, global_table, static_client)
  syntax = obj_to_js(syntax)

  capture do |&callback|
    gibbon.analyze(syntax, global_table, static_client, callback)
  end
end

#compile(semantics) ⇒ Object



402
403
404
# File 'lib/goodguide/gibbon.rb', line 402

def compile(semantics)
  gibbon.compile(obj_to_js(semantics))
end

#loggerObject



392
393
394
# File 'lib/goodguide/gibbon.rb', line 392

def logger
  js.logger
end

#parse(str) ⇒ Object



396
397
398
399
400
# File 'lib/goodguide/gibbon.rb', line 396

def parse(str)
  obj_to_ruby self.gibbon.parse(str)
rescue JSError => e
  raise SemanticError.new([{'_tag' => 'parse', 'message' => e.value}], self)
end

#run_compiled(compiled, entity_id, runtime_client) ⇒ Object



414
415
416
417
418
419
420
# File 'lib/goodguide/gibbon.rb', line 414

def run_compiled(compiled, entity_id, runtime_client)
  results, _ = capture do |&callback|
    compiled.run(entity_id, runtime_client, callback)
  end

  obj_to_ruby(results)
end