active-triples 0.10.2 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitlab-ci.yml +47 -0
- data/.travis.yml +9 -7
- data/CHANGES.md +32 -13
- data/Gemfile +8 -1
- data/README.md +75 -42
- data/active-triples.gemspec +15 -14
- data/lib/active_triples/configurable.rb +6 -1
- data/lib/active_triples/configuration.rb +22 -11
- data/lib/active_triples/extension_strategy.rb +1 -1
- data/lib/active_triples/list.rb +1 -6
- data/lib/active_triples/nested_attributes.rb +10 -7
- data/lib/active_triples/node_config.rb +64 -8
- data/lib/active_triples/persistable.rb +12 -9
- data/lib/active_triples/persistence_strategies/parent_strategy.rb +57 -43
- data/lib/active_triples/persistence_strategies/persistence_strategy.rb +14 -1
- data/lib/active_triples/properties.rb +27 -12
- data/lib/active_triples/property.rb +36 -11
- data/lib/active_triples/property_builder.rb +4 -4
- data/lib/active_triples/rdf_source.rb +218 -188
- data/lib/active_triples/relation.rb +350 -180
- data/lib/active_triples/schema.rb +20 -1
- data/lib/active_triples/util/buffered_transaction.rb +126 -0
- data/lib/active_triples/util/extended_bounded_description.rb +75 -0
- data/lib/active_triples/version.rb +1 -1
- data/spec/active_triples/configurable_spec.rb +35 -7
- data/spec/active_triples/extension_strategy_spec.rb +12 -1
- data/spec/active_triples/identifiable_spec.rb +19 -6
- data/spec/active_triples/list_spec.rb +15 -7
- data/spec/active_triples/nested_attributes_spec.rb +12 -10
- data/spec/active_triples/node_config_spec.rb +54 -0
- data/spec/active_triples/persistable_spec.rb +0 -4
- data/spec/active_triples/persistence_strategies/parent_strategy_spec.rb +80 -26
- data/spec/active_triples/property_spec.rb +10 -0
- data/spec/active_triples/rdf_source_spec.rb +198 -177
- data/spec/active_triples/relation_spec.rb +628 -137
- data/spec/active_triples/resource_spec.rb +123 -23
- data/spec/active_triples/schema_spec.rb +6 -0
- data/spec/active_triples/util/buffered_transaction_spec.rb +187 -0
- data/spec/active_triples/util/extended_bounded_description_spec.rb +98 -0
- data/spec/integration/reciprocal_properties_spec.rb +10 -10
- data/spec/spec_helper.rb +2 -2
- data/spec/support/matchers.rb +13 -1
- metadata +90 -49
- data/spec/pragmatic_context_spec.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b0ff972e1b4c29224d95c3b805194625adb62bd2e0b2f8e6bc10dce62fb048d0
|
4
|
+
data.tar.gz: b53c8cc0662587141709428bd6bb4aa522ddd24387d1b10807202c23a1e66554
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cb53a7845d93423d84bdac4fa82b6470f28867ee5cf8c4bc04f8ba5a3046cc3b6c6f34f8ef2a04aa211c880a7c55700e68cbfc3a73729382a5e4409933b4dd6
|
7
|
+
data.tar.gz: 279c0e2236bf9ad69aefc7e8e3e41e697431b8b103e548cc75b0985eeac1237e598f5fe89da71f9e4d86bad92bec84d4ab94b51c1a0798eb149021b0068d350f
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
.rspec:
|
2
|
+
script:
|
3
|
+
- bundle exec rspec
|
4
|
+
|
5
|
+
.jruby:
|
6
|
+
extends: .rspec
|
7
|
+
before_script:
|
8
|
+
- apk add git
|
9
|
+
- ruby -v
|
10
|
+
- bundle install --jobs $(nproc) "${FLAGS[@]}"
|
11
|
+
|
12
|
+
before_script:
|
13
|
+
- ruby -v
|
14
|
+
- bundle install --jobs $(nproc) "${FLAGS[@]}"
|
15
|
+
|
16
|
+
stages:
|
17
|
+
- test
|
18
|
+
|
19
|
+
ruby-2-4:
|
20
|
+
image: ruby:2.4
|
21
|
+
extends: .rspec
|
22
|
+
stage: test
|
23
|
+
|
24
|
+
ruby-2-5:
|
25
|
+
image: ruby:2.4
|
26
|
+
extends: .rspec
|
27
|
+
stage: test
|
28
|
+
|
29
|
+
ruby-2-6:
|
30
|
+
image: ruby:2.5
|
31
|
+
extends: .rspec
|
32
|
+
stage: test
|
33
|
+
|
34
|
+
ruby-2-7:
|
35
|
+
image: ruby:2.6
|
36
|
+
extends: .rspec
|
37
|
+
stage: test
|
38
|
+
|
39
|
+
ruby-latest:
|
40
|
+
image: ruby:latest
|
41
|
+
extends: .rspec
|
42
|
+
stage: test
|
43
|
+
|
44
|
+
jruby-9:
|
45
|
+
image: jruby:9-alpine
|
46
|
+
extends: .jruby
|
47
|
+
stage: test
|
data/.travis.yml
CHANGED
@@ -4,12 +4,14 @@ script: "bundle exec rspec spec"
|
|
4
4
|
sudo: false
|
5
5
|
cache: bundler
|
6
6
|
rvm:
|
7
|
-
- 2.
|
8
|
-
- 2.
|
9
|
-
- 2.
|
10
|
-
-
|
11
|
-
-
|
7
|
+
- 2.2
|
8
|
+
- 2.3
|
9
|
+
- 2.4
|
10
|
+
- ruby-head
|
11
|
+
- jruby-9.1.9.0
|
12
|
+
- jruby-head
|
12
13
|
matrix:
|
13
14
|
allow_failures:
|
14
|
-
- rvm: jruby-9.
|
15
|
-
- rvm:
|
15
|
+
- rvm: jruby-9.1.9.0
|
16
|
+
- rvm: jruby-head
|
17
|
+
- rvm: ruby-head
|
data/CHANGES.md
CHANGED
@@ -1,16 +1,35 @@
|
|
1
|
-
|
1
|
+
1.1.1
|
2
2
|
----
|
3
|
-
-
|
4
|
-
|
5
|
-
- Uses `#query` to find unregistered predicates, avoiding iterating through
|
6
|
-
all statements.
|
7
|
-
- Uses a transaction to batch commit changes when calling `#set_subject!`
|
8
|
-
- Removes the `deprecation` gem as a runtime dependency
|
3
|
+
- Major performance improvements due to a minor change in how
|
4
|
+
properties are resolved.
|
9
5
|
|
10
|
-
|
6
|
+
1.1.0
|
11
7
|
----
|
12
|
-
-
|
13
|
-
|
8
|
+
- Add support for RDF.rb 3.0
|
9
|
+
|
10
|
+
1.0.0
|
11
|
+
----
|
12
|
+
- Finalize 1.0.0 APIs
|
13
|
+
|
14
|
+
0.11.0
|
15
|
+
----
|
16
|
+
- Reworks ParentStrategy to use an Transaction over a well defined
|
17
|
+
"extended bounded description".
|
18
|
+
- Converts Relation to an Enumerable for more efficient access to
|
19
|
+
property values.
|
20
|
+
- Cleans up .Relation equality and added `#|` & `#&` for Set style
|
21
|
+
comparison.
|
22
|
+
- Deprecates `Relation#first_or_create`.
|
23
|
+
- Removes dependency on the `linkeddata` gem. Users should require
|
24
|
+
individual RDF libraries as needed.
|
25
|
+
- Adds inheritance of configured types when subclassing an
|
26
|
+
`RDFSource`.
|
27
|
+
- Uses `URI#intern` to avoid repeated allocations of common URIs.
|
28
|
+
- Changes handling of language and datatyped Literals in
|
29
|
+
`Relation#each` & `#to_a`;
|
30
|
+
- now returns `RDF::Literal` for lanugage tagged strings and
|
31
|
+
for unknown datatypes.
|
32
|
+
|
14
33
|
0.10.0
|
15
34
|
----
|
16
35
|
- Fix Identifiable for ActiveFedora [Trey Pendragon]
|
@@ -104,12 +123,12 @@
|
|
104
123
|
|
105
124
|
0.8.0
|
106
125
|
-----
|
107
|
-
- Adds RDF.rb interfaces to `RDFSource`, improving interoperability
|
126
|
+
- Adds RDF.rb interfaces to `RDFSource`, improving interoperability
|
108
127
|
with other `ruby-rdf` packages.
|
109
|
-
- Introduces a defined `Persistable` interface and
|
128
|
+
- Introduces a defined `Persistable` interface and
|
110
129
|
`PersistenceStrategies`.
|
111
130
|
- Changes `Relation`'s delete methods to remove all values, instead of
|
112
|
-
trying to maintain a predicate -> class pair on the property
|
131
|
+
trying to maintain a predicate -> class pair on the property
|
113
132
|
definitions in some cases. The previous functionality was unclear and
|
114
133
|
unreliable.
|
115
134
|
- Adds a `Schema` concept, for defining property definitions that are
|
data/Gemfile
CHANGED
@@ -2,5 +2,12 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'activesupport', '< 5.0.0' if RUBY_VERSION =~ /2\.1\..*/
|
6
5
|
gem 'pry-byebug' unless ENV["CI"]
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem 'rdf-spec', github: 'ruby-rdf/rdf-spec', branch: 'develop'
|
9
|
+
gem 'simplecov', require: false
|
10
|
+
end
|
11
|
+
|
12
|
+
Encoding.default_external = Encoding::UTF_8
|
13
|
+
Encoding.default_internal = Encoding::UTF_8
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Description
|
2
2
|
-----------
|
3
3
|
|
4
|
-
[![
|
5
|
-
[![Coverage
|
4
|
+
[![Pipeline Status](https://gitlab.com/no_reply/ActiveTriples/badges/develop/pipeline.svg)](https://gitlab.com/no_reply/ActiveTriples/commits/develop)
|
5
|
+
[![Coverage Report](https://gitlab.com/no_reply/ActiveTriples/badges/develop/coverage.svg)](https://gitlab.com/no_reply/ActiveTriples/commits/develop)
|
6
6
|
[![Gem Version](https://badge.fury.io/rb/active-triples.svg)](http://badge.fury.io/rb/active-triples)
|
7
7
|
|
8
8
|
An ActiveModel-like interface for RDF data. Models graphs as RDFSources with property/attribute configuration, accessors, and other methods to support Linked Data in a Ruby/Rails enviornment. See [RDF Concepts and Abstract Syntax](http://www.w3.org/TR/2014/REC-rdf11-concepts-20140225/#change-over-time) for an informal definition of an RDF Source.
|
@@ -23,36 +23,47 @@ The core module of `ActiveTriples` is `ActiveTriples::RDFSource`. You can use th
|
|
23
23
|
|
24
24
|
|
25
25
|
```ruby
|
26
|
+
require 'rdf/vocab'
|
27
|
+
|
26
28
|
class Thing
|
27
29
|
include ActiveTriples::RDFSource
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
|
31
|
+
configure type: RDF::OWL.Thing, base_uri: 'http://example.org/things#'
|
32
|
+
|
33
|
+
property :title, predicate: RDF::Vocab::DC.title
|
34
|
+
property :description, predicate: RDF::Vocab::DC.description
|
31
35
|
end
|
32
36
|
|
33
|
-
obj
|
34
|
-
obj.title
|
37
|
+
obj = Thing.new('123')
|
38
|
+
obj.title = 'Resource'
|
35
39
|
obj.description = 'A resource.'
|
40
|
+
|
36
41
|
obj.dump :ntriples # => "<http://example.org/things#123> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .\n<http://example.org/things#123> <http://purl.org/dc/terms/title> \"Resource\" .\n<http://example.org/things#123> <http://purl.org/dc/terms/description> \"A resource.\" .\n"
|
37
42
|
```
|
43
|
+
|
38
44
|
URI and bnode values are built out as generic Resources when accessed. A more specific model class can be configured on individual properties.
|
39
45
|
|
40
46
|
```ruby
|
41
|
-
Thing.property :creator, :
|
47
|
+
Thing.property :creator, predicate: RDF::Vocab::DC.creator, class_name: 'Person'
|
42
48
|
|
43
49
|
class Person
|
44
50
|
include ActiveTriples::RDFSource
|
45
|
-
|
46
|
-
|
51
|
+
|
52
|
+
configure type: RDF::Vocab::FOAF.Person,
|
53
|
+
base_uri: 'http://example.org/people#'
|
54
|
+
|
55
|
+
property :name, predicate: RDF::Vocab::FOAF.name
|
47
56
|
end
|
48
57
|
|
49
|
-
obj_2
|
58
|
+
obj_2 = Thing.new('2')
|
50
59
|
obj_2.creator = Person.new
|
60
|
+
|
51
61
|
obj_2.creator
|
52
62
|
# => [#<Person:0x3fbe84ac9234(default)>]
|
53
63
|
|
54
64
|
obj_2.creator.first.name = 'Herman Melville'
|
55
|
-
|
65
|
+
|
66
|
+
obj_2.dump :ntriples # => "_:g47361345336040 <http://xmlns.com/foaf/0.1/name> \"Herman Melville\" .\n_:g47361345336040 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .\n<http://example.org/things#2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .\n<http://example.org/things#2> <http://purl.org/dc/terms/creator> _:g47361345336040 .\n"
|
56
67
|
```
|
57
68
|
|
58
69
|
Open Model
|
@@ -63,23 +74,33 @@ An RDFSource lets you handle data as a graph, independent of whether it is defin
|
|
63
74
|
```ruby
|
64
75
|
related = Thing.new
|
65
76
|
|
66
|
-
related << RDF::Statement(related, RDF::DC.relation, obj)
|
67
|
-
related << RDF::Statement(related, RDF::DC.subject, 'ActiveTriples')
|
77
|
+
related << RDF::Statement(related, RDF::Vocab::DC.relation, obj)
|
78
|
+
related << RDF::Statement(related, RDF::Vocab::DC.subject, 'ActiveTriples')
|
68
79
|
|
69
|
-
related.query(:
|
70
|
-
|
71
|
-
|
80
|
+
related.query(subject: related,
|
81
|
+
predicate: RDF::Vocab::DC.relation).each_statement do |s,p,o|
|
82
|
+
puts o
|
83
|
+
end
|
72
84
|
# => http://example.org/things#123
|
85
|
+
|
86
|
+
related.query(subject: related,
|
87
|
+
predicate: RDF::Vocab::DC.subject).each_statement do |s,p,o|
|
88
|
+
puts o
|
89
|
+
end
|
90
|
+
# => 'ActiveTriples'
|
73
91
|
```
|
74
92
|
|
75
93
|
Any operation you can run against an RDF::Graph works with RDFSources, too. Or you can use generic setters and getters with URI predicates:
|
76
94
|
|
77
95
|
```ruby
|
78
|
-
related.set_value(RDF::DC.relation, obj)
|
79
|
-
related.set_value(RDF::DC.subject,
|
96
|
+
related.set_value(RDF::Vocab::DC.relation, obj)
|
97
|
+
related.set_value(RDF::Vocab::DC.subject, 'ActiveTriples')
|
98
|
+
|
99
|
+
related.get_values(RDF::Vocab::DC.relation)
|
100
|
+
# => [#<Thing:0x3f949c6a2294(default)>]
|
80
101
|
|
81
|
-
related.get_values(RDF::DC.
|
82
|
-
|
102
|
+
related.get_values(RDF::Vocab::DC.subject)
|
103
|
+
# => ["ActiveTriples"]
|
83
104
|
```
|
84
105
|
|
85
106
|
Some convienience methods provide support for handling data from web sources:
|
@@ -89,10 +110,13 @@ Some convienience methods provide support for handling data from web sources:
|
|
89
110
|
```ruby
|
90
111
|
require 'linkeddata' # to support various serializations
|
91
112
|
|
92
|
-
|
113
|
+
uri = 'http://dbpedia.org/resource/Oregon_State_University'
|
114
|
+
|
115
|
+
osu = ActiveTriples::Resource.new uri
|
93
116
|
osu.fetch
|
94
117
|
|
95
|
-
osu.rdf_label
|
118
|
+
osu.rdf_label
|
119
|
+
# => ["Oregon State University", "Oregon State University", "Université d'État de l'Oregon", "Oregon State University", "Oregon State University", "オレゴン州立大学", "Universidad Estatal de Oregón", "Oregon State University", "俄勒岡州立大學", "Universidade do Estado do Oregon"]
|
96
120
|
```
|
97
121
|
|
98
122
|
Typed Data
|
@@ -101,9 +125,9 @@ Typed Data
|
|
101
125
|
Typed literals are handled natively through Ruby types and [RDF::Literal](https://github.com/ruby-rdf/rdf/tree/develop/lib/rdf/model/literal). There is no need to register a specific type for a property, simply pass the setter the appropriate typed data. See the examples in the RDF::Literal documentation for futher information about supported datatypes.
|
102
126
|
|
103
127
|
```ruby
|
104
|
-
Thing.property :date, :
|
128
|
+
Thing.property :date, predicate: RDF::Vocab::DC.date
|
105
129
|
|
106
|
-
my_thing
|
130
|
+
my_thing = Thing.new
|
107
131
|
my_thing.date = Date.today
|
108
132
|
|
109
133
|
puts my_thing.dump :ntriples
|
@@ -143,38 +167,47 @@ Resources can persist to various databases and triplestores though integration w
|
|
143
167
|
# RDF::Repository support persistence to (e.g.) triplestores & NoSQL
|
144
168
|
# databases.
|
145
169
|
ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
|
146
|
-
ActiveTriples::Repositories.add_repository :people,
|
170
|
+
ActiveTriples::Repositories.add_repository :people, RDF::Repository.new
|
147
171
|
|
148
172
|
class Person
|
149
173
|
include ActiveTriples::RDFSource
|
150
|
-
|
151
|
-
|
174
|
+
|
175
|
+
configure type: RDF::Vocab::FOAF.Person,
|
176
|
+
base_uri: 'http://example.org/people#',
|
177
|
+
repository: :people
|
178
|
+
property :name, predicate: RDF::Vocab::FOAF.name
|
152
179
|
end
|
153
180
|
|
154
181
|
class Thing
|
155
182
|
include ActiveTriples::RDFSource
|
156
183
|
|
157
|
-
configure :
|
158
|
-
|
159
|
-
|
160
|
-
|
184
|
+
configure type: RDF::OWL.Thing,
|
185
|
+
base_uri: 'http://example.org/things#',
|
186
|
+
repository: :default
|
187
|
+
|
188
|
+
property :title, predicate: RDF::Vocab::DC.title
|
189
|
+
property :description, predicate: RDF::Vocab::DC.description
|
190
|
+
property :creator, predicate: RDF::Vocab::DC.creator, class_name: 'Person'
|
161
191
|
end
|
162
192
|
|
163
|
-
t
|
164
|
-
t.title
|
193
|
+
t = Thing.new('1')
|
194
|
+
t.title = 'A Thing'
|
165
195
|
t.creator = Person.new('1')
|
196
|
+
|
166
197
|
t.persisted? # => false
|
167
|
-
t.creator.first.name = 'Tove'
|
168
|
-
t.persist!
|
169
198
|
|
170
199
|
ActiveTriples::Repositories.repositories[:default].dump :ntriples
|
171
|
-
# => "
|
200
|
+
# => ""
|
172
201
|
|
173
|
-
t.creator.first.
|
174
|
-
t.
|
202
|
+
t.creator.first.name = 'Tove'
|
203
|
+
t.persist!
|
175
204
|
|
176
|
-
ActiveTriples::Repositories.repositories[:
|
177
|
-
#
|
205
|
+
puts ActiveTriples::Repositories.repositories[:default].dump :ntriples
|
206
|
+
# <http://example.org/things#1> <http://purl.org/dc/terms/title> "A Thing" .
|
207
|
+
# <http://example.org/things#1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
|
208
|
+
# <http://example.org/things#1> <http://purl.org/dc/terms/creator> <http://example.org/people#1> .
|
209
|
+
# <http://example.org/people#1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
|
210
|
+
# <http://example.org/people#1> <http://xmlns.com/foaf/0.1/name> "Tove" .
|
178
211
|
```
|
179
212
|
|
180
213
|
Contributing
|
@@ -182,7 +215,7 @@ Contributing
|
|
182
215
|
|
183
216
|
Please observe the following guidelines:
|
184
217
|
|
185
|
-
- Do your work in a feature branch based on ```
|
218
|
+
- Do your work in a feature branch based on ```develop``` and rebase before submitting a pull request.
|
186
219
|
- Write tests for your contributions.
|
187
220
|
- Document every method you add using YARD annotations. (_Note: Annotations are sparse in the existing codebase, help us fix that!_)
|
188
221
|
- Organize your commits into logical units.
|
data/active-triples.gemspec
CHANGED
@@ -7,27 +7,28 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = ActiveTriples::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Tom Johnson", "Trey Terrell"]
|
10
|
-
s.homepage = 'https://
|
11
|
-
s.email = 'tom@
|
10
|
+
s.homepage = 'https://gitlab.com/no_reply/ActiveTriples'
|
11
|
+
s.email = 'tom@curationexperts.com'
|
12
12
|
s.summary = %q{RDF graphs in ActiveModel wrappers.}
|
13
13
|
s.description = %q{ActiveTriples provides tools for modeling RDF as discrete resources.}
|
14
|
-
s.license =
|
14
|
+
s.license = 'Apache-2.0'
|
15
15
|
s.required_ruby_version = '>= 2.1.0'
|
16
16
|
|
17
|
-
s.add_dependency 'rdf', '
|
18
|
-
s.add_dependency 'rdf-vocab'
|
17
|
+
s.add_dependency 'rdf', '>= 2.0.2', '< 4.0'
|
18
|
+
s.add_dependency 'rdf-vocab', '>= 2.0', '< 4.0'
|
19
19
|
s.add_dependency 'activemodel', '>= 3.0.0'
|
20
20
|
s.add_dependency 'activesupport', '>= 3.0.0'
|
21
21
|
|
22
|
-
s.add_development_dependency '
|
23
|
-
s.add_development_dependency 'rspec'
|
24
|
-
s.add_development_dependency '
|
25
|
-
s.add_development_dependency 'rdf-
|
26
|
-
s.add_development_dependency 'rdf-
|
27
|
-
s.add_development_dependency '
|
28
|
-
s.add_development_dependency '
|
29
|
-
s.add_development_dependency '
|
30
|
-
s.add_development_dependency '
|
22
|
+
s.add_development_dependency 'yard', '~> 0.9'
|
23
|
+
s.add_development_dependency 'rspec', '~> 3.6'
|
24
|
+
s.add_development_dependency 'guard-rspec', '~> 4.7'
|
25
|
+
s.add_development_dependency 'rdf-spec', '~> 3.0'
|
26
|
+
s.add_development_dependency 'rdf-rdfxml', '>= 2.0', '< 4.0'
|
27
|
+
s.add_development_dependency 'rdf-turtle', '>= 2.0', '< 4.0'
|
28
|
+
s.add_development_dependency 'json-ld', '>= 2.0', '< 4.0'
|
29
|
+
s.add_development_dependency 'coveralls', '~> 0.8'
|
30
|
+
s.add_development_dependency 'webmock', '~> 3.0'
|
31
|
+
s.add_development_dependency 'nokogiri', '~> 1.8'
|
31
32
|
s.add_development_dependency 'pragmatic_context', '~> 0.1.2'
|
32
33
|
|
33
34
|
s.files = `git ls-files`.split("\n")
|
@@ -14,6 +14,11 @@ module ActiveTriples
|
|
14
14
|
#
|
15
15
|
# Available properties are base_uri, rdf_label, type, and repository
|
16
16
|
module Configurable
|
17
|
+
def inherited(child_class)
|
18
|
+
child_class.configure type: self.type
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
17
22
|
def base_uri
|
18
23
|
configuration[:base_uri]
|
19
24
|
end
|
@@ -62,7 +67,7 @@ module ActiveTriples
|
|
62
67
|
|
63
68
|
def transform_type(values)
|
64
69
|
Array.wrap(values).map do |value|
|
65
|
-
RDF::URI.
|
70
|
+
RDF::URI.intern(value).tap do |uri|
|
66
71
|
RDFSource.type_registry[uri] = self
|
67
72
|
end
|
68
73
|
end
|
@@ -3,15 +3,21 @@ module ActiveTriples
|
|
3
3
|
require_relative 'configuration/item'
|
4
4
|
require_relative 'configuration/merge_item'
|
5
5
|
require_relative 'configuration/item_factory'
|
6
|
+
|
6
7
|
##
|
7
8
|
# Class which contains configuration for RDFSources.
|
8
9
|
class Configuration
|
9
10
|
attr_accessor :inner_hash
|
11
|
+
|
12
|
+
##
|
13
|
+
# @param item_factory [ItemFactory]
|
10
14
|
# @param [Hash] options the configuration options.
|
11
|
-
def initialize(options
|
12
|
-
@
|
15
|
+
def initialize(item_factory: ItemFactory.new, **options)
|
16
|
+
@item_factory = item_factory
|
17
|
+
@inner_hash = Hash[options.to_a]
|
13
18
|
end
|
14
19
|
|
20
|
+
##
|
15
21
|
# Merges this configuration with other configuration options. This uses
|
16
22
|
# reflection setters to handle special cases like :type.
|
17
23
|
#
|
@@ -19,13 +25,17 @@ module ActiveTriples
|
|
19
25
|
# @return [ActiveTriples::Configuration] the configuration object which is a
|
20
26
|
# result of merging.
|
21
27
|
def merge(options)
|
22
|
-
|
28
|
+
options = options.to_h
|
29
|
+
new_config = self.class.new(**options)
|
30
|
+
|
23
31
|
new_config.items.each do |property, item|
|
24
32
|
build_configuration_item(property).set item.value
|
25
33
|
end
|
34
|
+
|
26
35
|
self
|
27
36
|
end
|
28
37
|
|
38
|
+
##
|
29
39
|
# Returns a hash with keys as the configuration property and values as
|
30
40
|
# reflections which know how to set a new value to it.
|
31
41
|
#
|
@@ -37,6 +47,7 @@ module ActiveTriples
|
|
37
47
|
end
|
38
48
|
end
|
39
49
|
|
50
|
+
##
|
40
51
|
# Returns the configured value for an option
|
41
52
|
#
|
42
53
|
# @return the configured value
|
@@ -44,30 +55,30 @@ module ActiveTriples
|
|
44
55
|
to_h[value]
|
45
56
|
end
|
46
57
|
|
58
|
+
##
|
47
59
|
# Returns the available configured options as a hash.
|
48
60
|
#
|
49
61
|
# This filters the options the class is initialized with.
|
50
62
|
#
|
51
63
|
# @return [Hash{Symbol => String, ::RDF::URI}]
|
52
64
|
def to_h
|
53
|
-
|
65
|
+
inner_hash.slice(*valid_config_options)
|
54
66
|
end
|
55
67
|
|
56
68
|
protected
|
57
69
|
|
58
70
|
def build_configuration_item(key)
|
59
|
-
|
71
|
+
item_factory.new(self, key)
|
60
72
|
end
|
61
73
|
|
62
74
|
private
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
75
|
+
|
76
|
+
CONFIG_OPTIONS = [:base_uri, :rdf_label, :type, :repository].freeze
|
77
|
+
|
78
|
+
attr_reader :item_factory
|
67
79
|
|
68
80
|
def valid_config_options
|
69
|
-
|
81
|
+
CONFIG_OPTIONS
|
70
82
|
end
|
71
83
|
end
|
72
|
-
|
73
84
|
end
|