Class: Dbd::Resource

Inherits:
Object
  • Object
show all
Includes:
Helpers::OrderedSetCollection
Defined in:
lib/dbd/resource.rb

Overview

A Resource is a collection of Facts that have the same subject.

In the real-world this is a mainly an "instance" about which all facts are giving information (e.g. a conference, a person, a bicycle, ...). More generally this can also be used to describe classes and other concepts in the system.

A new (random) subject is generated for a resource. In Dbd, a subject is a random uuid (like a oid), not a meaningful URI as it is in RDF.

A provenance_subject is a required field in the options hash. Practically, first a ProvenanceResource will be created and the subject of that will be used as provenance_subject for the Resources that are associated with it.

During build-up of a Fact, the subject and the provenance_subject can be nil. These will then be set when the Fact is added (with '<<') to a resource.

Direct Known Subclasses

ProvenanceResource

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::OrderedSetCollection

add_and_return_index, #each, #last, #size

Constructor Details

#initialize(options) ⇒ Resource

Build a new resource.

By default, a new (random) subject is generated for a resource. Optionally, an explicit subject can be given in the options parameter (this is best created with the new_subject class method for forward compatibility).

The provenance_subject argument is required. This will typically be taken from an earlier created ProvenanceResource.

Parameters:

  • options (Hash{Symbol => Object})

Options Hash (options):

  • :provenance_subject (Fact::Subject) — default: required —

    the subject of the provenance resource for this resource

  • :subject (Fact::Subject) — default: new_subject —

    Optional: the subject for the resource



50
51
52
53
54
# File 'lib/dbd/resource.rb', line 50

def initialize(options)
  set_subject(options)
  set_provenance_subject(options)
  super()
end

Instance Attribute Details

#provenance_subject ⇒ Object (readonly)

Returns the value of attribute provenance_subject.



28
29
30
# File 'lib/dbd/resource.rb', line 28

def provenance_subject
  @provenance_subject
end

#subject ⇒ Object (readonly)

Returns the value of attribute subject.



28
29
30
# File 'lib/dbd/resource.rb', line 28

def subject
  @subject
end

Class Method Details

.new_subject ⇒ Fact::Subject

Returns a new (random) Resource subject.

Returns:



32
33
34
# File 'lib/dbd/resource.rb', line 32

def self.new_subject
  Fact.new_subject
end

Instance Method Details

#<<(fact) ⇒ Object

Add a Fact (strictly not a ProvenanceFact)

Side effects on subject and provenance_subject:

  • if it has no subject, the subject is set (this modifies the fact !)
  • if is has the same subject as the resource, added unchanged.
  • if it has a different subject, a SubjectError is raised.
  • if it has no provenance_subject, the provenance_subject is set (this modifies the fact !)
  • if is has the same provenance_subject as the resource, added unchanged.
  • if it has a different provenance_subject, a ProvenanceError is raised.


66
67
68
69
70
71
# File 'lib/dbd/resource.rb', line 66

def <<(fact)
  assert_fact_provenance_fact(fact)
  set_fact_subject!(fact)
  set_fact_provenance!(fact)
  super(fact)
end