projecthydra/active_fedora — pull request #198 by scande3 (2013-09-16 13:13:05+00:00)
Title: New inherited cmodel pull request (read-only portion). Write portion coming soon.

In Active Fedora, it assumes quite often that a given object will have
only a single valid content model. With models in the community
starting to extend from other models (ie. Sufia or internal models at
BPL), this update makes such cases more sane. Note that this functionality is only for reading of objects.

For the below bulleted examples, I will assume the following two
models:

class GenericFile << ActiveFedora::Base

class ExtendedGenericFile << GenericFile

* belongs_to and has_many should automatically cast objects based on
the base class_name. For example, if one has:

has_many files, class_name: "GenericFile"

In this case, "GenericFile" objects will still be returned as such.
But "ExtendedGenericFile" objects will be instantiated as that
class. Note that only the first cmodel order on the
"ExtendedGenericFile" object is not important as it will attempt
to use the most specific class available.

* A ":cast" argument was added to relationships to allow for preventing
automatic casting. For example, using the previous example,

has_many files, class_name: "GenericFile", :cast=>false

In this case, "GenericFile" objects will still be returned as such.
But "ExtendedGenericFile" objects will be instantiated as that
class. Note that only the first cmodel order on the
"ExtendedGenericFile" object is not important as it will attempt
to use the most specific class available.

* adapt_to_cmodel no longer blindly uses the first cmodel. If an object
of a class other than ActiveFedora::Base is called with it, it will
attempt to find a more specific model based on that base model.
Otherwise, it will use the first model, and cast as that unless it
finds a more specific model registered in the system (based on that
first model).

This is easily reverted to using the first cmodel blindly. But
seems like that is more unpredictable behavior.