Created
March 5, 2012 18:16
-
-
Save jamesgecko/1980103 to your computer and use it in GitHub Desktop.
Attribute visibility task
This file contains 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
# TODO: this will fail when run on a project that uses namespaced models | |
desc "Show visibility of attributes" | |
task :attr => :environment do | |
require 'set' | |
models = Dir['**/models/**/*.rb'].map {|f| File.basename(f, '.*').camelize.constantize } | |
models.each do |m| | |
all = Set.new m.attribute_names | |
accessible = Set.new m.accessible_attributes.to_a | |
protected_ = Set.new m.protected_attributes.to_a | |
if accessible.empty? | |
is_accessible = (all - protected_).to_a | |
else | |
is_accessible = (accessible - protected_).to_a | |
end | |
non_accessible = ((all - is_accessible) + protected_).to_a | |
is_accessible = "None" if is_accessible.empty? | |
print m.name, "\n" | |
print " Accessible: ", is_accessible, "\n" | |
print " Nonaccessible: " , non_accessible , "\n\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment