Forum: Ruby on Rails Including common code among multiple web services issue?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Philip H. (Guest)
on 2006-05-09 00:02
(Received via mailing list)
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 topic is locked and can not be replied to.