Readme Persistence example differs from actual behaviour
Created by: eocarragain
When following the README in irb, the output I get differs from the documentation. Specifically, the Person-related triples are persisted to :default rather than :people
Output (c.f. README)
# Registers in-memory repositories. Other implementations of
# RDF::Repository support persistence to (e.g.) triplestores & NoSQL
# databases.
ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
ActiveTriples::Repositories.add_repository :people, RDF::Repository.new
class Person
include ActiveTriples::RDFSource
configure :type => RDF::FOAF.Person, :base_uri => 'http://example.org/people#', :repository => :people
property :name, :predicate => RDF::FOAF.name
end
class Thing
include ActiveTriples::RDFSource
configure :type => RDF::OWL.Thing, :base_uri => 'http://example.org/things#', :repository => :default
property :title, :predicate => RDF::DC.title
property :description, :predicate => RDF::DC.description
property :creator, :predicate => RDF::DC.creator, :class_name => 'Person'
end
t = Thing.new('1')
t.title = 'A Thing'
t.creator = Person.new('1')
t.persisted? # => false
t.creator.first.name = 'Tove'
t.persist!
ActiveTriples::Repositories.repositories[:default].dump :ntriples
# => "<http://example.org/things#1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .\n<http://example.org/things#1> <http://purl.org/dc/terms/title> \"A Thing\" .\n<http://example.org/things#1> <http://purl.org/dc/terms/creator> <http://example.org/people#1> .\n<http://example.org/people#1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .\n<http://example.org/people#1> <http://xmlns.com/foaf/0.1/name> \"Tove\" .\n"
t.creator.first.persisted? # => true
t.creator.first.persist! # => true
ActiveTriples::Repositories.repositories[:people].dump :ntriples
# => ""
If i create and persist a Person instance without associating it with a Thing instance, it works as expected:
p2 = Person.new("2")
# => #<Person:0x4997b6e(#<Person:0x932f6dc>)>
p2.name ="Nom"
# => "Nom"
p2.persisted?
# => false
ActiveTriples::Repositories.repositories[:people].dump :ntriples
# => ""
p2.persist!
# => true
p2.persisted?
# => true
ActiveTriples::Repositories.repositories[:people].dump :ntriples
# => "<http://example.org/people#2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .\n<http://example.org/people#2> <http://xmlns.com/foaf/0.1/name> \"Nom\" .\n"