Class: GoodGuide::Gibbon::StaticClient

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#hash_to_ruby, #obj_to_js, #obj_to_ruby

Methods inherited from AbstractClient

queries

Class Method Details

.query(type, opts = {}, &impl) ⇒ Object



327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/goodguide/gibbon.rb', line 327

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



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

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

Raises:



323
324
325
# File 'lib/goodguide/gibbon.rb', line 323

def query_error!(*a)
  raise StaticError.new(*a)
end

#to_js(gibbon) ⇒ Object



348
349
350
# File 'lib/goodguide/gibbon.rb', line 348

def to_js(gibbon)
  { :analyzeQuery => proc_for(gibbon, :analyze_query) }
end