This is a very simple plugin that adds support for decorators to your Rails application. Effectively all that this does is allow you to register paths in which to search for decorators which are then loaded at the appropriate point in your application's initialisation process.
Decorators must follow this naming convention:
app/decorators/<at least one subdirectory>/something_decorator.rb
This is an example of a decorator that will be loaded:
app/decorators/controllers/pages_controller_decorator.rb
These are examples of decorators that won't be loaded:
app/decorators/pages_controller_decorator.rb
app/decorators/controllers/pages_controller.rb
The important parts are being inside a sub directory of app/decorators
and having
_decorator.rb
at the end of the file's name.
In your Gemfile, add the gem:
gem 'decorators', '~> 1.0.0'
Now, run bundle install
and the gem should install.
There really is just one method to call; Decorators#register!
.
Simply pass one path or many paths to the method to register paths to search
inside for decorators to be loaded from.
require 'decorators'
Decorators.register! Rails.root
Or for many paths:
require 'decorators'
Decorators.register! Rails.root, Rails.root.join('vendor', 'extensions', 'extension_with_decorators')
Decorators is released under the MIT license and is copyright (c) 2013 Philip Arndt