Module: ActiveTriples::RDFSource::ClassMethods

Defined in:
lib/active_triples/rdf_source.rb

Instance Method Summary collapse

Instance Method Details

#from_uri(uri, vals = nil) ⇒ ActiveTriples::Entity

Adapter for a consistent interface for creating a new Resource from a URI. Similar functionality should exist in all objects which can become a Resource.

Parameters:

  • uri (#to_uri, String)
  • vals (defaults to: nil)

    values to pass as arguments to ::new

Returns:

  • (ActiveTriples::Entity)

    a Resource with the given uri



545
546
547
# File 'lib/active_triples/rdf_source.rb', line 545

def from_uri(uri, vals = nil)
  new(uri, vals)
end

#id_persisted?(test_id) ⇒ TrueClass, FalseClass

Test if the rdf_subject that would be generated using a specific ID is already in use in the triplestore.

Parameters:

  • ID (Integer, #read)

    to test

Returns:

  • (TrueClass, FalseClass)

    true, if the ID is in use in the triplestore; otherwise, false. NOTE: If the ID is in use in an object not yet

    persisted, false will be returned presenting
    a window of opportunity for an ID clash.
    


560
561
562
563
# File 'lib/active_triples/rdf_source.rb', line 560

def id_persisted?(test_id)
  rdf_subject = self.new(test_id).rdf_subject
  ActiveTriples::Repositories.has_subject?(rdf_subject)
end

#uri_persisted?(test_uri) ⇒ TrueClass, FalseClass

Test if the rdf_subject that would be generated using a specific URI is already in use in the triplestore.

Parameters:

  • URI (String, RDF::URI, #read)

    to test

Returns:

  • (TrueClass, FalseClass)

    true, if the URI is in use in the triplestore; otherwise, false. NOTE: If the URI is in use in an object not yet

    persisted, false will be returned presenting
    a window of opportunity for an ID clash.
    


576
577
578
579
# File 'lib/active_triples/rdf_source.rb', line 576

def uri_persisted?(test_uri)
  rdf_subject = test_uri.kind_of?(RDF::URI) ? test_uri : RDF::URI(test_uri)
  ActiveTriples::Repositories.has_subject?(rdf_subject)
end