active-triples 0.6.1 → 0.7.0
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/.travis.yml +7 -3
- data/CHANGES.md +20 -0
- data/Gemfile +2 -0
- data/README.md +21 -17
- data/lib/active_triples.rb +6 -1
- data/lib/active_triples/configurable.rb +18 -19
- data/lib/active_triples/configuration.rb +72 -0
- data/lib/active_triples/configuration/item.rb +20 -0
- data/lib/active_triples/configuration/item_factory.rb +27 -0
- data/lib/active_triples/configuration/merge_item.rb +14 -0
- data/lib/active_triples/identifiable.rb +3 -3
- data/lib/active_triples/list.rb +6 -4
- data/lib/active_triples/property_builder.rb +10 -2
- data/lib/active_triples/rdf_source.rb +582 -0
- data/lib/active_triples/{term.rb → relation.rb} +40 -15
- data/lib/active_triples/resource.rb +9 -534
- data/lib/active_triples/version.rb +1 -1
- data/spec/active_triples/configurable_spec.rb +18 -2
- data/spec/active_triples/configuration_spec.rb +59 -0
- data/spec/active_triples/identifiable_spec.rb +12 -11
- data/spec/active_triples/list_spec.rb +13 -7
- data/spec/active_triples/nested_attributes_spec.rb +12 -6
- data/spec/active_triples/properties_spec.rb +19 -1
- data/spec/active_triples/rdf_source_spec.rb +5 -0
- data/spec/active_triples/{term_spec.rb → relation_spec.rb} +9 -7
- data/spec/active_triples/repositories_spec.rb +7 -4
- data/spec/active_triples/resource_spec.rb +24 -26
- data/spec/active_triples_spec.rb +9 -0
- data/spec/pragmatic_context_spec.rb +6 -4
- data/spec/spec_helper.rb +1 -0
- metadata +14 -5
@@ -20,6 +20,12 @@ describe ActiveTriples::Resource do
|
|
20
20
|
|
21
21
|
subject { DummyResource.new }
|
22
22
|
|
23
|
+
describe '#property' do
|
24
|
+
it 'raises error when set directly on Resource' do
|
25
|
+
expect { ActiveTriples::Resource.property :blah, :predicate => RDF::DC.title }.to raise_error
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
23
29
|
describe 'rdf_subject' do
|
24
30
|
it "should be a blank node if we haven't set it" do
|
25
31
|
expect(subject.rdf_subject.node?).to be true
|
@@ -429,10 +435,10 @@ describe ActiveTriples::Resource do
|
|
429
435
|
end
|
430
436
|
|
431
437
|
describe 'array setters' do
|
432
|
-
before do
|
438
|
+
before do
|
433
439
|
DummyResource.property :aggregates, :predicate => RDF::DC.relation
|
434
440
|
end
|
435
|
-
|
441
|
+
|
436
442
|
it "should be empty array if we haven't set it" do
|
437
443
|
expect(subject.aggregates).to match_array([])
|
438
444
|
end
|
@@ -449,7 +455,7 @@ describe ActiveTriples::Resource do
|
|
449
455
|
expect(subject.aggregates_ids).to eq [aggregates_uri]
|
450
456
|
end
|
451
457
|
end
|
452
|
-
|
458
|
+
|
453
459
|
it "should be settable" do
|
454
460
|
subject.aggregates = RDF::URI("http://example.org/b1")
|
455
461
|
expect(subject.aggregates.first.rdf_subject).to eq RDF::URI("http://example.org/b1")
|
@@ -460,13 +466,13 @@ describe ActiveTriples::Resource do
|
|
460
466
|
let(:bib1) { RDF::URI("http://example.org/b1") }
|
461
467
|
let(:bib2) { RDF::URI("http://example.org/b2") }
|
462
468
|
let(:bib3) { RDF::URI("http://example.org/b3") }
|
463
|
-
|
469
|
+
|
464
470
|
before do
|
465
471
|
subject.aggregates = bib1
|
466
472
|
subject.aggregates << bib2
|
467
473
|
subject.aggregates << bib3
|
468
474
|
end
|
469
|
-
|
475
|
+
|
470
476
|
it 'raises error when trying to set nil value' do
|
471
477
|
expect { subject.aggregates[1] = nil }.to raise_error /value must be an RDF URI, Node, Literal, or a valid datatype/
|
472
478
|
end
|
@@ -474,12 +480,12 @@ describe ActiveTriples::Resource do
|
|
474
480
|
it "should be changeable for multiple values" do
|
475
481
|
new_bib1 = RDF::URI("http://example.org/b1_NEW")
|
476
482
|
new_bib3 = RDF::URI("http://example.org/b3_NEW")
|
477
|
-
|
483
|
+
|
478
484
|
aggregates = subject.aggregates.dup
|
479
485
|
aggregates[0] = new_bib1
|
480
486
|
aggregates[2] = new_bib3
|
481
487
|
subject.aggregates = aggregates
|
482
|
-
|
488
|
+
|
483
489
|
expect(subject.aggregates[0].rdf_subject).to eq new_bib1
|
484
490
|
expect(subject.aggregates[1].rdf_subject).to eq bib2
|
485
491
|
expect(subject.aggregates[2].rdf_subject).to eq new_bib3
|
@@ -490,7 +496,7 @@ describe ActiveTriples::Resource do
|
|
490
496
|
end
|
491
497
|
end
|
492
498
|
end
|
493
|
-
|
499
|
+
|
494
500
|
describe 'child nodes' do
|
495
501
|
it 'should return an object of the correct class when the value is a URI' do
|
496
502
|
subject.license = DummyLicense.new('http://example.org/license')
|
@@ -521,7 +527,7 @@ describe ActiveTriples::Resource do
|
|
521
527
|
subject.set_value(RDF::DC.title, RDF::URI("http://opaquenamespace.org/jokes/1"))
|
522
528
|
end
|
523
529
|
it "should return a resource" do
|
524
|
-
expect(subject.title.first).to be_kind_of(ActiveTriples::
|
530
|
+
expect(subject.title.first).to be_kind_of(ActiveTriples::RDFSource)
|
525
531
|
end
|
526
532
|
context "and it's configured to not cast" do
|
527
533
|
before do
|
@@ -539,7 +545,7 @@ describe ActiveTriples::Resource do
|
|
539
545
|
subject.set_value('license',vals)
|
540
546
|
expect(subject.get_values('license')).to eq ["foo"]
|
541
547
|
end
|
542
|
-
|
548
|
+
|
543
549
|
it "safely handles terms passed in with pre-existing values" do
|
544
550
|
subject.license = "foo"
|
545
551
|
vals = subject.get_values('license')
|
@@ -604,7 +610,7 @@ describe ActiveTriples::Resource do
|
|
604
610
|
let(:literal1) { RDF::Literal.new("test", :language => :en) }
|
605
611
|
let(:literal2) { RDF::Literal.new("test", :language => :fr) }
|
606
612
|
before do
|
607
|
-
subject.set_value(RDF::DC.title, [literal1, literal2])
|
613
|
+
subject.set_value(RDF::DC.title, [literal1, literal2])
|
608
614
|
end
|
609
615
|
context "and literals are not requested" do
|
610
616
|
it "should return a string" do
|
@@ -643,7 +649,7 @@ describe ActiveTriples::Resource do
|
|
643
649
|
|
644
650
|
describe '#type' do
|
645
651
|
it 'should return the type configured on the parent class' do
|
646
|
-
expect(subject.type).to eq
|
652
|
+
expect(subject.type).to eq DummyResource.type
|
647
653
|
end
|
648
654
|
|
649
655
|
it 'should set the type' do
|
@@ -677,17 +683,6 @@ describe ActiveTriples::Resource do
|
|
677
683
|
end
|
678
684
|
end
|
679
685
|
|
680
|
-
describe '#solrize' do
|
681
|
-
it 'should return a label for bnodes' do
|
682
|
-
expect(subject.solrize).to eq subject.rdf_label
|
683
|
-
end
|
684
|
-
|
685
|
-
it 'should return a string of the resource uri' do
|
686
|
-
subject.set_subject! 'http://example.org/moomin'
|
687
|
-
expect(subject.solrize).to eq 'http://example.org/moomin'
|
688
|
-
end
|
689
|
-
end
|
690
|
-
|
691
686
|
describe 'editing the graph' do
|
692
687
|
it 'should write properties when statements are added' do
|
693
688
|
subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, 'Comet in Moominland')
|
@@ -703,14 +698,16 @@ describe ActiveTriples::Resource do
|
|
703
698
|
|
704
699
|
describe 'big complex graphs' do
|
705
700
|
before do
|
706
|
-
class DummyPerson
|
701
|
+
class DummyPerson
|
702
|
+
include ActiveTriples::RDFSource
|
707
703
|
configure :type => RDF::URI('http://example.org/Person')
|
708
704
|
property :foaf_name, :predicate => RDF::FOAF.name
|
709
705
|
property :publications, :predicate => RDF::FOAF.publications, :class_name => 'DummyDocument'
|
710
706
|
property :knows, :predicate => RDF::FOAF.knows, :class_name => DummyPerson
|
711
707
|
end
|
712
708
|
|
713
|
-
class DummyDocument
|
709
|
+
class DummyDocument
|
710
|
+
include ActiveTriples::RDFSource
|
714
711
|
configure :type => RDF::URI('http://example.org/Document')
|
715
712
|
property :title, :predicate => RDF::DC.title
|
716
713
|
property :creator, :predicate => RDF::DC.creator, :class_name => 'DummyPerson'
|
@@ -777,7 +774,8 @@ END
|
|
777
774
|
describe "callbacks" do
|
778
775
|
describe ".before_persist" do
|
779
776
|
before do
|
780
|
-
class DummyResource
|
777
|
+
class DummyResource
|
778
|
+
include ActiveTriples::RDFSource
|
781
779
|
def bla
|
782
780
|
self.title = "test"
|
783
781
|
end
|
@@ -3,14 +3,16 @@ require 'pragmatic_context'
|
|
3
3
|
|
4
4
|
describe 'PragmaticContext integration' do
|
5
5
|
before do
|
6
|
-
class DummyLicense
|
6
|
+
class DummyLicense
|
7
|
+
include ActiveTriples::RDFSource
|
7
8
|
include PragmaticContext::Contextualizable
|
8
9
|
property :title, :predicate => RDF::DC.title
|
9
10
|
|
10
11
|
contextualize :title, :as => RDF::DC.title.to_s
|
11
12
|
end
|
12
13
|
|
13
|
-
class DummyResource
|
14
|
+
class DummyResource
|
15
|
+
include ActiveTriples::RDFSource
|
14
16
|
include PragmaticContext::Contextualizable
|
15
17
|
|
16
18
|
configure :type => RDF::URI('http://example.org/SomeClass')
|
@@ -41,9 +43,9 @@ describe 'PragmaticContext integration' do
|
|
41
43
|
end
|
42
44
|
|
43
45
|
it 'should have contexts' do
|
44
|
-
expect(subject.as_jsonld['@context'].keys).to
|
46
|
+
expect(subject.as_jsonld['@context'].keys).to contain_exactly('license', 'title')
|
45
47
|
end
|
46
|
-
|
48
|
+
|
47
49
|
it 'should use context with dump' do
|
48
50
|
context = JSON.parse(subject.dump :jsonld)['@context']
|
49
51
|
subject.class.properties.keys.each do |prop|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-triples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Johnson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdf
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- ".gitignore"
|
192
192
|
- ".travis.yml"
|
193
193
|
- AUTHORS
|
194
|
+
- CHANGES.md
|
194
195
|
- Gemfile
|
195
196
|
- Guardfile
|
196
197
|
- LICENSE
|
@@ -200,25 +201,33 @@ files:
|
|
200
201
|
- lib/active/triples.rb
|
201
202
|
- lib/active_triples.rb
|
202
203
|
- lib/active_triples/configurable.rb
|
204
|
+
- lib/active_triples/configuration.rb
|
205
|
+
- lib/active_triples/configuration/item.rb
|
206
|
+
- lib/active_triples/configuration/item_factory.rb
|
207
|
+
- lib/active_triples/configuration/merge_item.rb
|
203
208
|
- lib/active_triples/identifiable.rb
|
204
209
|
- lib/active_triples/list.rb
|
205
210
|
- lib/active_triples/nested_attributes.rb
|
206
211
|
- lib/active_triples/node_config.rb
|
207
212
|
- lib/active_triples/properties.rb
|
208
213
|
- lib/active_triples/property_builder.rb
|
214
|
+
- lib/active_triples/rdf_source.rb
|
209
215
|
- lib/active_triples/reflection.rb
|
216
|
+
- lib/active_triples/relation.rb
|
210
217
|
- lib/active_triples/repositories.rb
|
211
218
|
- lib/active_triples/resource.rb
|
212
|
-
- lib/active_triples/term.rb
|
213
219
|
- lib/active_triples/version.rb
|
214
220
|
- spec/active_triples/configurable_spec.rb
|
221
|
+
- spec/active_triples/configuration_spec.rb
|
215
222
|
- spec/active_triples/identifiable_spec.rb
|
216
223
|
- spec/active_triples/list_spec.rb
|
217
224
|
- spec/active_triples/nested_attributes_spec.rb
|
218
225
|
- spec/active_triples/properties_spec.rb
|
226
|
+
- spec/active_triples/rdf_source_spec.rb
|
227
|
+
- spec/active_triples/relation_spec.rb
|
219
228
|
- spec/active_triples/repositories_spec.rb
|
220
229
|
- spec/active_triples/resource_spec.rb
|
221
|
-
- spec/
|
230
|
+
- spec/active_triples_spec.rb
|
222
231
|
- spec/pragmatic_context_spec.rb
|
223
232
|
- spec/spec_helper.rb
|
224
233
|
- spec/support/active_model_lint.rb
|
@@ -242,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
251
|
version: '0'
|
243
252
|
requirements: []
|
244
253
|
rubyforge_project:
|
245
|
-
rubygems_version: 2.2.
|
254
|
+
rubygems_version: 2.2.1
|
246
255
|
signing_key:
|
247
256
|
specification_version: 4
|
248
257
|
summary: RDF graphs in ActiveModel wrappers.
|