Skip to content

Instantly share code, notes, and snippets.

@stalcottsmith
Created March 3, 2011 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stalcottsmith/852562 to your computer and use it in GitHub Desktop.
Save stalcottsmith/852562 to your computer and use it in GitHub Desktop.
Declarative Auth Role Ancestor hierarchy
class Role < ActiveRecord::Base
require 'declarative_authorization/development_support/analyzer'
has_many :assignments
has_many :users, :through => :assignments
validates :name, :presence => true
validates :name, :uniqueness => true
def ancestors
Authorization::DevelopmentSupport::AnalyzerEngine::Role.for_sym(self.name.to_sym,
Authorization::Engine.instance).ancestors.map { |r| r.instance_variable_get("@role") }
end
def self_and_ancestors
ancestors << self.name.to_sym
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment