rdf 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rdf/changeset.rb +79 -18
- data/lib/rdf/mixin/mutable.rb +3 -13
- data/lib/rdf/mixin/writable.rb +2 -14
- data/lib/rdf/repository.rb +8 -1
- data/lib/rdf/util.rb +6 -5
- data/lib/rdf/util/coercions.rb +60 -0
- data/lib/rdf/vocab/xsd.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f11909f850c5c1de088d0fd736267556ea533ec2f14e7245676e0547ff22f4d8
|
4
|
+
data.tar.gz: 4cf062a4eb81399c761e60210dbb7e87a1b778c8aa46161f6086c3819c3b9b23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb6699ee27aceb7eff73b5b15a685abb3501b1de930ed3b5612662c2303af75239d1b76b3c6a0a721bf79577bfa357acefe71084db89851d2619ede8fcfc44cc
|
7
|
+
data.tar.gz: 94c48695d2c77cb6847a88aecabed96e6b31db07e5b7d3a70f43e54afc5d6910d090e41f26fe74e5acff6733f62c3321a6185336928f64d39bf5d3924d366465
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.1.
|
1
|
+
3.1.1
|
data/lib/rdf/changeset.rb
CHANGED
@@ -31,10 +31,11 @@ module RDF
|
|
31
31
|
#
|
32
32
|
# @since 2.0.0
|
33
33
|
class Changeset
|
34
|
-
include RDF::Mutable
|
34
|
+
# include RDF::Mutable
|
35
|
+
include RDF::Util::Coercions
|
35
36
|
|
36
37
|
##
|
37
|
-
# Applies a changeset to the given
|
38
|
+
# Applies a changeset to the given {RDF::Mutable} object.
|
38
39
|
#
|
39
40
|
# @param [RDF::Mutable] mutable
|
40
41
|
# @param [Hash{Symbol => Object}] options
|
@@ -98,6 +99,24 @@ module RDF
|
|
98
99
|
false
|
99
100
|
end
|
100
101
|
|
102
|
+
##
|
103
|
+
# Returns `false` as changesets are not {RDF::Writable}.
|
104
|
+
#
|
105
|
+
# @return [Boolean]
|
106
|
+
# @see RDF::Writable#writable?
|
107
|
+
def writable?
|
108
|
+
false
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# Returns `false` as changesets are not {RDF::Mutable}.
|
113
|
+
#
|
114
|
+
# @return [Boolean]
|
115
|
+
# @see RDF::Mutable#mutable?
|
116
|
+
def mutable?
|
117
|
+
false
|
118
|
+
end
|
119
|
+
|
101
120
|
##
|
102
121
|
# Applies this changeset to the given mutable RDF::Enumerable.
|
103
122
|
#
|
@@ -127,35 +146,77 @@ module RDF
|
|
127
146
|
|
128
147
|
##
|
129
148
|
# Outputs a developer-friendly representation of this changeset to
|
130
|
-
#
|
149
|
+
# `$stderr`.
|
131
150
|
#
|
132
151
|
# @return [void]
|
133
152
|
def inspect!
|
134
153
|
$stderr.puts(self.inspect)
|
135
154
|
end
|
136
155
|
|
137
|
-
protected
|
138
|
-
|
139
156
|
##
|
140
|
-
#
|
157
|
+
# Returns the sum of both the `inserts` and `deletes` counts.
|
141
158
|
#
|
142
|
-
# @
|
143
|
-
|
144
|
-
|
145
|
-
def insert_statement(statement)
|
146
|
-
self.inserts << statement
|
159
|
+
# @return [Integer]
|
160
|
+
def count
|
161
|
+
inserts.count + deletes.count
|
147
162
|
end
|
148
163
|
|
164
|
+
# Append statements to `inserts`. Statements _should_ be constant
|
165
|
+
# as variable statements will at best be ignored or at worst raise
|
166
|
+
# an error when applied.
|
167
|
+
#
|
168
|
+
# @param statements [Enumerable, RDF::Statement] Some statements
|
169
|
+
# @return [self]
|
170
|
+
def insert(*statements)
|
171
|
+
coerce_statements(statements) do |stmts|
|
172
|
+
append_statements :inserts, stmts
|
173
|
+
end
|
174
|
+
|
175
|
+
self
|
176
|
+
end
|
177
|
+
alias_method :insert!, :insert
|
178
|
+
alias_method :<<, :insert
|
179
|
+
|
180
|
+
# Append statements to `deletes`. Statements _may_ contain
|
181
|
+
# variables, although support will depend on the {RDF::Mutable}
|
182
|
+
# target.
|
183
|
+
#
|
184
|
+
# @param statements [Enumerable, RDF::Statement] Some statements
|
185
|
+
# @return [self]
|
186
|
+
def delete(*statements)
|
187
|
+
coerce_statements(statements) do |stmts|
|
188
|
+
append_statements :deletes, stmts
|
189
|
+
end
|
190
|
+
|
191
|
+
self
|
192
|
+
end
|
193
|
+
alias_method :delete!, :delete
|
194
|
+
alias_method :>>, :delete
|
195
|
+
|
196
|
+
private
|
197
|
+
|
149
198
|
##
|
150
|
-
#
|
199
|
+
# Append statements to the appropriate target. This is a little
|
200
|
+
# shim to go in between the other shim and the target.
|
151
201
|
#
|
152
|
-
# @param
|
153
|
-
# @
|
154
|
-
#
|
155
|
-
def
|
156
|
-
|
202
|
+
# @param target [Symbol] the method to send
|
203
|
+
# @param arg [Enumerable, RDF::Statement]
|
204
|
+
#
|
205
|
+
def append_statements(target, arg)
|
206
|
+
# coerce to an enumerator
|
207
|
+
stmts = case
|
208
|
+
when arg.is_a?(RDF::Statement)
|
209
|
+
[arg]
|
210
|
+
when arg.respond_to?(:each_statement)
|
211
|
+
arg.each_statement
|
212
|
+
when arg.respond_to?(:each)
|
213
|
+
arg
|
214
|
+
else
|
215
|
+
raise ArgumentError, "Invalid statement: #{arg.class}"
|
216
|
+
end
|
217
|
+
|
218
|
+
stmts.each { |s| send(target) << s }
|
157
219
|
end
|
158
220
|
|
159
|
-
undef_method :load, :update, :clear
|
160
221
|
end # Changeset
|
161
222
|
end # RDF
|
data/lib/rdf/mixin/mutable.rb
CHANGED
@@ -9,6 +9,7 @@ module RDF
|
|
9
9
|
extend RDF::Util::Aliasing::LateBound
|
10
10
|
include RDF::Readable
|
11
11
|
include RDF::Writable
|
12
|
+
include RDF::Util::Coercions
|
12
13
|
|
13
14
|
##
|
14
15
|
# Returns `true` if `self` is mutable.
|
@@ -154,20 +155,9 @@ module RDF
|
|
154
155
|
def delete(*statements)
|
155
156
|
raise TypeError.new("#{self} is immutable") if immutable?
|
156
157
|
|
157
|
-
statements
|
158
|
-
|
159
|
-
when value.respond_to?(:each_statement)
|
160
|
-
delete_statements(value)
|
161
|
-
nil
|
162
|
-
when (statement = Statement.from(value)).constant?
|
163
|
-
statement
|
164
|
-
else
|
165
|
-
delete_statements(query(value))
|
166
|
-
nil
|
167
|
-
end
|
158
|
+
coerce_statements(statements, query: true, constant: true) do |value|
|
159
|
+
delete_statements(value)
|
168
160
|
end
|
169
|
-
statements.compact!
|
170
|
-
delete_statements(statements) unless statements.empty?
|
171
161
|
|
172
162
|
return self
|
173
163
|
end
|
data/lib/rdf/mixin/writable.rb
CHANGED
@@ -7,6 +7,7 @@ module RDF
|
|
7
7
|
# @see RDF::Repository
|
8
8
|
module Writable
|
9
9
|
extend RDF::Util::Aliasing::LateBound
|
10
|
+
include RDF::Util::Coercions
|
10
11
|
|
11
12
|
##
|
12
13
|
# Returns `true` if `self` is writable.
|
@@ -58,26 +59,13 @@ module RDF
|
|
58
59
|
# @param [Enumerable<RDF::Statement>] statements
|
59
60
|
# @return [self]
|
60
61
|
def insert(*statements)
|
61
|
-
statements
|
62
|
-
case
|
63
|
-
when value.respond_to?(:each_statement)
|
64
|
-
insert_statements(value)
|
65
|
-
nil
|
66
|
-
when (statement = Statement.from(value))
|
67
|
-
statement
|
68
|
-
else
|
69
|
-
raise ArgumentError.new("not a valid statement: #{value.inspect}")
|
70
|
-
end
|
71
|
-
end
|
72
|
-
statements.compact!
|
73
|
-
insert_statements(statements) unless statements.empty?
|
62
|
+
coerce_statements(statements) { |value| insert_statements value }
|
74
63
|
|
75
64
|
return self
|
76
65
|
end
|
77
66
|
alias_method :insert!, :insert
|
78
67
|
|
79
68
|
protected
|
80
|
-
|
81
69
|
##
|
82
70
|
# Inserts statements from the given RDF reader into the underlying
|
83
71
|
# storage or output stream.
|
data/lib/rdf/repository.rb
CHANGED
@@ -340,7 +340,14 @@ module RDF
|
|
340
340
|
# @see Mutable#apply_changeset
|
341
341
|
def apply_changeset(changeset)
|
342
342
|
data = @data
|
343
|
-
changeset.deletes.each
|
343
|
+
changeset.deletes.each do |del|
|
344
|
+
if del.constant?
|
345
|
+
data = delete_from(data, del)
|
346
|
+
else
|
347
|
+
# we need this condition to handle wildcard statements
|
348
|
+
query_pattern(del) { |stmt| data = delete_from(data, stmt) }
|
349
|
+
end
|
350
|
+
end
|
344
351
|
changeset.inserts.each { |ins| data = insert_to(data, ins) }
|
345
352
|
@data = data
|
346
353
|
end
|
data/lib/rdf/util.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module RDF; module Util
|
2
|
-
autoload :Aliasing,
|
3
|
-
autoload :Cache,
|
4
|
-
autoload :File,
|
5
|
-
autoload :Logger,
|
6
|
-
autoload :UUID,
|
2
|
+
autoload :Aliasing, 'rdf/util/aliasing'
|
3
|
+
autoload :Cache, 'rdf/util/cache'
|
4
|
+
autoload :File, 'rdf/util/file'
|
5
|
+
autoload :Logger, 'rdf/util/logger'
|
6
|
+
autoload :UUID, 'rdf/util/uuid'
|
7
|
+
autoload :Coercions, 'rdf/util/coercions'
|
7
8
|
end; end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module RDF
|
3
|
+
module Util
|
4
|
+
module Coercions
|
5
|
+
# This is a provisional module intended to house input
|
6
|
+
# coercions. Currently the only coercion is a statement
|
7
|
+
# preprocessor that is used in e.g. {RDF::Writable#insert} and
|
8
|
+
# {RDF::Mutable#delete}.
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
##
|
13
|
+
# Coerce an array of arguments into {RDF::Statement}, or
|
14
|
+
# {RDF::Enumerable} and then yield to a block. Note that this
|
15
|
+
# code was amalgamated from that which was sandwiched around
|
16
|
+
# both {RDF::Writable#insert_statements} and
|
17
|
+
# {RDF::Mutable#delete_statements}. The parameters `query` and
|
18
|
+
# `constant` are therefore present to handle the conditions
|
19
|
+
# where the statements contain wildcards and what to do about
|
20
|
+
# them.
|
21
|
+
#
|
22
|
+
# @example
|
23
|
+
# coerce_statements(statements) { |value| do_something(value) }
|
24
|
+
#
|
25
|
+
# @param statements [#map] The arbitrary-ish input to be manipulated
|
26
|
+
# @param query [false, true] Whether to call `query` before the block
|
27
|
+
# (as expected by {Mutable#delete_statements})
|
28
|
+
# @param constant [false, true] Whether to test if the statements
|
29
|
+
# are constant (as expected by {Mutable#delete_statements})
|
30
|
+
# @yield [RDF::Statement, RDF::Enumerable]
|
31
|
+
# @return statements
|
32
|
+
def coerce_statements(statements, query: false, constant: false, &block)
|
33
|
+
raise ArgumentError, 'expecting a block' unless block_given?
|
34
|
+
|
35
|
+
statements = statements.map do |value|
|
36
|
+
case
|
37
|
+
when value.respond_to?(:each_statement)
|
38
|
+
block.call(value)
|
39
|
+
nil
|
40
|
+
when (statement = Statement.from(value)) &&
|
41
|
+
(!constant || statement.constant?)
|
42
|
+
statement
|
43
|
+
when query
|
44
|
+
# XXX note that this only makes sense when the module is include()d
|
45
|
+
block.call(self.query(value))
|
46
|
+
nil
|
47
|
+
else
|
48
|
+
raise ArgumentError, "Not a valid statement: #{value.inspect}"
|
49
|
+
end
|
50
|
+
end.compact
|
51
|
+
|
52
|
+
block.call(statements) unless statements.empty?
|
53
|
+
|
54
|
+
# eh might as well return these
|
55
|
+
statements
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/rdf/vocab/xsd.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arto Bendiken
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-01-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: link_header
|
@@ -80,28 +80,28 @@ dependencies:
|
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: '3.
|
83
|
+
version: '3.1'
|
84
84
|
type: :development
|
85
85
|
prerelease: false
|
86
86
|
version_requirements: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
88
|
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: '3.
|
90
|
+
version: '3.1'
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rdf-xsd
|
93
93
|
requirement: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
95
|
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: '3.
|
97
|
+
version: '3.1'
|
98
98
|
type: :development
|
99
99
|
prerelease: false
|
100
100
|
version_requirements: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
102
|
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: '3.
|
104
|
+
version: '3.1'
|
105
105
|
- !ruby/object:Gem::Dependency
|
106
106
|
name: rest-client
|
107
107
|
requirement: !ruby/object:Gem::Requirement
|
@@ -267,6 +267,7 @@ files:
|
|
267
267
|
- lib/rdf/util.rb
|
268
268
|
- lib/rdf/util/aliasing.rb
|
269
269
|
- lib/rdf/util/cache.rb
|
270
|
+
- lib/rdf/util/coercions.rb
|
270
271
|
- lib/rdf/util/file.rb
|
271
272
|
- lib/rdf/util/logger.rb
|
272
273
|
- lib/rdf/util/uuid.rb
|
@@ -302,7 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
302
303
|
- !ruby/object:Gem::Version
|
303
304
|
version: '0'
|
304
305
|
requirements: []
|
305
|
-
rubygems_version: 3.
|
306
|
+
rubygems_version: 3.1.1
|
306
307
|
signing_key:
|
307
308
|
specification_version: 4
|
308
309
|
summary: A Ruby library for working with Resource Description Framework (RDF) data.
|