Zertico
Easy Rails development using the Zertico Way. Rails is a great framework, but is not a great idea to let your tests depend on any part of it. Zertico let you develop what most important: your business logic. Also, your tests will not depend of rails at all.
Installation
Add this line to your application's Gemfile:
gem 'zertico'
And then execute:
$ bundle
Or install it yourself as:
$ gem install zertico
Basic Usage
First, alter your ApplicationController and extend Zertico::Controller
class ApplicationController < Zertico::Controller
end
Now, define the routes you need as follow:
resources :entries
And thats all. All the logic is already defined on the controller. Happy coding. =D
Advanced Usage
The Zertico::Controller doesn't cover all cases. For those that are not covered you will have to create a service with the same name of the controller, as follows:
class UsersController < ApplicationController
module UsersService
include Zertico::Service
end
Your service must be a module and include Zertico::Service to grant access to all the methods already defined. Then you will have to redefine all the methods you need. Each action of the controller is mapped to a method. The method has to return a hash. The key must be the name of the global variable you want to use on the views.
Sometimes, the ActiveRecord models grow to much. It start to handle all kinds of logic. To make things simple, it should only concern about database access. To clean it, use the Zertico::Accessor. It is a wrapper that will pass all methods to the object unless the ones you overwrite. This way, is easy to start develop better models.
By using Zertico::Controller and Zertico::Accessor, a great part of you project will be simple ruby classes. It means, better and simple tests, without depend on rails and any other external logic. =D
Conventions
To work with the gem, you will need to follow some conventions. Your model ( called interface here ) need to have the same name of your controller, without the 'Controller' substring. The Service need to replace the 'Controller' substring with 'Service' like:
class UsersController < Zertico::Controller
end
module UsersService
include Zertico::Service
end
class UserAccessor < Zertico::Accessor
end
class User < ActiveRecord::Base
end
It is good to put the services on a separate folder called services.
Mantainers
Contributing
- Fork it
- 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