Zobi helps you to orchestrate your controller behaviors using the following gems :
How to use it?
Add it in your
Gemfile and run
gem 'zobi', '~> 4.0.1'
Next, include Zobi module in your controller and set modules you want to include :
extend Zobi behaviors :inherited, :scoped, :included, :paginated, :controlled_access, :decorated
This module uses inherited_resources gem (for version >= 1.4.0).
This module deals with String Parameters using Parameters classes.
A Parameters inherits from Zobi::ParametersSanitizer, and should define the list of parameters and nested parameters to accept.
If your controller is namespaced, you should define the
resource_type method to
override its generic behavior.
If your model is namespaced, you should define the defaults resource_class for
Inherited Resource, ie :
defaults resource_class: ::User::Address
Here is an example :
module User class AddressParameters < Zobi::ParametersSanitizer # Optional, usefull for a namespaced controller, User::AddressesController # here. def resource_type :user_address end protected def fields [ :id, :street, :zip_code, nested_attributes: [:id, :foo, :bar] ] end end end
By default, Parameters class are discovered using the controller namespace.
User::AddressesController, Zobi will search for
If you don't want to use Parameters class, you can define the
in your controller and perform custom filtering.
This module uses has_scope gem.
This module only works with ActiveRecord because it uses the Eager Loading Associations of Active Record.
You just need to define a method named includes and add the associations to load.
def includes [:association] end
This module uses kaminari gem.
This module uses draper gem and has a dependency on Inherited modules for now.
By default, Zobi will try to discover the decorator class to use using the current namespece.
For example, given a controller named Admin::User::AddressesController, Zobi will try to find the appropriate decorator class in this order :
Admin::User::AddressesDecorator Admin::AddressesDecorator AdressesDecorator Admin::User::CollectionDecorator Admin::CollectionDecorator CollectionDecorator
Admin::User::AddressDecorator Admin::AddressDecorator AdressDecorator Admin::User::ResourceDecorator Admin::ResourceDecorator ResourceDecorator
If this is not the way you organize your decorators, you can override this
behavior by defining a method called
decorator_class which returns the decorator class to use.
Launch test suite :
cd spec/dummy bundle exec rake db:test:prepare cd ../.. bundle exec rspec
Launch the dummy app :
cd spec/dummy bundle exec rake db:migrate bundle exec rails s
We decided to follow rails versions to simplify update of Zobi when you want to upgrade rails.
Copyright (c) 2013 af83
Released under the MIT license