Including common code among multiple web services issue?

Hi all -

I’m implementing some web services and every one has at the very least a
“find_newer_than” method.

In my models, I’ve split things up like this and it works great.

class XyzService < WebService
web_service_api XyzApi
… service specific methods go here…

class WebService < ActionWebService::Base
def find_newer_than(created_at)
:conditions => [‘created_at >= ?’,

def real_class
Class.const_get(self.class.to_s.gsub(/Service$/, ‘’))


I’d like to do the same for the API’s, but can’t quite get there. If I
try the same logic as above then when I go to /api/invoke all the
methods show up as being of the “WebService” class.

Right now I’ve got this and it works. I’d like to move that api_method
line into a common file though. Since subclassing the Api’s another
level didn’t work I’ve tried both require and load, but require doesn’t
work at all, and load gives me an unknown method error for

class XyzApi < ActionWebService::API::Base

api_method :find_newer_than,
:expects => [{:created_at => :datetime}],
:returns => [[Class.const_get($/, ‘’))]]


So, what I really want is to move that code into it’s own file and get
ruby to simply insert it as is into each of my files and then parse

Similar to PHP’s include() function.




This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs