Simple roles for your classes. Heavily based on Pat Nakajima's Roleful (github.com/nakajima/roleful), but with less features and less metaprogramming.
Basically just what I needed for a personal project, plus some additions I need (TODO).
class User include SimpleRoles def role :basic end role :basic do can :do_this can :do_that do |that| self == that end end role :advanced do can :do_advanced_stuff end end user = User.new user.can?(:do_this) # => true user.can?(:do_advanced_suff) # => false user.can?(:do_that, 'I am not a user') # => false user.can?(:do_that, user) # => true
Copyright © 2009 Ismael Celis. See LICENSE for details.