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



241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/goodguide/gibbon.rb', line 241

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



255
256
257
258
259
260
# File 'lib/goodguide/gibbon.rb', line 255

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:



237
238
239
# File 'lib/goodguide/gibbon.rb', line 237

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

#to_jsObject



262
263
264
# File 'lib/goodguide/gibbon.rb', line 262

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