I am using dynamic dispatch to define several class methods in a class that inherits from ActiveResource.
class Invoice < ActiveResource::Base
self.site = 'http://localhost:8080/'
def self.define(method)
define_singleton_method(method) do |params = {}|
site = self.site
self.site = "#{self.site}/Invoice/#{method.to_s.camelize(:lower)}"
puts "self.site -> #{self.site}"
results = Invoice.all(params: params)
self.site = site
puts "changing self.site back to #{site}"
return results
end
end
define :get_details
define :put_approval
define :get_attachment
define :get_pending_notifications
end
This works great for the first call, whatever it is (Invoice.get_details, Invoice.get_pending_notifications...), but always fails on the second call.
I would like to understand why this is happening and what I can do to get it fixed.