Skip to content

Instantly share code, notes, and snippets.

@grosscol
Created August 7, 2016 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grosscol/120604073bb39051405fad77d500cf83 to your computer and use it in GitHub Desktop.
Save grosscol/120604073bb39051405fad77d500cf83 to your computer and use it in GitHub Desktop.
Print properties and predicates of an ActiveFedora::Base subclass
# 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