Module: ActiveTriples::RDFSource::ClassMethods

Defined in:
lib/active_triples/rdf_source.rb

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



566
567
568
569
570
# File 'lib/active_triples/rdf_source.rb', line 566

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

#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



556
557
558
# File 'lib/active_triples/rdf_source.rb', line 556

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.
    


583
584
585
586
# File 'lib/active_triples/rdf_source.rb', line 583

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.
    


599
600
601
602
# File 'lib/active_triples/rdf_source.rb', line 599

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