Created
February 17, 2012 16:38
-
-
Save barmintor/1854278 to your computer and use it in GitHub Desktop.
Checking for AF::Base subclasses without calling .ancestors or creating an enumerator
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
module ActiveFedora | |
class ContentModel | |
# Returns an ActiveFedora Model class corresponding to the given uri if one can be found. | |
# Returns false if no corresponding model can be found. | |
def self.uri_to_model_class( uri ) | |
verify_base(rc = Model.from_class_uri(uri)) and rc | |
end | |
def self.verify_base klass | |
return false unless klass.is_a? Class | |
while (klass = klass.superclass) and klass != ActiveFedora::Base; end | |
klass == ActiveFedora::Base | |
end | |
private_class_method :verify_base | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment