rdf-serializers 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rdf/serializers/data_type_helper.rb +2 -2
- data/lib/rdf/serializers/lookup_chain.rb +5 -6
- data/lib/rdf/serializers/object_serializer.rb +21 -7
- data/lib/rdf/serializers/renderers.rb +1 -1
- data/lib/rdf/serializers/serialization_core.rb +22 -31
- data/lib/rdf/serializers/version.rb +1 -1
- data/lib/rdf/serializers.rb +11 -4
- metadata +7 -8
- data/lib/rdf/serializers/statements.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d375c9e57bfcdfcaf9bee6372abbf54ea974e1991a34936917e59c1ed67469a8
|
4
|
+
data.tar.gz: 0efed8bc77b7d97301d08ddaf5e5194c6234fd2c203bc1244d0269f06c81becf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6edcec3ce7990cb072e6211ce96452d12dd7c245de15177dffafac781b86e48b3f04e60e01af9853e8523a129cc84210c5e9ed3959a1c192c35184f7379a0f5f
|
7
|
+
data.tar.gz: 807766507554892c53f3dd0c9a3199a9d80b59f8b9c4ddb763b609d57727249f050797dfb55591837ce519b4b31fd3635be96fe14aae48e97dca72e01f997604
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RDF
|
4
4
|
module Serializers
|
5
5
|
module DataTypeHelper
|
6
|
-
def xsd_to_rdf(xsd, value, opts
|
6
|
+
def xsd_to_rdf(xsd, value, **opts) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
7
7
|
klass =
|
8
8
|
case xsd
|
9
9
|
when RDF::XSD[:anyURI]
|
@@ -28,7 +28,7 @@ module RDF
|
|
28
28
|
RDF::Literal
|
29
29
|
end
|
30
30
|
|
31
|
-
klass.new(value, opts)
|
31
|
+
klass.new(value, **opts)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -20,7 +20,7 @@ module RDF
|
|
20
20
|
resource_namespace = namespace_for(resource_class)
|
21
21
|
serializer_name = serializer_from(resource_class)
|
22
22
|
|
23
|
-
"#{resource_namespace}::#{serializer_name}"
|
23
|
+
"#{resource_namespace}::#{serializer_name}" if resource_namespace && serializer_name
|
24
24
|
end
|
25
25
|
|
26
26
|
# Uses the controller namespace of the resource to find the serializer
|
@@ -28,8 +28,7 @@ module RDF
|
|
28
28
|
# Example:
|
29
29
|
# Api::V3::AuthorsController => Api::V3::AuthorSerializer
|
30
30
|
BY_NAMESPACE = lambda do |resource_class, namespace|
|
31
|
-
|
32
|
-
namespace ? "#{namespace}::#{resource_name}Serializer" : nil
|
31
|
+
(namespace && resource_class.name) ? "#{namespace}::#{resource_class_name(resource_class)}Serializer" : nil
|
33
32
|
end
|
34
33
|
|
35
34
|
DEFAULT = [
|
@@ -41,11 +40,11 @@ module RDF
|
|
41
40
|
module_function
|
42
41
|
|
43
42
|
def namespace_for(klass)
|
44
|
-
klass.name
|
43
|
+
klass.name&.deconstantize
|
45
44
|
end
|
46
45
|
|
47
46
|
def resource_class_name(klass)
|
48
|
-
klass.name
|
47
|
+
klass.name&.demodulize
|
49
48
|
end
|
50
49
|
|
51
50
|
def serializer_from_resource_name(name)
|
@@ -54,7 +53,7 @@ module RDF
|
|
54
53
|
|
55
54
|
def serializer_from(klass)
|
56
55
|
name = resource_class_name(klass)
|
57
|
-
serializer_from_resource_name(name)
|
56
|
+
serializer_from_resource_name(name) if name
|
58
57
|
end
|
59
58
|
end
|
60
59
|
end
|
@@ -9,20 +9,25 @@ module RDF
|
|
9
9
|
include FastJsonapi::ObjectSerializer
|
10
10
|
include SerializationCore
|
11
11
|
|
12
|
+
included do
|
13
|
+
class_attribute :_statements
|
14
|
+
self._statements ||= []
|
15
|
+
end
|
16
|
+
|
12
17
|
def dump(*args, **options)
|
13
18
|
case args.first
|
14
19
|
when :hndjson
|
15
20
|
render_hndjson
|
16
21
|
else
|
17
|
-
render_repository(*args, options)
|
22
|
+
render_repository(*args, **options)
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
21
26
|
def triples(*args, **options)
|
22
27
|
if include_named_graphs?(*args)
|
23
|
-
repository.triples(*args, options)
|
28
|
+
repository.triples(*args, **options)
|
24
29
|
else
|
25
|
-
repository.project_graph(nil).triples(*args, options)
|
30
|
+
repository.project_graph(nil).triples(*args, **options)
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
@@ -107,16 +112,16 @@ module RDF
|
|
107
112
|
.join("\n")
|
108
113
|
end
|
109
114
|
|
110
|
-
def render_repository(*args, options)
|
115
|
+
def render_repository(*args, **options)
|
111
116
|
if include_named_graphs?(*args)
|
112
|
-
repository.dump(*args, options)
|
117
|
+
repository.dump(*args, **options)
|
113
118
|
else
|
114
|
-
repository.project_graph(nil).dump(*args, options)
|
119
|
+
repository.project_graph(nil).dump(*args, **options)
|
115
120
|
end
|
116
121
|
end
|
117
122
|
|
118
123
|
def serializable_hextuples
|
119
|
-
if is_collection?(@resource, @is_collection)
|
124
|
+
if self.class.is_collection?(@resource, @is_collection)
|
120
125
|
hextuples_for_collection + meta_hextuples
|
121
126
|
elsif !@resource
|
122
127
|
[]
|
@@ -153,6 +158,11 @@ module RDF
|
|
153
158
|
serializer_for(association_class_name)
|
154
159
|
end
|
155
160
|
|
161
|
+
def inherited(base)
|
162
|
+
super
|
163
|
+
base._statements = _statements.dup
|
164
|
+
end
|
165
|
+
|
156
166
|
def serializer_for(name)
|
157
167
|
associatopm_serializer = association_serializer_for(name)
|
158
168
|
return associatopm_serializer if associatopm_serializer
|
@@ -164,6 +174,10 @@ module RDF
|
|
164
174
|
'Consider specifying the serializer directly through options[:serializer].'
|
165
175
|
end
|
166
176
|
end
|
177
|
+
|
178
|
+
def statements(attribute)
|
179
|
+
self._statements << attribute
|
180
|
+
end
|
167
181
|
end
|
168
182
|
end
|
169
183
|
end
|
@@ -30,7 +30,7 @@ module RDF
|
|
30
30
|
options,
|
31
31
|
respond_to?(:serializer_params, true) ? serializer_params : {}
|
32
32
|
)
|
33
|
-
RDF::Serializers.serializer_for(resource)&.new(resource, serializer_opts)&.dump(symbol, opts)
|
33
|
+
RDF::Serializers.serializer_for(resource)&.new(resource, serializer_opts)&.dump(symbol, **opts)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -80,47 +80,38 @@ module RDF
|
|
80
80
|
|
81
81
|
def get_included_records_hex(record, includes_list, known_included_objects, fieldsets, params = {})
|
82
82
|
return unless includes_list.present?
|
83
|
+
return [] unless relationships_to_serialize
|
83
84
|
|
84
|
-
includes_list
|
85
|
-
items = parse_include_item(include_item)
|
86
|
-
remaining_items = remaining_items(items)
|
85
|
+
includes_list = parse_includes_list(includes_list)
|
87
86
|
|
88
|
-
|
89
|
-
|
87
|
+
includes_list.each_with_object([]) do |include_item, included_records|
|
88
|
+
relationship_item = relationships_to_serialize[include_item.first]
|
90
89
|
|
91
|
-
|
92
|
-
next unless relationship_item.include_relationship?(record, params)
|
90
|
+
next unless relationship_item&.include_relationship?(record, params)
|
93
91
|
|
94
|
-
|
92
|
+
included_objects = Array(relationship_item.fetch_associated_object(record, params))
|
93
|
+
next if included_objects.empty?
|
95
94
|
|
96
|
-
|
97
|
-
|
95
|
+
static_serializer = relationship_item.static_serializer
|
96
|
+
static_record_type = relationship_item.static_record_type
|
98
97
|
|
99
|
-
|
98
|
+
included_objects.each do |inc_obj|
|
99
|
+
serializer = static_serializer || relationship_item.serializer_for(inc_obj, params)
|
100
|
+
record_type = static_record_type || serializer.record_type
|
100
101
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
serializer = static_serializer || relationship_item.serializer_for(inc_obj, params)
|
106
|
-
record_type = static_record_type || serializer.record_type
|
107
|
-
|
108
|
-
if remaining_items.present?
|
109
|
-
serializer_records =
|
110
|
-
serializer
|
111
|
-
.get_included_records_hex(inc_obj, remaining_items, known_included_objects, fieldsets, params)
|
112
|
-
included_records.concat(serializer_records) unless serializer_records.empty?
|
113
|
-
end
|
102
|
+
if include_item.last.any?
|
103
|
+
serializer_records = serializer.get_included_records_hex(inc_obj, include_item.last, known_included_objects, fieldsets, params)
|
104
|
+
included_records.concat(serializer_records) unless serializer_records.empty?
|
105
|
+
end
|
114
106
|
|
115
|
-
|
116
|
-
|
107
|
+
code = "#{record_type}_#{serializer.iri_from_record(inc_obj)}"
|
108
|
+
next if known_included_objects.include?(code)
|
117
109
|
|
118
|
-
|
110
|
+
known_included_objects << code
|
119
111
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
end
|
112
|
+
included_records.concat(
|
113
|
+
serializer.record_hextuples(inc_obj, fieldsets[record_type], includes_list, params)
|
114
|
+
)
|
124
115
|
end
|
125
116
|
end
|
126
117
|
end
|
data/lib/rdf/serializers.rb
CHANGED
@@ -4,7 +4,6 @@ require 'fast_jsonapi'
|
|
4
4
|
|
5
5
|
require 'rdf/serializers/lookup_chain'
|
6
6
|
require 'rdf/serializers/config'
|
7
|
-
require 'rdf/serializers/statements'
|
8
7
|
require 'rdf/serializers/hextuple_serializer'
|
9
8
|
require 'rdf/serializers/data_type_helper'
|
10
9
|
require 'rdf/serializers/hdnjson_parser'
|
@@ -58,9 +57,7 @@ module RDF
|
|
58
57
|
serializers_cache.fetch_or_store(cache_key) do
|
59
58
|
# NOTE(beauby): When we drop 1.9.3 support we can lazify the map for perfs.
|
60
59
|
lookup_chain = serializer_lookup_chain_for(klass, namespace)
|
61
|
-
serializer_class = lookup_chain
|
62
|
-
x&.include?(FastJsonapi::SerializationCore)
|
63
|
-
end
|
60
|
+
serializer_class = serializer_class_from_chain(lookup_chain)
|
64
61
|
|
65
62
|
if serializer_class
|
66
63
|
serializer_class
|
@@ -77,6 +74,16 @@ module RDF
|
|
77
74
|
@serializers_cache ||= Concurrent::Map.new
|
78
75
|
end
|
79
76
|
|
77
|
+
def serializer_class_from_chain(lookup_chain)
|
78
|
+
lookup_chain.map do |klass|
|
79
|
+
klass&.safe_constantize
|
80
|
+
rescue LoadError
|
81
|
+
nil
|
82
|
+
end.find do |klass|
|
83
|
+
klass&.include?(FastJsonapi::SerializationCore)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
80
87
|
def serializer_lookup_chain_for(klass, namespace = nil)
|
81
88
|
lookups = config.serializer_lookup_chain
|
82
89
|
Array[*lookups].flat_map do |lookup|
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf-serializers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arthur Dingemans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-serializer
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: oj
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,7 +91,6 @@ files:
|
|
91
91
|
- lib/rdf/serializers/renderers.rb
|
92
92
|
- lib/rdf/serializers/scalar.rb
|
93
93
|
- lib/rdf/serializers/serialization_core.rb
|
94
|
-
- lib/rdf/serializers/statements.rb
|
95
94
|
- lib/rdf/serializers/version.rb
|
96
95
|
homepage: https://github.com/ontola/rdf-serializers
|
97
96
|
licenses:
|
@@ -112,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
111
|
- !ruby/object:Gem::Version
|
113
112
|
version: '0'
|
114
113
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
114
|
+
rubygems_version: 3.2.22
|
116
115
|
signing_key:
|
117
116
|
specification_version: 4
|
118
117
|
summary: Adds RDF serialization, like n-triples or turtle, to active model serializers
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RDF
|
4
|
-
module Serializers
|
5
|
-
module Statements
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
class_attribute :_statements
|
10
|
-
self._statements ||= []
|
11
|
-
end
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
def inherited(base)
|
15
|
-
super
|
16
|
-
base._statements = _statements.dup
|
17
|
-
end
|
18
|
-
|
19
|
-
def statements(attribute)
|
20
|
-
self._statements << attribute
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
FastJsonapi::ObjectSerializer.include(RDF::Serializers::Statements)
|