Giter Site home page Giter Site logo

pluggablelite's Introduction

PluggableLite

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!.

Installation

Add this line to your application's Gemfile:

gem 'pluggable_lite'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pluggable_lite

Usage

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

Contributing

  1. Fork it ( http://github.com//pluggable_lite/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Contributors

  • i18n

Thanks!

pluggablelite's People

Stargazers

Kohei Yamada avatar

Watchers

 avatar Eizen Kimura avatar

Forkers

yantene

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.