Mr eel
Introspection in Rails
OK, I’m working on security for a web-app using ACLs. What I want to do is populate a database table with references to the controllers and methods in the app. I can then use these as permissions.
I can get the controllers into a hash like this:
controllers = {}
ObjectSpace.each_object(ActionController::Base) do |controller|
controllers["#{controller.class}"] = controller
end
This works very well, but it only has access to the classes currently loaded. To make sure all of the controllers are loaded so we can access them using ObjectSpace, I look at each controller in the controllers folder, and require each in turn.
Like so:
require 'find'
Find.find(File.join(RAILS_ROOT, 'app/controllers')) { |name|
require_dependency(name) if /_controller\.rb$/ =~ name
}
It finds the files, but the method call require_dependency() doesn’t seem to work. The controllers just aren’t being loaded. Anyone know why?
Comments