Created
August 7, 2016 16:03
-
-
Save grosscol/120604073bb39051405fad77d500cf83 to your computer and use it in GitHub Desktop.
Print properties and predicates of an ActiveFedora::Base subclass
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
# Use given single class name arg or default to GenericWork | |
desc "Print properties of a sub-class of ActiveFedora::Base" | |
task :properties_to_csv, [:class_name] => :environment do |t, args| | |
Rails.application.eager_load! | |
class_name = args.one? ? args[:class_name] : "GenericWork" | |
print_properties_of class_name.constantize | |
end | |
# Given a class, print some properties information as csv | |
def print_properties_of(klass) | |
#Check if klass is subclass of ActiveFedora::Base | |
if klass <= ActiveFedora::Base | |
klass.properties.each do |key, prop| | |
puts [key, prop.term, prop.type, prop.predicate].join(',') | |
end | |
else | |
puts "#{klass} is not ActiveFedora::Base nor a subclass thereof." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment