class KOSapiClient::RequestBuilderDelegator

Public Class Methods

new(request_builder) click to toggle source
# File lib/kosapi_client/request_builder_delegator.rb, line 4
def initialize(request_builder)
  @request_builder = request_builder
  @response = nil
end

Public Instance Methods

method_missing(method, *args, &block) click to toggle source
# File lib/kosapi_client/request_builder_delegator.rb, line 11
def method_missing(method, *args, &block)
  if @response
    delegate_to_response(method, *args, &block)
  else
    delegate_to_builder(method, *args, &block)
  end
end
Also aliased as: super_method_missing
respond_to_missing?(method, include_all) click to toggle source
# File lib/kosapi_client/request_builder_delegator.rb, line 19
def respond_to_missing?(method, include_all)
  if @response
    @response.respond_to?(method, include_all)
  else
    @request_builder.respond_to?(method, include_all)
  end
end
super_method_missing(method, *args, &block)
Alias for: method_missing

Private Instance Methods

delegate_to_builder(method, *args, &block) click to toggle source
# File lib/kosapi_client/request_builder_delegator.rb, line 36
def delegate_to_builder(method, *args, &block)
  if @request_builder.respond_to?(method)
    res = @request_builder.send(method, *args, &block)
    if res.equal?(@request_builder)
      self
    else
      res
    end
  else
    @request_builder.finalize
    @response = @request_builder.response
    delegate_to_response(method, *args, &block)
  end
end
delegate_to_response(method, *args, &block) click to toggle source
# File lib/kosapi_client/request_builder_delegator.rb, line 28
def delegate_to_response(method, *args, &block)
  if @response.respond_to?(method)
    @response.send(method, *args, &block)
  else
    super_method_missing(method, *args)
  end
end