class ActiveFedora::RDFDatastream

def add_attribute_indexing_config(name, &block)

def add_attribute_indexing_config(name, &block)
  Deprecation.warn(RDFDatastream, "Adding indexing to datastreams is deprecated")
  # TODO the hash can be initalized to return on of these
  index_config[name] ||= ActiveFedora::Indexing::Map::IndexObject.new &block
end

def content

def content
  serialize
end

def content=(new_content)

def content=(new_content)
  resource.clear!
  resource << deserialize(new_content)
  content
end

def content_changed?

def content_changed?
  return false unless instance_variable_defined? :@resource
  return true if empty_or_blank_subject? # can't be serialized because a subject hasn't been assigned yet.
  @content = serialize
  super
end

def deserialize(data=nil)

def deserialize(data=nil)
  return ::RDF::Graph.new if new_record? && data.nil?
  data ||= remote_content
  # Because datastream_content can return nil, we should check that here.
  return ::RDF::Graph.new if data.nil?
  data.force_encoding('utf-8')
  ::RDF::Graph.new << ::RDF::Reader.for(serialization_format).new(data)
end

def empty_or_blank_subject?

def empty_or_blank_subject?
  resource.rdf_subject.node? || resource.rdf_subject.value.blank?
end

def freeze

def freeze
  @resource.freeze
end

def metadata?

def metadata?
  true
end

def parent_uri(ds)

Trim the last segment off the URI to get the parents uri
def parent_uri(ds)
  m = /^(.*)\/[^\/]*$/.match(ds.uri)
  if m
    m[1]
  else
    ::RDF::URI.new(nil)
  end
end

def parent_uri

def parent_uri
  self.class.parent_uri(self)
end

def property(name, *args, &block)

def property(name, *args, &block)
  super
  add_attribute_indexing_config(name, &block) if block_given?
end

def rdf_subject &block

def rdf_subject &block
  if block_given?
    return @subject_block = block
  end
  @subject_block ||= lambda { |ds| parent_uri(ds) }
end

def refresh_attributes

def refresh_attributes
  @resource = nil
end

def resource

set_value, get_value, and property accessors are delegated to this object.

other nodes.
the datastream and is the central point for its relationship to
The resource is the RdfResource object that stores the graph for
#
def resource
  @resource ||= begin
                  klass = self.class.resource_class
                  klass.properties.merge(self.class.properties).each do |prop, config|
                    klass.property(config.term,
                                   predicate: config.predicate,
                                   class_name: config.class_name)
                  end
                  klass.accepts_nested_attributes_for(*nested_attributes_options.keys) unless nested_attributes_options.blank?
                  uri_stub = self.class.rdf_subject.call(self)
                  r = klass.new(uri_stub)
                  r.datastream = self
                  r << deserialize
                  r
                end
end

def resource_class(klass=nil)

Returns:
  • (Class) - the object resource class

Parameters:
  • klass (Class) -- an object to set as the resource class, Must be a descendant of
def resource_class(klass=nil)
  if klass
    raise ArgumentError, "#{self} already has a resource_class #{@resource_class}, cannot redefine it to #{klass}" if @resource_class and klass != @resource_class
    raise ArgumentError, "#{klass} must be a subclass of ActiveTriples::Resource" unless klass < ActiveTriples::Resource
  end
  @resource_class ||= begin
                        klass = Class.new(klass || ActiveTriples::Resource)
                        klass.send(:include, RDF::Persistence)
                        klass
                      end
end

def serialization_format

def serialization_format
  raise "you must override the `serialization_format' method in a subclass"
end

def serialize

def serialize
  resource.set_subject!(parent_uri) if parent_uri and rdf_subject.node?
  resource.dump serialization_format
end

def term_values(*values)

@TODO: We may need to enable deep RDF delegation at one point.
OmDatastream implementation as our "consistency" point.
This patches the fact that there's no consistent API for allowing delegation - we're matching the
This method allows for delegation.
#
def term_values(*values)
  self.send(values.first)
end

def update_indexed_attributes(hash)

def update_indexed_attributes(hash)
  hash.each do |fields, value|
    fields.each do |field|
      self.send("#{field}=", value)
    end
  end
end

def uri=(uri)

def uri=(uri)
  super
  resource.set_subject!(parent_uri) if empty_or_blank_subject?
end