Class: GoodGuide::Gibbon::StaticClient
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Util
#hash_to_ruby, #obj_to_js, #obj_to_ruby
queries
Class Method Details
.query(type, opts = {}, &impl) ⇒ Object
332
333
334
335
336
337
338
339
340
341
342
343
344
|
# File 'lib/goodguide/gibbon.rb', line 332
def self.query(type, opts={}, &impl)
arity = opts.fetch(:arity, 1)
super type, opts do |input, args, builder|
if args.size != arity
query_error!(
"wrong number of arguments: " +
"#{args.size} for #{arity} (in .#{type} #{args.join(' ')})"
)
end
self.instance_exec(input, *args, builder, &impl)
end
end
|
Instance Method Details
#analyze_query(input_id, query, t) ⇒ Object
346
347
348
349
350
351
|
# File 'lib/goodguide/gibbon.rb', line 346
def analyze_query(input_id, query, t)
query_impl = get_query(query.type) or query_error! "no such query #{query.type.inspect}"
analysis = instance_exec(input_id, obj_to_ruby(query.args), t, &query_impl)
analysis[:annotations]['_query_type'] = query.type
analysis
end
|
#query_error!(*a) ⇒ Object
328
329
330
|
# File 'lib/goodguide/gibbon.rb', line 328
def query_error!(*a)
raise StaticError.new(*a)
end
|
#to_js(gibbon) ⇒ Object
353
354
355
|
# File 'lib/goodguide/gibbon.rb', line 353
def to_js(gibbon)
{ :analyzeQuery => proc_for(gibbon, :analyze_query) }
end
|