Module: ActiveTriples::RDFSource::ClassMethods

Defined in:
lib/active_triples/rdf_source.rb

Overview

Class methods for RDFSource, included via ActiveSupport

Instance Method Summary collapse

Instance Method Details

#apply_schema(schema, strategy = ActiveTriples::ExtensionStrategy) ⇒ Object

Apply a predicate mapping using a given strategy.

Parameters:

  • schema (ActiveTriples::Schema, #properties)

    A schema to apply.

  • strategy (#apply!) (defaults to: ActiveTriples::ExtensionStrategy)

    A strategy for applying. Defaults to ActiveTriples::ExtensionStrategy



712
713
714
# File 'lib/active_triples/rdf_source.rb', line 712

def apply_schema(schema, strategy = ActiveTriples::ExtensionStrategy)
  schema.properties.each { |property| strategy.apply(self, property) }
end

#from_uri(uri, *args) ⇒ 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)
  • args

    values to pass as arguments to ::new

Returns:

  • (ActiveTriples::Entity)

    a Resource with the given uri



702
703
704
# File 'lib/active_triples/rdf_source.rb', line 702

def from_uri(uri, *args)
  new(uri, *args)
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.
    


727
728
729
730
731
# File 'lib/active_triples/rdf_source.rb', line 727

def id_persisted?(test_id)
  rdf_subject = 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.
    


744
745
746
747
748
# File 'lib/active_triples/rdf_source.rb', line 744

def uri_persisted?(test_uri)
  test_uri = RDF::URI.intern(test_uri) unless test_uri.is_a?(RDF::URI)

  ActiveTriples::Repositories.has_subject?(test_uri)
end