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.



343
344
345
346
347
348
349
350
# File 'lib/goodguide/gibbon.rb', line 343

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

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

Instance Attribute Details

#gibbonObject (readonly)

Returns the value of attribute gibbon.



342
343
344
# File 'lib/goodguide/gibbon.rb', line 342

def gibbon
  @gibbon
end

Instance Method Details

#analyze(syntax, global_table, static_client) ⇒ Object



362
363
364
365
366
367
368
# File 'lib/goodguide/gibbon.rb', line 362

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



358
359
360
# File 'lib/goodguide/gibbon.rb', line 358

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

#parse(str) ⇒ Object



352
353
354
355
356
# File 'lib/goodguide/gibbon.rb', line 352

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

#run_compiled(compiled, entity_id, runtime_client) ⇒ Object



370
371
372
373
374
375
376
# File 'lib/goodguide/gibbon.rb', line 370

def run_compiled(compiled, entity_id, runtime_client)
  values, error = capture do |&callback|
    compiled.run('/', entity_id, runtime_client, callback)
  end

  [hash_to_ruby(values), obj_to_ruby(error)]
end