[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Plugin-API

Christian Kruse

11/20/2003 1:48:00 PM

Hi there,

I'm writing an application in Ruby which should be easy to extend. One
should be able to write a plugin for this application and should be able
to load it with an entry in the config file, e.g.

Load ContentFilter

Perl I would use eval statements like

eval "use $modname";
die $@ if $@;

to load the plugin. In Perl the plugin would look like the following:

push @{$main::Plugins->{state}},new Module;

package Module;

sub new() {
}
....

1;

What's the "ruby way" to do this?

Greetings,
CK

3 Answers

Robert Klemme

11/20/2003 2:35:00 PM

0


"Christian Kruse" <ckruse@defunced.de> schrieb im Newsbeitrag
news:8mgipb.a13.ln@news.defunced.de...
> Hi there,
>
> I'm writing an application in Ruby which should be easy to extend. One
> should be able to write a plugin for this application and should be able
> to load it with an entry in the config file, e.g.
>
> Load ContentFilter
>
> Perl I would use eval statements like
>
> eval "use $modname";
> die $@ if $@;
>
> to load the plugin. In Perl the plugin would look like the following:
>
> push @{$main::Plugins->{state}},new Module;
>
> package Module;
>
> sub new() {
> }
> ....
>
> 1;
>
> What's the "ruby way" to do this?

Assuming the config file is evaluated as ruby code you can do:

15:33:28 [temp]: for file in PluginBase.rb SomePlugin.rb config.rb
application.rb ; do echo "---- $file ----" ; cat "$file" ; done
---- PluginBase.rb ----
class PluginBase
end

---- SomePlugin.rb ----
require 'PluginBase'

class PluginClass < PluginBase
# functionality
end

$plugin_registry << PluginClass
---- config.rb ----
require 'SomePlugin'

---- application.rb ----
# other classes

$plugin_registry = []

eval File.readlines("config.rb").join

p $plugin_registry

15:33:36 [temp]:


As easy as that...

robert

gabriele renzi

11/20/2003 2:38:00 PM

0

il Thu, 20 Nov 2003 14:47:52 +0100, Christian Kruse
<ckruse@defunced.de> ha scritto::


you may find this thread useful:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-...

Christian Kruse

11/23/2003 5:04:00 PM

0

Hoi,

> [...]

Thank you very much for your help.

Greetings,
CK