module Yelp::Fusion::Singleton

Load each endpoint object once for acces by the Yelp::Fusion::Client object

Constants

REQUEST_CLASSES

Private Instance Methods

add_method(instance, method_name) click to toggle source

Define the method on the client and send it to the endpoint instance with the args passed in

# File lib/yelp/fusion/singleton.rb, line 57
def add_method(instance, method_name)
  define_singleton_method(method_name) do |*args|
    instance.public_send(method_name, *args)
  end
end
create_methods_from_instance(instance) click to toggle source

Loop through all of the endpoint instances' public singleton methods to add the method to client

# File lib/yelp/fusion/singleton.rb, line 49
def create_methods_from_instance(instance)
  instance.public_methods(false).each do |method_name|
    add_method(instance, method_name)
  end
end
define_request_methods() click to toggle source

This goes through each endpoint class and creates singleton methods on the client that query those classes. We do this to avoid possible namespace collisions in the future when adding new classes

# File lib/yelp/fusion/singleton.rb, line 40
def define_request_methods
  REQUEST_CLASSES.each do |request_class|
    endpoint_instance = request_class.new(self)
    create_methods_from_instance(endpoint_instance)
  end
end