Skip to content

Instantly share code, notes, and snippets.

@zhhz
Created March 29, 2009 00:28
Show Gist options
  • Save zhhz/87244 to your computer and use it in GitHub Desktop.
Save zhhz/87244 to your computer and use it in GitHub Desktop.
#Role.rb
...
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
return [] if klass.nil? || !klass.respond_to?(:callable_actions)# make sure is a controller
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