Skip to content

Instantly share code, notes, and snippets.

@barmintor
Created February 17, 2012 16:38
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 barmintor/1854278 to your computer and use it in GitHub Desktop.
Save barmintor/1854278 to your computer and use it in GitHub Desktop.
Checking for AF::Base subclasses without calling .ancestors or creating an enumerator
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