PluggableLite help you to create pluggable architecture in your ruby application. In only 3 steps, you can make your ruby app pluggable.
- Include PluggableLite::Plugin to your plugin base class
- Include PluggableLite::PluginManager to your class which holds loaded plugins
- Register your plugin base class to your plugin manager
That's it!.
Add this line to your application's Gemfile:
gem 'pluggable_lite'
And then execute:
$ bundle
Or install it yourself as:
$ gem install pluggable_lite
Create your own plugin base class and extend it with PluggableLite::Plugin. In addition, you can define default implementation in your plugin base class(not mandatory).
#feature1_plugin.rb
require './Plugin.rb'
class Feature1Plugin
extend PluggableLite::Plugin
def execute
raise RuntimeError.new('please override [execute] method')
end
end
Create you own plugin manager class and extend it with PluggableLite::PluginManager. You need to use "register" class method to indicate which plugin base class it holds.
#feature1_plugin.rb
class Feature1PluginManager
extend PluggableLite::PluginManager
register Feature1Plugin
end
Create your plugin class and inherit your plugin base class and implement methods.
#feature1_plugins/helloworld
class HelloWorldPlugin < Feature1Plugin
def execute
puts "Hello world!!!"
end
end
Specify directory you want to load plugins by using "load" method. After calling load methods, you can get plugin class objects through plugins method in your plugin manager.
#app.rb
require './feature1_plugin'
#Specify directory where plugins locates
Feature1PluginManager.load("feature1_plugins")
#Now Feature1PluginManager.plugins hold class objects
Feature1PluginManager.plugins.each do |plugin_class|
plugin = plugin_class.new
plugin.execute
end
- Fork it ( https://github.com//pluggable_lite/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
- i18n
Thanks!