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



288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/goodguide/gibbon.rb', line 288

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



302
303
304
305
306
307
# File 'lib/goodguide/gibbon.rb', line 302

def analyze_query(input_id, query, t)
  query_impl = get_query(query.type)
  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:



284
285
286
# File 'lib/goodguide/gibbon.rb', line 284

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

#to_jsObject



309
310
311
# File 'lib/goodguide/gibbon.rb', line 309

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