dbd 0.0.19 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/HISTORY.txt +5 -0
- data/lib/dbd/context.rb +1 -1
- data/lib/dbd/graph.rb +20 -0
- data/lib/dbd/resource.rb +22 -17
- data/lib/dbd/version.rb +1 -1
- data/spec/lib/dbd/graph/methods_spec.rb +33 -0
- data/spec/lib/dbd/resource/collection_spec.rb +21 -12
- data/spec/lib/dbd/resource/new_spec.rb +17 -14
- data/spec/lib/dbd/resource/test_factories_spec.rb +5 -4
- data/spec/test_factories/resource.rb +2 -9
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dee663a858909394b98fac3db46fc8555a2abdcf
|
4
|
+
data.tar.gz: 0dda169214ad947ac23e4d04f62b60cc0c9dc723
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79597df1ed60147831542ffaa689123a9706bab7047d07622b772b988fb59e16893dc5c0d2b97b32cfa1ab3656fcb9d13ecb80f2992b2db76e9f0bc5f5cbb8c3
|
7
|
+
data.tar.gz: 534fe8b6fa1157cd8bcce028a2636518ee4c02f8a5dccc02c213e0b6a653584e0e050f8e137ec23956b503d01d3d1f350d52268ab4f8447f45d0bbb76ed593e6
|
data/HISTORY.txt
CHANGED
data/lib/dbd/context.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Dbd
|
2
2
|
##
|
3
3
|
# A Context is derived from a Resource, and is the
|
4
|
-
# set of all
|
4
|
+
# set of all ContextFacts that share the same subject.
|
5
5
|
#
|
6
6
|
# It is pointed to by a context_subject of a Fact and has
|
7
7
|
# no context_subject itself (the context_subject
|
data/lib/dbd/graph.rb
CHANGED
@@ -85,8 +85,28 @@ module Dbd
|
|
85
85
|
on_sorted_file(filename) { |sorted_file| from_CSV(sorted_file) }
|
86
86
|
end
|
87
87
|
|
88
|
+
##
|
89
|
+
# Return an array of resources for graph
|
90
|
+
#
|
91
|
+
# @return [Array] array with all resources
|
92
|
+
def resources
|
93
|
+
subjects.map do |subject|
|
94
|
+
facts = by_subject(subject)
|
95
|
+
resource_from_facts(subject, facts)
|
96
|
+
end.compact
|
97
|
+
end
|
98
|
+
|
88
99
|
private
|
89
100
|
|
101
|
+
# FIXME : the context_subject argument must not be given here
|
102
|
+
def resource_from_facts(subject, facts)
|
103
|
+
unless facts.first.is_a?(ContextFact)
|
104
|
+
context_subject = facts.first.context_subject
|
105
|
+
resource = Resource.new(subject: subject, context_subject: context_subject)
|
106
|
+
resource << facts
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
90
110
|
##
|
91
111
|
# Setting a strictly monotonically increasing time_stamp (if not yet set).
|
92
112
|
# The time_stamp also has some randomness (1 .. 999 ns) to reduce the
|
data/lib/dbd/resource.rb
CHANGED
@@ -13,10 +13,9 @@ module Dbd
|
|
13
13
|
# a subject is a random uuid (like a oid), not a meaningful URI
|
14
14
|
# as it is in RDF.
|
15
15
|
#
|
16
|
-
# A context_subject
|
17
|
-
#
|
18
|
-
#
|
19
|
-
# Resources that are associated with it.
|
16
|
+
# A context_subject can optionally be given in the options hash.
|
17
|
+
# The context_subject of the Resource will be used as a default
|
18
|
+
# for Facts that are added to the Resource.
|
20
19
|
#
|
21
20
|
# During build-up of a Fact, the subject and the context_subject
|
22
21
|
# can be nil. These will then be set when the Fact is added
|
@@ -41,13 +40,13 @@ module Dbd
|
|
41
40
|
# (this is best created with the new_subject class method for forward
|
42
41
|
# compatibility).
|
43
42
|
#
|
44
|
-
# The context_subject argument is
|
45
|
-
#
|
43
|
+
# The context_subject argument is optional (if all facts in the resource
|
44
|
+
# have the same context).
|
46
45
|
#
|
47
|
-
# @param [Hash{Symbol => Object}] options
|
48
|
-
# @option options [Fact::Subject] :context_subject (
|
46
|
+
# @param [Hash{Symbol => Object}] options (optional)
|
47
|
+
# @option options [Fact::Subject] :context_subject (nil) Optional: the subject of the context for this resource
|
49
48
|
# @option options [Fact::Subject] :subject (new_subject) Optional: the subject for the resource
|
50
|
-
def initialize(options)
|
49
|
+
def initialize(options = {})
|
51
50
|
set_subject(options)
|
52
51
|
set_context_subject(options)
|
53
52
|
super()
|
@@ -60,18 +59,17 @@ module Dbd
|
|
60
59
|
# * if it has no subject, the subject is set (this modifies the fact !)
|
61
60
|
# * if is has the same subject as the resource, added unchanged.
|
62
61
|
# * if it has a different subject, a SubjectError is raised.
|
62
|
+
# * inside one resource, all facts must have same subject
|
63
63
|
#
|
64
64
|
# * if it has no context_subject, the context_subject is set (this modifies the fact !)
|
65
|
-
# * if is has
|
66
|
-
# *
|
65
|
+
# * if is has a context_subject this remains unchanged
|
66
|
+
# * inside one resource, different facts can have different context_subjects
|
67
67
|
#
|
68
68
|
# @param [Fact, #each] fact_collection a recursive collection of Facts
|
69
69
|
# @return [Resource] self
|
70
70
|
def <<(fact_collection)
|
71
71
|
fact_collection.each_recursively do |fact|
|
72
|
-
|
73
|
-
set_fact_subject!(fact)
|
74
|
-
set_fact_context_subject!(fact)
|
72
|
+
prepare_fact!(fact)
|
75
73
|
super(fact)
|
76
74
|
end
|
77
75
|
self
|
@@ -84,16 +82,23 @@ module Dbd
|
|
84
82
|
end
|
85
83
|
|
86
84
|
def set_context_subject(options)
|
87
|
-
@context_subject = options[:context_subject]
|
88
|
-
raise ContextError, "context_subject cannot be nil" if @context_subject.nil?
|
85
|
+
@context_subject = options[:context_subject] # nil default
|
89
86
|
end
|
90
87
|
|
91
88
|
def set_fact_subject!(fact)
|
89
|
+
# this is protected by a SetOnce immutable behavior
|
92
90
|
fact.subject = subject
|
93
91
|
end
|
94
92
|
|
95
93
|
def set_fact_context_subject!(fact)
|
96
|
-
|
94
|
+
#context_subject from fact has priority
|
95
|
+
fact.context_subject ||= context_subject
|
96
|
+
end
|
97
|
+
|
98
|
+
def prepare_fact!(fact)
|
99
|
+
assert_fact_or_context_fact(fact)
|
100
|
+
set_fact_subject!(fact)
|
101
|
+
set_fact_context_subject!(fact)
|
97
102
|
end
|
98
103
|
|
99
104
|
# Assert _no_ Contexts here
|
data/lib/dbd/version.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Dbd
|
4
|
+
describe Graph do
|
5
|
+
let(:full_graph) { TestFactories::Graph.full }
|
6
|
+
|
7
|
+
context 'resources' do
|
8
|
+
it 'is an array' do
|
9
|
+
full_graph.resources.should be_a(Array)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'is an array of resources' do
|
13
|
+
full_graph.resources.each do |resource|
|
14
|
+
resource.should be_a(Resource)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'the resource has the facts' do
|
19
|
+
facts = full_graph.reject(&:context_fact?)
|
20
|
+
full_graph.resources.single.should include(*facts)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'the resource does not have has the context_facts' do
|
24
|
+
context_facts = full_graph.select(&:context_fact?)
|
25
|
+
full_graph.resources.single.should_not include(*context_facts)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'has at least one entry' do
|
29
|
+
full_graph.resources.should_not be_empty
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -4,8 +4,11 @@ module Dbd
|
|
4
4
|
describe Resource do
|
5
5
|
|
6
6
|
let(:context_subject) { TestFactories::ContextFact.new_subject }
|
7
|
-
let(:
|
8
|
-
let(:resource_subject) {
|
7
|
+
let(:other_context_subject) { TestFactories::ContextFact.new_subject }
|
8
|
+
let(:resource_subject) { TestFactories::Fact.new_subject }
|
9
|
+
let(:resource) { described_class.new(subject: resource_subject) }
|
10
|
+
let(:resource_with_context_subject) { described_class.new(context_subject: context_subject,
|
11
|
+
subject: resource_subject) }
|
9
12
|
|
10
13
|
describe 'the fact collection' do
|
11
14
|
|
@@ -15,7 +18,7 @@ module Dbd
|
|
15
18
|
let(:fact_with_context) { TestFactories::Fact.data_fact(context_subject, nil) }
|
16
19
|
let(:fact_with_resource_subject) { TestFactories::Fact.data_fact(nil, resource_subject) }
|
17
20
|
let(:fact_with_context_and_resource_subject) { TestFactories::Fact.data_fact(context_subject, resource_subject) }
|
18
|
-
let(:
|
21
|
+
let(:fact_with_other_context_and_resource_subject) { TestFactories::Fact.data_fact(other_context_subject, resource_subject) }
|
19
22
|
let(:context_fact_visibility) { TestFactories::ContextFact.visibility }
|
20
23
|
|
21
24
|
it 'enumerable functions work' do
|
@@ -96,17 +99,22 @@ module Dbd
|
|
96
99
|
describe 'adding a fact with a context_fact subject :' do
|
97
100
|
describe 'when the context_subject of the fact is equal to the context_subject of the resource' do
|
98
101
|
it 'inserts the fact unaltered' do
|
99
|
-
|
100
|
-
|
102
|
+
resource_with_context_subject << fact_with_context
|
103
|
+
resource_with_context_subject.single.should be_equal(fact_with_context)
|
101
104
|
end
|
102
105
|
end
|
103
106
|
|
104
107
|
describe 'when the context_subject of the fact is not equal to the resource' do
|
105
|
-
it '
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
108
|
+
it 'the context_fact of the fact wins' do
|
109
|
+
resource_with_context_subject << fact_with_other_context_and_resource_subject
|
110
|
+
resource_with_context_subject.single.should be_equal(fact_with_other_context_and_resource_subject)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe 'when the context_subject of the fact is set and the resource has no context_subject' do
|
115
|
+
it 'the context_fact of the fact wins' do
|
116
|
+
resource << fact_with_context_and_resource_subject
|
117
|
+
resource.single.should be_equal(fact_with_context_and_resource_subject)
|
110
118
|
end
|
111
119
|
end
|
112
120
|
end
|
@@ -114,10 +122,11 @@ module Dbd
|
|
114
122
|
describe 'adding a fact without context_subject' do
|
115
123
|
|
116
124
|
before(:each) do
|
117
|
-
|
125
|
+
fact_with_resource_subject.context_subject.should be_nil # assert pre-condition
|
126
|
+
resource_with_context_subject << fact_with_resource_subject
|
118
127
|
end
|
119
128
|
|
120
|
-
let(:fact_in_resource) {
|
129
|
+
let(:fact_in_resource) { resource_with_context_subject.single }
|
121
130
|
|
122
131
|
it 'inserts the same instance' do
|
123
132
|
fact_in_resource.should be_equal(fact_with_resource_subject)
|
@@ -4,7 +4,8 @@ module Dbd
|
|
4
4
|
describe Resource do
|
5
5
|
|
6
6
|
let(:context_subject) { TestFactories::ContextFact.new_subject }
|
7
|
-
let(:resource) { described_class.new
|
7
|
+
let(:resource) { described_class.new }
|
8
|
+
let(:resource_with_context_subject) { described_class.new(context_subject: context_subject) }
|
8
9
|
|
9
10
|
describe '.new_subject' do
|
10
11
|
it 'returns a Fact#new_subject' do
|
@@ -13,29 +14,31 @@ module Dbd
|
|
13
14
|
end
|
14
15
|
|
15
16
|
describe '.new' do
|
16
|
-
|
17
|
+
|
18
|
+
describe 'without a context_subject argument' do
|
17
19
|
it 'has created a subject' do
|
18
20
|
resource.subject.should be_a(described_class.new_subject.class)
|
19
21
|
end
|
20
22
|
|
21
|
-
it 'has
|
22
|
-
resource.context_subject.should
|
23
|
+
it 'has a nil context_subject' do
|
24
|
+
resource.context_subject.should be_nil
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
describe 'with
|
27
|
-
it 'has
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
describe 'with a context_subject argument' do
|
29
|
+
it 'has created a subject' do
|
30
|
+
resource_with_context_subject.subject.should be_a(described_class.new_subject.class)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'has stored the explicit context_subject' do
|
34
|
+
resource_with_context_subject.context_subject.should == context_subject
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
35
|
-
describe 'with
|
36
|
-
it '
|
37
|
-
|
38
|
-
|
38
|
+
describe 'with an explicit subject argument' do
|
39
|
+
it 'has stored the given subject' do
|
40
|
+
explicit_subject = described_class.new_subject
|
41
|
+
described_class.new(subject: explicit_subject).subject.should == explicit_subject
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
@@ -7,18 +7,19 @@ module TestFactories
|
|
7
7
|
|
8
8
|
describe "TestFactories::Resource" do
|
9
9
|
it ".empty works" do
|
10
|
-
resource = described_class.empty
|
11
|
-
resource.context_subject.should ==
|
10
|
+
resource = described_class.empty
|
11
|
+
resource.context_subject.should == nil
|
12
12
|
end
|
13
13
|
|
14
14
|
describe ".facts_resource" do
|
15
15
|
it "works with explicit context_subject" do
|
16
|
-
described_class.facts_resource(context_subject)
|
16
|
+
resource = described_class.facts_resource(context_subject)
|
17
|
+
resource.context_subject.should == context_subject
|
17
18
|
end
|
18
19
|
|
19
20
|
it "works without explicit context_subject" do
|
20
21
|
resource = described_class.facts_resource()
|
21
|
-
resource.context_subject.
|
22
|
+
resource.context_subject.should be_nil
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
@@ -10,24 +10,17 @@ module TestFactories
|
|
10
10
|
::Dbd::Fact
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.empty(context_subject)
|
13
|
+
def self.empty(context_subject = nil)
|
14
14
|
subject = element_class.factory.new_subject
|
15
15
|
factory_for.new(subject: subject, context_subject: context_subject)
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.facts_resource(context_subject =
|
18
|
+
def self.facts_resource(context_subject = nil)
|
19
19
|
subject = element_class.factory.new_subject
|
20
20
|
factory_for.new(subject: subject, context_subject: context_subject).tap do |resource|
|
21
21
|
resource << TestFactories::Fact.data_fact(context_subject, subject)
|
22
22
|
resource << TestFactories::Fact.data_fact_EU(context_subject, subject)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def self.context_subject
|
29
|
-
TestFactories::ContextFact.new_subject
|
30
|
-
end
|
31
|
-
|
32
25
|
end
|
33
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Vandenabeele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -221,6 +221,7 @@ files:
|
|
221
221
|
- spec/lib/dbd/fact/test_factories_spec.rb
|
222
222
|
- spec/lib/dbd/graph/add_to_graph_spec.rb
|
223
223
|
- spec/lib/dbd/graph/from_csv_spec.rb
|
224
|
+
- spec/lib/dbd/graph/methods_spec.rb
|
224
225
|
- spec/lib/dbd/graph/test_factories_spec.rb
|
225
226
|
- spec/lib/dbd/graph/to_csv_spec.rb
|
226
227
|
- spec/lib/dbd/helpers/ordered_set_collection/ordered_set_collection_spec.rb
|
@@ -289,6 +290,7 @@ test_files:
|
|
289
290
|
- spec/lib/dbd/fact/test_factories_spec.rb
|
290
291
|
- spec/lib/dbd/graph/add_to_graph_spec.rb
|
291
292
|
- spec/lib/dbd/graph/from_csv_spec.rb
|
293
|
+
- spec/lib/dbd/graph/methods_spec.rb
|
292
294
|
- spec/lib/dbd/graph/test_factories_spec.rb
|
293
295
|
- spec/lib/dbd/graph/to_csv_spec.rb
|
294
296
|
- spec/lib/dbd/helpers/ordered_set_collection/ordered_set_collection_spec.rb
|