Plugins - appable_plugins
Add to favoritesappable_plugins
appable_plugins adds the ability for plugins to share models, controllers, helpers, and other application classes with your Rails application.
Resources
Announcement
Wiki
API
Development
Source
Description
The goal of this plugin is to make it really easy for plugin developers to add models/controllers/helpers/etc. that are automatically mixed in with your existing classes.
appable_plugins expects developers to store each model/controller/helper in a similar directory as that of your application. For example,
plugin_xyz/ plugin_xyz/app/ plugin_xyz/app/controllers/ plugin_xyz/app/helpers plugin_xyz/app/models/
appable_plugins is able to automatically load both plugin files and app files by simply wrapping require and load calls. It will then look in plugin folders first before allowing the original require/load to get called.
Usage
Example
Let’s assume you want to write a plugin called acts_as_commentable. You would setup a directory structure like the following:
acts_as_commentable/ acts_as_commentable/app/ acts_as_commentable/app/models/ acts_as_commentable/app/models/comment.rb acts_as_commentable/lib/ acts_as_commentable/lib/acts_as_commentable.rb acts_as_commentable/init.rb
acts_as_commentable/init.rb:
require 'acts_as_commentable'
acts_as_commentable/lib/acts_as_commentable.rb
...add your macro stuff here...
acts_as_commentable/app/models/comment.rb
class Comment < ActiveRecord::Base
...
end
Let’s then assume that our main Rails app has a Comment model as well like so:
Application structure:
app/ app/models/ app/models/comment.rb
app/models/comment.rb
class Comment < ActiveRecord::Base
...add some additional things...
end
When you first try to access the Comment model, appable_plugins knows it first needs to load comment.rb from your acts_as_commentable plugin. Once this finished, it will then load the comment.rb stored in your application’s app/models/ folder. As a result, the code from both Comment models are now mixed in and shared automatically.
Adding additional types to automatically mix
If you want to add additional class types to have automatically mixed in, you can do so by adding the following to an initializer or within config.after_initialize:
config/environment.rb:
Rails::Initializer.run do |config|
...
config.after_initialize do
Plugin.mix_code_from(:activities => /.+_activity/)
end
...
end
This tells appable_plugins that you have an app/activities folder whose file names are matched by the given regular expression. By default, appable_plugins supports the following app types:
:controllers => /.+_controller|application/ :helpers => /.+_helper/ :apis => /.+_api/ :services => /.+_service/ :models => /.+/
Dependencies
This plugin depends on the presence of the following plugins:
- loaded_plugins[http://wiki.pluginaweek.org/Loaded_plugins]
- plugin_dependencies[http://wiki.pluginaweek.org/Plugin_dependencies]
References
- James Adam - Engines[http://www.rails-engines.org]
http://wiki.pluginaweek.org/Appable_plugins
http://svn.pluginaweek.org/trunk/plugins/rails/appable_plugins
Rails' (MIT)
Misc. Enhancements
