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_js, #hash_to_ruby, #obj_to_ruby

Methods inherited from AbstractClient

queries

Class Method Details

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



216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/goodguide/gibbon.rb', line 216

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



230
231
232
233
234
235
# File 'lib/goodguide/gibbon.rb', line 230

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:



212
213
214
# File 'lib/goodguide/gibbon.rb', line 212

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

#to_jsObject



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

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