Characterize
Make your models behave in special ways.
Usage
class UsersController < ApplicationController
characterize :user
def show
end
end
# the above sets a helper_method of 'user' and loads UserCharacter
class UsersController < ApplicationController
def show
characterize(user, display_module)
end
def display_module
current_user.can_edit?(user) ? AdministratedUser : StandardUser
end
end
# use a standard interface in your views but change the character of the object
module AdministratedUser
def edit_link
view.link_to('Edit', admin_user_path)
end
end
module StandardUser
def edit_link
""
end
end
Installation
Add this line to your application's Gemfile:
gem 'characterize'
And then execute:
$ bundle
Or install it yourself as:
$ gem install characterize
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