lib/challah/rolls/permission.rb
def challah_permission
      unless included_modules.include?(InstanceMethods)
        include InstanceMethods
        extend ClassMethods
      end

      class_eval do
        validates_presence_of :name, :key
        validates_uniqueness_of :name, :key
        validates_format_of :key, :with => /^([a-z0-9_])*$/, :message => :invalid_key

        has_many :permission_roles, :dependent => :destroy
        has_many :roles, :through => :permission_roles, :order => 'roles.name'
        has_many :permission_users, :dependent => :destroy
        has_many :users, :through => :permission_users, :order => 'users.last_name, users.first_name'

        default_scope order('permissions.name')

        attr_accessible :name, :description, :key, :locked

        after_create :add_to_admin_role
      end
    end
def challah_permission
      unless included_modules.include?(InstanceMethods)
        include InstanceMethods
        extend ClassMethods
      end

      class_eval do
        validates_presence_of :name, :key
        validates_uniqueness_of :name, :key
        validates_format_of :key, :with => /^([a-z0-9_])*$/, :message => :invalid_key

        has_many :permission_roles, :dependent => :destroy
        has_many :roles, :through => :permission_roles, :order => 'roles.name'
        has_many :permission_users, :dependent => :destroy
        has_many :users, :through => :permission_users, :order => 'users.last_name, users.first_name'

        default_scope order('permissions.name')

        attr_accessible :name, :description, :key, :locked

        after_create :add_to_admin_role
      end
    end
This method sets up the +Permission+ class with all baked in methods.

 A permission requires the presence of the +name+, +key+ and +description+

 Once this method has been called, the {InstanceMethods} module
 will be accessibile within the Permission model.