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:

  • ActiveFedora::Rdf::Resource.from_uri


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

def from_uri(uri,_)
  begin
    ActiveFedora::Base.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



60
61
62
63
64
# File 'lib/active_fedora/rdf/identifiable.rb', line 60

def pid_from_subject(uri)
  base_uri = self.ds_specs[resource_datastream.to_s][:type].resource_class.base_uri if resource_datastream
  base_uri = base_uri || ActiveFedora::RDF::Persistence::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.



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

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