spira 2.1.0 → 3.2.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 +5 -5
- data/README.md +46 -31
- data/UNLICENSE +1 -1
- data/VERSION +1 -1
- data/lib/spira/base.rb +25 -19
- data/lib/spira/persistence.rb +16 -16
- data/lib/spira/resource.rb +7 -7
- data/lib/spira/type.rb +3 -3
- data/lib/spira/types/any.rb +1 -1
- data/lib/spira/types/anyURI.rb +3 -3
- data/lib/spira/types/boolean.rb +3 -3
- data/lib/spira/types/date.rb +3 -3
- data/lib/spira/types/dateTime.rb +3 -3
- data/lib/spira/types/decimal.rb +2 -2
- data/lib/spira/types/double.rb +2 -2
- data/lib/spira/types/float.rb +2 -2
- data/lib/spira/types/gYear.rb +3 -3
- data/lib/spira/types/int.rb +3 -3
- data/lib/spira/types/integer.rb +2 -2
- data/lib/spira/types/long.rb +3 -3
- data/lib/spira/types/negativeInteger.rb +3 -3
- data/lib/spira/types/nonNegativeInteger.rb +3 -3
- data/lib/spira/types/nonPositiveInteger.rb +3 -3
- data/lib/spira/types/positiveInteger.rb +3 -3
- data/lib/spira/types/string.rb +1 -1
- data/lib/spira/types/time.rb +3 -3
- data/lib/spira/types/uri.rb +1 -1
- data/lib/spira/utils.rb +2 -2
- data/lib/spira/validations/uniqueness.rb +1 -1
- data/lib/spira/validations.rb +3 -3
- data/lib/spira.rb +6 -4
- metadata +46 -35
- data/CHANGES.md +0 -118
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 97fddc3a248df0d23723ea8967034dab05e28d23ccced070f1e87b910896adcf
|
4
|
+
data.tar.gz: e0828af26e91756329cbf511785d005dc528d0971683f992547fe2dde76f03cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c146fef9d47e59add48611de4e460c290f60a410efbefeadf9f64e76e5b56be97a3d5ad1257640c657dcbfe805035edd435f697651f037214971faebc41c139
|
7
|
+
data.tar.gz: 5c69eca5680a622992a4bd7ab0647b6308fe2daaf5c9c651cd14207f870c4d79efcc227768cc974dde9e04f859a33cc1240dafba694eed7dc45b241ba67f5f97
|
data/README.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
# Spira
|
1
|
+
# Spira
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/spira)
|
4
|
+
[](https://github.com/ruby-rdf/spira/actions?query=workflow%3ACI)
|
5
|
+
[](https://coveralls.io/r/ruby-rdf/spira)
|
6
|
+
[](https://codeclimate.com/github/ruby-rdf/spira)
|
2
7
|
|
3
8
|
It's time to breathe life into your linked data.
|
4
9
|
|
@@ -13,19 +18,18 @@ losing access to statement-oriented nature of linked data, if you so choose.
|
|
13
18
|
It can be used either to access existing RDF data in a resource-oriented way,
|
14
19
|
or to create a new store of RDF data based on simple defaults.
|
15
20
|
|
16
|
-
An introductory blog post is at <http://blog.datagraph.org/2010/05/spira>
|
17
|
-
|
18
|
-
A changelog is available in the {file:CHANGES.md} file.
|
19
|
-
|
20
21
|
### Example
|
21
22
|
|
22
23
|
```ruby
|
24
|
+
require 'spira'
|
25
|
+
require 'rdf/vocab'
|
26
|
+
|
23
27
|
class Person < Spira::Base
|
24
28
|
|
25
|
-
configure :
|
29
|
+
configure base_uri: "http://example.org/example/people"
|
26
30
|
|
27
|
-
property :name, :
|
28
|
-
property :age, :
|
31
|
+
property :name, predicate: RDF::Vocab::FOAF.name, type: String
|
32
|
+
property :age, predicate: RDF::Vocab::FOAF.age, type: Integer
|
29
33
|
|
30
34
|
end
|
31
35
|
|
@@ -100,7 +104,7 @@ The easiest way to work with Spira is to install it via Rubygems:
|
|
100
104
|
|
101
105
|
$ sudo gem install spira
|
102
106
|
|
103
|
-
Downloads will be available on the github project page
|
107
|
+
Downloads will be available on the github project page.
|
104
108
|
|
105
109
|
## Defining Model Classes
|
106
110
|
|
@@ -110,17 +114,18 @@ without the `RDF::` prefix. For example:
|
|
110
114
|
|
111
115
|
```ruby
|
112
116
|
require 'spira'
|
117
|
+
require 'rdf/vocab'
|
113
118
|
|
114
119
|
class CD < Spira::Base
|
115
|
-
configure :
|
116
|
-
property :name, :
|
117
|
-
property :artist, :
|
120
|
+
configure base_uri: 'http://example.org/cds'
|
121
|
+
property :name, predicate: RDF::Vocab::DC.title, type: XSD.string
|
122
|
+
property :artist, predicate: RDF::URI.new('http://example.org/vocab/artist'), type: :artist
|
118
123
|
end
|
119
124
|
|
120
125
|
class Artist < Spira::Base
|
121
|
-
configure :
|
122
|
-
property :name, :
|
123
|
-
has_many :cds, :
|
126
|
+
configure base_uri: 'http://example.org/artists'
|
127
|
+
property :name, predicate: RDF::Vocab::DC.title, type: XSD.string
|
128
|
+
has_many :cds, predicate: RDF::URI.new('http://example.org/vocab/published_cd'), type: XSD.string
|
124
129
|
end
|
125
130
|
```
|
126
131
|
|
@@ -210,15 +215,18 @@ CD.for RDF::URI.new('http://example.org/cds/queens-greatest-hits')
|
|
210
215
|
A class with a `type` set is assigned an `RDF.type` on creation and saving.
|
211
216
|
|
212
217
|
```ruby
|
218
|
+
require 'spira'
|
219
|
+
require 'rdf/vocab'
|
220
|
+
|
213
221
|
class Album < Spira::Base
|
214
|
-
type URI.new('http://example.org/types/album')
|
215
|
-
property :name, :
|
222
|
+
type RDF::URI.new('http://example.org/types/album')
|
223
|
+
property :name, predicate: RDF::Vocab::DC.title
|
216
224
|
end
|
217
225
|
|
218
226
|
Spira.repository = RDF::Repository.new
|
219
227
|
|
220
228
|
rolling_stones = Album.for RDF::URI.new('http://example.org/cds/rolling-stones-hits')
|
221
|
-
# See RDF.rb at
|
229
|
+
# See RDF.rb at https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Enumerable.html for more information about #has_predicate?
|
222
230
|
rolling_stones.has_predicate?(RDF.type) #=> true
|
223
231
|
Album.type #=> RDF::URI('http://example.org/types/album')
|
224
232
|
```
|
@@ -263,10 +271,10 @@ A class with a `default_vocabulary` set will transparently create predicates for
|
|
263
271
|
|
264
272
|
```ruby
|
265
273
|
class Song < Spira::Base
|
266
|
-
configure :
|
267
|
-
:
|
274
|
+
configure default_vocabulary: RDF::URI.new('http://example.org/vocab'),
|
275
|
+
base_uri: 'http://example.org/songs'
|
268
276
|
property :title
|
269
|
-
property :author, :
|
277
|
+
property :author, type: :artist
|
270
278
|
end
|
271
279
|
|
272
280
|
Spira.repository = RDF::Repository.new
|
@@ -288,8 +296,8 @@ will always return a list, including an empty list for no value. All options
|
|
288
296
|
for `property` work for `has_many`.
|
289
297
|
|
290
298
|
```ruby
|
291
|
-
property :artist, :
|
292
|
-
has_many :cds, :
|
299
|
+
property :artist, type: :artist #=> cd.artist returns a single value
|
300
|
+
has_many :cds, type: :cd #=> artist.cds returns an array
|
293
301
|
```
|
294
302
|
|
295
303
|
Property always takes a symbol name as a name, and a variable list of options. The supported options are:
|
@@ -308,7 +316,7 @@ properties having a single item, ie defined with `property`.
|
|
308
316
|
|
309
317
|
```ruby
|
310
318
|
class Article < Spira::Base
|
311
|
-
property :label, :
|
319
|
+
property :label, localized: true
|
312
320
|
end
|
313
321
|
|
314
322
|
Spira.repository = RDF::Repository.new
|
@@ -368,8 +376,8 @@ Classes can now use this particular type like so:
|
|
368
376
|
|
369
377
|
```ruby
|
370
378
|
class Test < Spira::Base
|
371
|
-
property :test1, :
|
372
|
-
property :test2, :
|
379
|
+
property :test1, type: Integer
|
380
|
+
property :test2, type: RDF::XSD.integer
|
373
381
|
end
|
374
382
|
```
|
375
383
|
|
@@ -384,7 +392,7 @@ are implemented:
|
|
384
392
|
|
385
393
|
The default type for a Spira property is `Spira::Types::Any`, which uses
|
386
394
|
`RDF::Literal`'s automatic boxing/unboxing of XSD types as best it can.
|
387
|
-
See [`RDF::Literal`](
|
395
|
+
See [`RDF::Literal`](https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Literal.html) for more information.
|
388
396
|
|
389
397
|
You can implement your own types as well. Your class' serialize method should
|
390
398
|
turn an RDF::Value into a ruby object, and vice versa.
|
@@ -404,7 +412,7 @@ module MyModule
|
|
404
412
|
end
|
405
413
|
|
406
414
|
class MyClass < Spira::Base
|
407
|
-
property :property1, :
|
415
|
+
property :property1, type: MyModule::MyType
|
408
416
|
end
|
409
417
|
```
|
410
418
|
|
@@ -467,6 +475,10 @@ All model objects are fully-functional as `RDF::Enumerable`, `RDF::Queryable`,
|
|
467
475
|
and `RDF::Mutable`. This lets you manipulate objects on the RDF statement
|
468
476
|
level. You can also access attributes that are not defined as properties.
|
469
477
|
|
478
|
+
## Documentation
|
479
|
+
|
480
|
+
<https://www.rubydoc.info/github/ruby-rdf/spira>
|
481
|
+
|
470
482
|
## Support
|
471
483
|
|
472
484
|
There are a number of ways to ask for help. In declining order of preference:
|
@@ -493,7 +505,10 @@ This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange develo
|
|
493
505
|
list in the the `README`. Alphabetical order applies.
|
494
506
|
* Do note that in order for us to merge any non-trivial changes (as a rule
|
495
507
|
of thumb, additions larger than about 15 lines of code), we need an
|
496
|
-
explicit [public domain dedication][PDD] on record from you
|
508
|
+
explicit [public domain dedication][PDD] on record from you,
|
509
|
+
which you will be asked to agree to on the first commit to a repo within the organization.
|
510
|
+
Note that the agreement applies to all repos in the [Ruby RDF](https://github.com/ruby-rdf/) organization.
|
497
511
|
|
498
|
-
[public-rdf-ruby w3c mailing list]:
|
499
|
-
[RDF.rb]:
|
512
|
+
[public-rdf-ruby w3c mailing list]: https://lists.w3.org/Archives/Public/public-rdf-ruby/
|
513
|
+
[RDF.rb]: https://rubygems.org/gems/rdf
|
514
|
+
[PDD]: https://unlicense.org/#unlicensing-contributions
|
data/UNLICENSE
CHANGED
@@ -21,4 +21,4 @@ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
21
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
22
|
OTHER DEALINGS IN THE SOFTWARE.
|
23
23
|
|
24
|
-
For more information, please refer to <
|
24
|
+
For more information, please refer to <https:///unlicense.org/>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
3.2.0
|
data/lib/spira/base.rb
CHANGED
@@ -32,8 +32,6 @@ module Spira
|
|
32
32
|
# @return [RDF::URI]
|
33
33
|
attr_reader :subject
|
34
34
|
|
35
|
-
attr_accessor :attributes
|
36
|
-
|
37
35
|
class << self
|
38
36
|
attr_reader :reflections, :properties
|
39
37
|
|
@@ -95,7 +93,7 @@ module Spira
|
|
95
93
|
end
|
96
94
|
|
97
95
|
def instantiate_record(subj)
|
98
|
-
new(:
|
96
|
+
new(_subject: id_for(subj))
|
99
97
|
end
|
100
98
|
|
101
99
|
end # class methods
|
@@ -109,31 +107,40 @@ module Spira
|
|
109
107
|
# Initialize a new Spira::Base instance of this resource class using
|
110
108
|
# a new blank node subject. Accepts a hash of arguments for initial
|
111
109
|
# attributes. To use a URI or existing blank node as a subject, use
|
112
|
-
#
|
110
|
+
# the `.for` method on the subclass instead.
|
111
|
+
#
|
112
|
+
# @example
|
113
|
+
# class Person < Spira::Base; end
|
114
|
+
# bob = Person.for("bob")
|
113
115
|
#
|
114
116
|
# @param [Hash{Symbol => Any}] props Default attributes for this instance
|
115
117
|
# @yield [self] Executes a given block
|
116
118
|
# @yieldparam [self] self The newly created instance
|
117
|
-
# @see Spira
|
119
|
+
# @see Spira::Persistence::ClassMethods#for
|
118
120
|
# @see RDF::URI#as
|
119
121
|
# @see RDF::Node#as
|
120
122
|
def initialize(props = {}, options = {})
|
121
123
|
@subject = props.delete(:_subject) || RDF::Node.new
|
124
|
+
@attrs = {}
|
122
125
|
|
123
|
-
@attributes = {}
|
124
126
|
reload props
|
125
127
|
|
126
128
|
yield self if block_given?
|
127
129
|
end
|
128
130
|
|
131
|
+
# Returns the attributes
|
132
|
+
def attributes
|
133
|
+
@attrs
|
134
|
+
end
|
135
|
+
|
129
136
|
# Freeze the attributes hash such that associations are still accessible, even on destroyed records.
|
130
137
|
def freeze
|
131
|
-
@
|
138
|
+
@attrs.freeze; self
|
132
139
|
end
|
133
140
|
|
134
141
|
# Returns +true+ if the attributes hash has been frozen.
|
135
142
|
def frozen?
|
136
|
-
@
|
143
|
+
@attrs.frozen?
|
137
144
|
end
|
138
145
|
|
139
146
|
##
|
@@ -185,7 +192,7 @@ module Spira
|
|
185
192
|
# an RDF level, and will work across subclasses as long as the attributes
|
186
193
|
# are the same.
|
187
194
|
#
|
188
|
-
# @see
|
195
|
+
# @see https://rubygems.org/gems/rdf-isomorphic/
|
189
196
|
def ==(other)
|
190
197
|
# TODO: define behavior for equality on subclasses.
|
191
198
|
# TODO: should we compare attributes here?
|
@@ -257,7 +264,7 @@ module Spira
|
|
257
264
|
# @param [RDF::Resource] new_subject
|
258
265
|
# @return [Spira::Base] copy
|
259
266
|
def copy(new_subject)
|
260
|
-
self.class.new(
|
267
|
+
self.class.new(@attrs.merge(_subject: new_subject))
|
261
268
|
end
|
262
269
|
|
263
270
|
##
|
@@ -284,20 +291,19 @@ module Spira
|
|
284
291
|
private
|
285
292
|
|
286
293
|
def reset_changes
|
287
|
-
|
288
|
-
@changed_attributes.clear
|
294
|
+
clear_changes_information
|
289
295
|
end
|
290
296
|
|
291
297
|
def write_attribute(name, value)
|
292
298
|
name = name.to_s
|
293
299
|
if self.class.properties[name]
|
294
|
-
if
|
295
|
-
changed_attributes[name] =
|
296
|
-
|
300
|
+
if @attrs[name].is_a?(Promise)
|
301
|
+
changed_attributes[name] = @attrs[name] unless changed_attributes.include?(name)
|
302
|
+
@attrs[name] = value
|
297
303
|
else
|
298
304
|
if value != read_attribute(name)
|
299
305
|
attribute_will_change!(name)
|
300
|
-
|
306
|
+
@attrs[name] = value
|
301
307
|
end
|
302
308
|
end
|
303
309
|
else
|
@@ -309,7 +315,7 @@ module Spira
|
|
309
315
|
# Get the current value for the given attribute
|
310
316
|
#
|
311
317
|
def read_attribute(name)
|
312
|
-
value =
|
318
|
+
value = @attrs[name.to_s]
|
313
319
|
|
314
320
|
refl = self.class.reflections[name]
|
315
321
|
if refl && !value
|
@@ -334,7 +340,7 @@ module Spira
|
|
334
340
|
end
|
335
341
|
|
336
342
|
def serialize_localized_property(value, locale)
|
337
|
-
RDF::Literal.new(value, :
|
343
|
+
RDF::Literal.new(value, language: locale)
|
338
344
|
end
|
339
345
|
|
340
346
|
def unserialize_localized_properties(values, locale)
|
@@ -350,7 +356,7 @@ module Spira
|
|
350
356
|
end
|
351
357
|
|
352
358
|
def serialize_hash_localized_properties(values)
|
353
|
-
values.map { |lang, property| RDF::Literal.new(property, :
|
359
|
+
values.map { |lang, property| RDF::Literal.new(property, language: lang) }
|
354
360
|
end
|
355
361
|
|
356
362
|
# Build a Ruby value from an RDF value.
|
data/lib/spira/persistence.rb
CHANGED
@@ -20,7 +20,7 @@ module Spira
|
|
20
20
|
# @param [Hash] args
|
21
21
|
# args can contain:
|
22
22
|
# :conditions - Hash of properties and values
|
23
|
-
# :limit -
|
23
|
+
# :limit - Integer, limiting the amount of returned records
|
24
24
|
# @return [Spira::Base, Array]
|
25
25
|
def find(scope, *args)
|
26
26
|
case scope
|
@@ -73,7 +73,7 @@ module Spira
|
|
73
73
|
# cannot handle such patterns, we iterate across types "manually"
|
74
74
|
types.each do |tp|
|
75
75
|
break if limit.zero?
|
76
|
-
q = conditions_to_query(conditions.merge(:
|
76
|
+
q = conditions_to_query(conditions.merge(type: tp))
|
77
77
|
repository.query(q) do |solution|
|
78
78
|
break if limit.zero?
|
79
79
|
if offset.zero?
|
@@ -112,24 +112,24 @@ module Spira
|
|
112
112
|
#
|
113
113
|
# ==== Examples
|
114
114
|
# # Create a single new object
|
115
|
-
# User.create(:
|
115
|
+
# User.create(first_name: 'Jamie')
|
116
116
|
#
|
117
117
|
# # Create a single new object using the :admin mass-assignment security role
|
118
|
-
# User.create({ :
|
118
|
+
# User.create({ first_name: 'Jamie', is_admin: true }, as: :admin)
|
119
119
|
#
|
120
120
|
# # Create a single new object bypassing mass-assignment security
|
121
|
-
# User.create({ :
|
121
|
+
# User.create({ first_name: 'Jamie', is_admin: true }, without_protection: true)
|
122
122
|
#
|
123
123
|
# # Create an Array of new objects
|
124
|
-
# User.create([{ :
|
124
|
+
# User.create([{ first_name: 'Jamie' }, { first_name: 'Jeremy' }])
|
125
125
|
#
|
126
126
|
# # Create a single object and pass it into a block to set other attributes.
|
127
|
-
# User.create(:
|
127
|
+
# User.create(first_name: 'Jamie') do |u|
|
128
128
|
# u.is_admin = false
|
129
129
|
# end
|
130
130
|
#
|
131
131
|
# # Creating an Array of new objects using a block, where the block is executed for each object:
|
132
|
-
# User.create([{ :
|
132
|
+
# User.create([{ first_name: 'Jamie' }, { first_name: 'Jeremy' }]) do |u|
|
133
133
|
# u.is_admin = false
|
134
134
|
# end
|
135
135
|
def create(attributes = nil, options = {}, &block)
|
@@ -171,7 +171,7 @@ module Spira
|
|
171
171
|
# @yield [self] Executes a given block and calls `#save!`
|
172
172
|
# @yieldparam [self] self The newly created instance
|
173
173
|
# @return [Spira::Base] The newly created instance
|
174
|
-
# @see
|
174
|
+
# @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/URI.html
|
175
175
|
def for(identifier, attributes = {}, &block)
|
176
176
|
self.project(id_for(identifier), attributes, &block)
|
177
177
|
end
|
@@ -192,7 +192,7 @@ module Spira
|
|
192
192
|
# @param [Hash{Symbol => Any}] attributes Initial attributes
|
193
193
|
# @return [Spira::Base] the newly created instance
|
194
194
|
def project(subject, attributes = {}, &block)
|
195
|
-
new(attributes.merge(:
|
195
|
+
new(attributes.merge(_subject: subject), &block)
|
196
196
|
end
|
197
197
|
|
198
198
|
##
|
@@ -205,7 +205,7 @@ module Spira
|
|
205
205
|
# @param [Any] identifier
|
206
206
|
# @return [RDF::URI, RDF::Node]
|
207
207
|
# @raise [ArgumentError] If this class cannot create an identifier from the given argument
|
208
|
-
# @see
|
208
|
+
# @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/URI.html
|
209
209
|
# @see Spira.base_uri
|
210
210
|
# @see Spira.for
|
211
211
|
def id_for(identifier)
|
@@ -303,10 +303,10 @@ module Spira
|
|
303
303
|
##
|
304
304
|
# Enumerate each RDF statement that makes up this projection. This makes
|
305
305
|
# each instance an `RDF::Enumerable`, with all of the nifty benefits
|
306
|
-
# thereof. See <
|
306
|
+
# thereof. See <https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Enumerable.html> for
|
307
307
|
# information on arguments.
|
308
308
|
#
|
309
|
-
# @see
|
309
|
+
# @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Enumerable.html
|
310
310
|
def each
|
311
311
|
if block_given?
|
312
312
|
self.class.properties.each do |name, property|
|
@@ -333,7 +333,7 @@ module Spira
|
|
333
333
|
##
|
334
334
|
# The number of RDF::Statements this projection has.
|
335
335
|
#
|
336
|
-
# @see
|
336
|
+
# @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Enumerable.html#count
|
337
337
|
def count
|
338
338
|
each.count
|
339
339
|
end
|
@@ -342,7 +342,7 @@ module Spira
|
|
342
342
|
# Update multiple attributes of this repository.
|
343
343
|
#
|
344
344
|
# @example Update multiple attributes
|
345
|
-
# person.update_attributes(:
|
345
|
+
# person.update_attributes(name: 'test', age: 10)
|
346
346
|
# #=> person
|
347
347
|
# person.name
|
348
348
|
# #=> 'test'
|
@@ -366,7 +366,7 @@ module Spira
|
|
366
366
|
# NB: "props" argument is ignored, it is handled in Base
|
367
367
|
#
|
368
368
|
def reload(props = {})
|
369
|
-
sts = self.class.repository.query(:
|
369
|
+
sts = self.class.repository.query({subject: subject})
|
370
370
|
self.class.properties.each do |name, options|
|
371
371
|
name = name.to_s
|
372
372
|
if sts
|
data/lib/spira/resource.rb
CHANGED
@@ -15,8 +15,8 @@ module Spira
|
|
15
15
|
#
|
16
16
|
def configure(options = {})
|
17
17
|
singleton_class.class_eval do
|
18
|
-
{ :
|
19
|
-
:
|
18
|
+
{ base_uri: options[:base_uri],
|
19
|
+
default_vocabulary: options[:default_vocabulary]
|
20
20
|
}.each do |name, value|
|
21
21
|
# redefine reader methods only when required,
|
22
22
|
# otherwise, use the ancestor methods
|
@@ -61,11 +61,11 @@ module Spira
|
|
61
61
|
# represents an RDF predicate.
|
62
62
|
#
|
63
63
|
# @example A simple string property
|
64
|
-
# property :name, :
|
64
|
+
# property :name, predicate: RDF::Vocab::FOAF.name, type: String
|
65
65
|
# @example A property which defaults to {Spira::Types::Any}
|
66
|
-
# property :name, :
|
66
|
+
# property :name, predicate: RDF::Vocab::FOAF.name
|
67
67
|
# @example An integer property
|
68
|
-
# property :age, :
|
68
|
+
# property :age, predicate: RDF::Vocab::FOAF.age, type: Integer
|
69
69
|
# @param [Symbol] name The name of this property
|
70
70
|
# @param [Hash{Symbol => Any}] opts property options
|
71
71
|
# @option opts [RDF::URI] :predicate The RDF predicate which will refer to this property
|
@@ -81,12 +81,12 @@ module Spira
|
|
81
81
|
if opts.delete(:localized)
|
82
82
|
raise 'Only Spira::Types::Any properties can accept the :localized option' unless type_for(opts[:type]) == Spira::Types::Any
|
83
83
|
define_localized_property_methods(name, opts)
|
84
|
-
has_many "#{name}_native", opts.merge(:
|
84
|
+
has_many "#{name}_native", opts.merge(type: Spira::Types::Native)
|
85
85
|
else
|
86
86
|
unset_has_many(name)
|
87
87
|
predicate = predicate_for(opts[:predicate], name)
|
88
88
|
type = type_for(opts[:type])
|
89
|
-
properties[name] = HashWithIndifferentAccess.new(:
|
89
|
+
properties[name] = HashWithIndifferentAccess.new(predicate: predicate, type: type)
|
90
90
|
|
91
91
|
define_attribute_method name
|
92
92
|
define_method "#{name}=" do |arg|
|
data/lib/spira/type.rb
CHANGED
@@ -26,13 +26,13 @@ module Spira
|
|
26
26
|
# Spira by default. It allows either of the following forms to declare an
|
27
27
|
# integer property on a Spira resource:
|
28
28
|
#
|
29
|
-
# property :age, :
|
30
|
-
# property :age, :
|
29
|
+
# property :age, predicate: RDF::Vocab::FOAF.age, type: Integer
|
30
|
+
# property :age, predicate: RDF::Vocab::FOAF.age, type: RDF::XSD.integer
|
31
31
|
#
|
32
32
|
# `Spira::Type`s include the RDF namespace and thus have all of the base RDF
|
33
33
|
# vocabularies available to them without the `RDF::` prefix.
|
34
34
|
#
|
35
|
-
# @see
|
35
|
+
# @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Value.html
|
36
36
|
# @see Spira::Resource
|
37
37
|
module Type
|
38
38
|
|
data/lib/spira/types/any.rb
CHANGED
@@ -6,7 +6,7 @@ module Spira::Types
|
|
6
6
|
# Its behavior is defined as 'What `RDF::Literal` does' for a given value.
|
7
7
|
#
|
8
8
|
# @see Spira::Type
|
9
|
-
# @see
|
9
|
+
# @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Literal.html
|
10
10
|
class Any
|
11
11
|
|
12
12
|
include Spira::Type
|
data/lib/spira/types/anyURI.rb
CHANGED
@@ -8,7 +8,7 @@ module Spira::Types
|
|
8
8
|
# `Spira::Types::AnyURI`, `AnyURI`, or `XSD.anyURI`.
|
9
9
|
#
|
10
10
|
# @see Spira::Type
|
11
|
-
# @see
|
11
|
+
# @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Literal.html
|
12
12
|
class AnyURI
|
13
13
|
|
14
14
|
include Spira::Type
|
@@ -18,10 +18,10 @@ module Spira::Types
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.serialize(value)
|
21
|
-
RDF::Literal.new(value, :
|
21
|
+
RDF::Literal.new(value, datatype: XSD.anyURI)
|
22
22
|
end
|
23
23
|
|
24
|
-
register_alias XSD.anyURI
|
24
|
+
register_alias RDF::XSD.anyURI
|
25
25
|
|
26
26
|
end
|
27
27
|
end
|
data/lib/spira/types/boolean.rb
CHANGED
@@ -8,7 +8,7 @@ module Spira::Types
|
|
8
8
|
# `Spira::Types::Boolean`, `Boolean`, or `XSD.boolean`.
|
9
9
|
#
|
10
10
|
# @see Spira::Type
|
11
|
-
# @see
|
11
|
+
# @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Literal.html
|
12
12
|
class Boolean
|
13
13
|
|
14
14
|
include Spira::Type
|
@@ -19,9 +19,9 @@ module Spira::Types
|
|
19
19
|
|
20
20
|
def self.serialize(value)
|
21
21
|
if value
|
22
|
-
RDF::Literal.new(true, :
|
22
|
+
RDF::Literal.new(true, datatype: RDF::XSD.boolean)
|
23
23
|
else
|
24
|
-
RDF::Literal.new(false, :
|
24
|
+
RDF::Literal.new(false, datatype: RDF::XSD.boolean)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
data/lib/spira/types/date.rb
CHANGED
@@ -8,7 +8,7 @@ module Spira::Types
|
|
8
8
|
# `Spira::Types::Date`, `Date`, or `XSD.date`.
|
9
9
|
#
|
10
10
|
# @see Spira::Type
|
11
|
-
# @see
|
11
|
+
# @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Literal.html
|
12
12
|
class Date
|
13
13
|
include Spira::Type
|
14
14
|
|
@@ -17,10 +17,10 @@ module Spira::Types
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.serialize(value)
|
20
|
-
RDF::Literal.new(value, :
|
20
|
+
RDF::Literal.new(value, datatype: XSD.date)
|
21
21
|
end
|
22
22
|
|
23
|
-
register_alias XSD.date
|
23
|
+
register_alias RDF::XSD.date
|
24
24
|
|
25
25
|
end
|
26
26
|
end
|
data/lib/spira/types/dateTime.rb
CHANGED
@@ -8,7 +8,7 @@ module Spira::Types
|
|
8
8
|
# `Spira::Types::DateTime`, `DateTime`, or `XSD.dateTime`.
|
9
9
|
#
|
10
10
|
# @see Spira::Type
|
11
|
-
# @see
|
11
|
+
# @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Literal.html
|
12
12
|
class DateTime
|
13
13
|
include Spira::Type
|
14
14
|
|
@@ -17,10 +17,10 @@ module Spira::Types
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.serialize(value)
|
20
|
-
RDF::Literal.new(value, :
|
20
|
+
RDF::Literal.new(value, datatype: XSD.dateTime)
|
21
21
|
end
|
22
22
|
|
23
|
-
register_alias XSD.dateTime
|
23
|
+
register_alias RDF::XSD.dateTime
|
24
24
|
|
25
25
|
end
|
26
26
|
end
|
data/lib/spira/types/decimal.rb
CHANGED
@@ -10,7 +10,7 @@ module Spira::Types
|
|
10
10
|
# `Spira::Types::Integer`, `Integer`, or `XSD.integer`.
|
11
11
|
#
|
12
12
|
# @see Spira::Type
|
13
|
-
# @see
|
13
|
+
# @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Literal.html
|
14
14
|
class Decimal
|
15
15
|
include Spira::Type
|
16
16
|
|
@@ -20,7 +20,7 @@ module Spira::Types
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.serialize(value)
|
23
|
-
RDF::Literal.new(value.is_a?(BigDecimal) ? value.to_s('F') : value.to_s, :
|
23
|
+
RDF::Literal.new(value.is_a?(BigDecimal) ? value.to_s('F') : value.to_s, datatype: RDF::XSD.decimal)
|
24
24
|
end
|
25
25
|
|
26
26
|
register_alias RDF::XSD.decimal
|
data/lib/spira/types/double.rb
CHANGED
@@ -8,7 +8,7 @@ module Spira::Types
|
|
8
8
|
# `Spira::Types::Double`, `Double`, or `XSD.double`.
|
9
9
|
#
|
10
10
|
# @see Spira::Type
|
11
|
-
# @see
|
11
|
+
# @see https://www.rubydoc.info/github/ruby-rdf/rdf/RDF/Literal.html
|
12
12
|
class Double
|
13
13
|
|
14
14
|
include Spira::Type
|
@@ -18,7 +18,7 @@ module Spira::Types
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.serialize(value)
|
21
|
-
RDF::Literal.new(value.to_f, :
|
21
|
+
RDF::Literal.new(value.to_f, datatype: RDF::XSD.double)
|
22
22
|
end
|
23
23
|
|
24
24
|
register_alias RDF::XSD.double
|