Class: GoodGuide::Gibbon::RuntimeClient

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

Instance Method Summary collapse

Methods included from Util

#hash_to_ruby, #obj_to_js, #obj_to_ruby

Methods inherited from AbstractClient

queries, query

Instance Method Details

#add_dependency!(key, dep) ⇒ Object



450
451
452
# File 'lib/goodguide/gibbon.rb', line 450

def add_dependency!(key, dep)
  (@dependencies[key] ||= []) << dep
end

#local_dependency!(current_key, dependence_key) ⇒ Object



446
447
448
# File 'lib/goodguide/gibbon.rb', line 446

def local_dependency!(current_key, dependence_key)
  add_dependency! current_key, Dependency::Local.new(dependence_key)
end

#missing_data!Object

Raises:



440
441
442
443
444
# File 'lib/goodguide/gibbon.rb', line 440

def missing_data!
  add_dependency! @last_key, Dependency::Missing.new(@last_query_type, @last_id, @last_annotations)

  raise RuntimeError
end

#query!(current_key, annotations, type, id) ⇒ Object



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/goodguide/gibbon.rb', line 411

def query!(current_key, annotations, type, id)
  query_type = annotations.delete('_query_type')

  # stash this data in case missing_data! is called
  @last_key = current_key
  @last_query_type = query_type
  @last_annotations = annotations
  @last_id = id

  query = get_query(query_type) or raise "invalid query type in compiled code: #{query_type.inspect} with annotations #{annotations.inspect}"
  value = instance_exec(id, annotations, &query)

  add_dependency! current_key, Dependency::Query.new(
    query_type: query_type,
    annotations: annotations,
    type: type,
    id: id,
    value: value
  )

  value
end

#to_js(gibbon) ⇒ Object



454
455
456
# File 'lib/goodguide/gibbon.rb', line 454

def to_js(gibbon)
  { :performQuery => proc_for(gibbon, :perform_query) }
end

#with_dependencies(&b) ⇒ Object



434
435
436
437
438
# File 'lib/goodguide/gibbon.rb', line 434

def with_dependencies(&b)
  @dependencies = {}
  value = yield
  [@dependencies, value]
end