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, #to_js

Instance Method Details

#add_dependency!(key, dep) ⇒ Object



488
489
490
# File 'lib/goodguide/gibbon.rb', line 488

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

#local_dependency!(current_key, dependence_key) ⇒ Object



484
485
486
# File 'lib/goodguide/gibbon.rb', line 484

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

#missing_data!Object

Raises:



478
479
480
481
482
# File 'lib/goodguide/gibbon.rb', line 478

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



449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
# File 'lib/goodguide/gibbon.rb', line 449

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

#with_dependencies(&b) ⇒ Object



472
473
474
475
476
# File 'lib/goodguide/gibbon.rb', line 472

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