projecthydra/active_fedora — pull request #377 by no-reply (2014-03-13 17:49:56+00:00)
Title: Overhauling implementatation of ActiveFedora::Rdf

** THIS BREAKS BACKWARD COMPATIBILITY **

This is a major rewrite of RDF Datastreams and the underlying node
support, tightly coupling the ActiveFedora::Rdf to rdf.rb. It replaces
the old RdfNode and related modules with a Resource class that
subclasses RDF::Graph.

The commit adds support for RDF Resources (nodes) persisted to an
RDF::Repository, which allows many ActiveFedora::Base objects to share
data without duplicating statements in each of their datastreams. It
will handle deep nodes in graphs gracefully, even if they are not
expected in the model. The other key features are some powerful
convenience methods for handling Linked Data; namely, #fetch (which
pulls data from an upstream URI) and #rdf_label (which is a way of
getting a human-readable label from common fields).

It also improves handling of typed data. Primarily by virtue of using
df.rb. Saving a Date object (for example) will serialize correctly
typed data and return a Date object when parsed.

A demo of the features included in the commit is here:
https://gist.github.com/no-reply/9519740

The commit breaks backwards compatability in several ways. Full
documentation of compatibility breakage and deprecation is here:
https://gist.github.com/terrellt/75a2fc84fd3d274a1bbd

- New object types now subclass ActiveFedora::Rdf::Resource:

class Component < ActiveFedora::Rdf::Resource
end
# instead of:
class Component
include ActiveFedora::RdfObject
end

- Parameters for new Resources are changed.

- A resource is *always* returned for URI subjects, even when no
class can be identified. This allows better handling of nested data
from sources whose structure is unknown; properties won't be
registered, but other Resource methods will be available. You can get
the string version by calling #rdf_subject.

- Typed literals are supported. *This includes changes to
serialization of RDF!* Passing (e.g.) a Ruby Date object as the value
of a property/triple will yield a typed literal in RDF serializations
and a Ruby Date object will be returned when fetching that data.

It also deprecates a few things for future removal.

- `rdf_type` is deprecated in favor of a general configuration syntax
for Resources.

- `map_predicates` is superceded by `property`, which registers
properties in a simpler way (without need for a block) using a pattern
borrowed from some non-core ruby-rdf libraries.

This work depends on the linkeddata gem for support loading arbitrary
RDF serialations (see: ActiveFedora::Rdf::Resource#fetch).