Created
April 10, 2009 20:20
-
-
Save zhhz/93272 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| def self.available_controllers(name) | |
| roles = Role.all(:name => name, :authorizable_type.not => nil) | |
| exists_controllers = roles.collect{|r| r.authorizable_type} | |
| controllers = Application.subclasses_list.to_a.sort | |
| controllers - exists_controllers | |
| end | |
| def authorizable_class | |
| return nil if authorizable_type.nil? | |
| klass = begin | |
| authorizable_type.split("::").inject(Object){|x, y| x.const_get(y)} | |
| rescue NameError => e | |
| msg = "Class not found: `#{authorizable_type}'" | |
| Merb.logger.warn!(msg) | |
| nil | |
| end | |
| end | |
| ... | |
| def callable_actions | |
| klass = authorizable_class | |
| # make sure is a controller | |
| return [] if klass.nil? || !klass.respond_to?(:callable_actions) | |
| # get the supper class's actions out your way | |
| actions = klass.callable_actions.keys - klass.superclass.callable_actions.keys | |
| actions.sort | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment