0

I have to develop a plugin based software in ruby. What's the best architeture tu use?

I am thinking about plugin like this, each in a separate .rb file:

class MyPlugin < Plugin

def info
 infos
end

def run
 # run
end
end

How i can write a plugin manager to call these plugins?

tapioco123
  • 3,235
  • 10
  • 36
  • 42
  • You might also consider using `Module` s with `include` or `extend`. – jtbandes Jul 25 '10 at 21:03
  • most ruby plugins come in the form of gems, check this tutorial out as a resource http://guides.rubygems.org/make-your-own-gem/, which also covers a conventional architecture. – random-forest-cat Aug 20 '15 at 18:18

1 Answers1

2

You'd have to clearly define what "calling the plugins" exactly mean.

For start, you can check out here how to require all the files from a directory, put your plugins into a single directory and require them all.

Then you need to somehow pick which one to use, whether it be:

  • passing its classname as a string through a command line argument or a config file parameter, and looking for a class by that name using const_get, or
  • presenting a user a list of all plugins (all descendants of your Plugin class) - check out here how to do it

Finally, you instantiate your plugin and do whatever you need to do with it.

Community
  • 1
  • 1
Mladen Jablanović
  • 43,461
  • 10
  • 90
  • 113