Module: ActiveFedora::Rdf::Identifiable::ClassMethods

Defined in:
lib/active_fedora/rdf/identifiable.rb

Instance Method Summary collapse

Instance Method Details

#from_uri(uri, _) ⇒ Object

Finds the appropriate ActiveFedora::Base object given a URI from a graph. Expected by the API in ActiveFedora::Rdf::Resource @TODO: Generalize this.

Parameters:

  • uri (RDF::URI)

    URI that is being looked up.

See Also:



46
47
48
49
50
51
52
# File 'lib/active_fedora/rdf/identifiable.rb', line 46

def from_uri(uri,_)
  begin
    self.find(pid_from_subject(uri))
  rescue ActiveFedora::ObjectNotFoundError
    self.ds_specs[resource_datastream.to_s][:type].resource_class.new(uri)
  end
end

#pid_from_subject(uri) ⇒ Object

Finds the pid of an object from its RDF subject, override this for URI configurations not of form base_uri + pid

Parameters:

  • uri (RDF::URI)

    URI to convert to pid



58
59
60
61
# File 'lib/active_fedora/rdf/identifiable.rb', line 58

def pid_from_subject(uri)
  base_uri = resource_datastream ? self.ds_specs[resource_datastream.to_s][:type].resource_class.base_uri : ActiveFedora::Rdf::ObjectResource.base_uri
  uri.to_s.gsub(base_uri, "")
end

#resource_datastream(ds = nil) ⇒ Object

Returns the datastream whose ActiveFedora::Rdf::Resource is used for the identifiable object. This supports delegating methods to the Resource and #from_uri. Defaults to :descMetadata if it responds to #rdf_subject, otherwise looks for the first registered datastream that does.



30
31
32
33
34
35
36
37
38
# File 'lib/active_fedora/rdf/identifiable.rb', line 30

def resource_datastream(ds=nil)
  @resource_datastream ||= ds ? ds : nil
  return @resource_datastream unless @resource_datastream.nil?
  return :descMetadata if self.ds_specs['descMetadata'][:type].respond_to? :rdf_subject
  self.ds_specs.each do |dsid, conf|
    return dsid.to_sym if conf[:type].respond_to? :rdf_subject
  end
  nil
end