From: Patrick Hurley Date: 2005-03-26T03:46:01+09:00 Subject: Re: loading "plugins" On Sat, 26 Mar 2005 03:29:50 +0900, Hans Fugal wrote: > I am writing a log analyzer (hans.fugal.net/src/clog) that uses a sort > of plugin (I call them agents) which is basically a class that gets > instantiated and then called to do work. I want to include various > agents with the distribution. > > Where should the files end up? How should I discover the agents? > > The sysadmin will be able to specify a directory (or directories) that > contain his own agents, in addition to the included agents. I can scan > that directory for .rb files and load them. That part works. But I don't > want to make the sysadmin specify where the standard agents are in the > config file - that should be implied. "require 'clog/agents/*'" would > express what I want to do, although that isn't valid. I don't want to > hardcode a path to /usr/local/lib/site_ruby/whatever, either. > > Ultimately, the sysadmin should refer to the agents with a simple > one-word name, e.g. Postfix or Bogofilter. > > I don't know if my question makes sense, but I'm wondering what you all > would do because there is no obvious best way to do this to me at the > moment. > > (and yes, I know IoC or DI would fit here but I don't want to put the > burden of figuring out what the heck those are on the poor sysadmin who > just needs to specify what agent to use) > > What is wrong with something like: base = "." Dir.glob("#{base}/*.rb").each { |plugin| require plugin } where you can obviously set base to anything you want. Patrick