Class: Dbd::Resource
- Inherits:
-
Object
- Object
- Dbd::Resource
- 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 context_subject can optionally be given in the options hash. The context_subject of the Resource will be used as a default for Facts that are added to the Resource.
During build-up of a Fact, the subject and the context_subject can be nil. These will then be set when the Fact is added (with ‘<<’) to a resource.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#context_subject ⇒ Object
readonly
Returns the value of attribute context_subject.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Class Method Summary collapse
-
.new_subject ⇒ Fact::Subject
A new (random) Resource subject.
Instance Method Summary collapse
-
#<<(fact_collection) ⇒ Resource
Add a Fact (strictly not a ContextFact) or recursive collection of facts.
-
#initialize(options = {}) ⇒ Resource
constructor
Build a new resource.
Methods included from Helpers::OrderedSetCollection
add_and_return_index, #each, #freeze, #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 context_subject argument is optional (if all facts in the resource have the same context).
49 50 51 52 53 |
# File 'lib/dbd/resource.rb', line 49 def initialize( = {}) set_subject() set_context_subject() super() end |
Instance Attribute Details
#context_subject ⇒ Object (readonly)
Returns the value of attribute context_subject.
27 28 29 |
# File 'lib/dbd/resource.rb', line 27 def context_subject @context_subject end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
27 28 29 |
# File 'lib/dbd/resource.rb', line 27 def subject @subject end |
Class Method Details
.new_subject ⇒ Fact::Subject
Returns a new (random) Resource subject.
31 32 33 |
# File 'lib/dbd/resource.rb', line 31 def self.new_subject Fact.factory.new_subject end |
Instance Method Details
#<<(fact_collection) ⇒ Resource
Add a Fact (strictly not a ContextFact) or recursive collection of facts
Side effects on subject and context_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.
-
inside one resource, all facts must have same subject
-
if it has no context_subject, the context_subject is set (this modifies the fact !)
-
if is has a context_subject this remains unchanged
-
inside one resource, different facts can have different context_subjects
70 71 72 73 74 75 76 |
# File 'lib/dbd/resource.rb', line 70 def <<(fact_collection) fact_collection.each_recursively do |fact| prepare_fact!(fact) super(fact) end self end |