rdf-serializers 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_model_serializers/adapter/rdf.rb +10 -2
- data/lib/active_model_serializers/serializer.rb +12 -0
- data/lib/{rdf_serializers.rb → rdf/serializers.rb} +1 -0
- data/lib/rdf/serializers/renderers.rb +33 -0
- data/lib/{rdf_serializers → rdf/serializers}/version.rb +1 -1
- metadata +6 -5
- data/lib/rdf_serializers/renderers.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ed97dbe57a341549fb3bf366bebc5b630fcded0
|
4
|
+
data.tar.gz: ca39c6571dba789c392a76085e9548c4fc04bed0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 259012b9e67240543b0423eabd7d7aac3f7281e4269d2513eceba2f0411e6ee501d5ffb756f3c461ece95e940cb7114894ed4bd9f7df8cae34f901b6b581c037
|
7
|
+
data.tar.gz: deb4d015668dfac91cd37f42f20bd1610aa6b92d401b26db10c66405a4ede9730cce50f7102566a6149c5e50d30176f8807627ce78c78d491f52d7875ad8dead
|
@@ -50,6 +50,14 @@ module ActiveModelSerializers
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
def custom_triples_for(serializer)
|
54
|
+
serializer.class.try(:_triples)&.map do |key|
|
55
|
+
serializer.read_attribute_for_serialization(key).each do |triple|
|
56
|
+
@graph << triple
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
53
61
|
def graph
|
54
62
|
return @graph if @graph.present?
|
55
63
|
@graph = ::RDF::Graph.new
|
@@ -66,8 +74,7 @@ module ActiveModelSerializers
|
|
66
74
|
serializer.each { |s| process_relationship(s, include_slice) }
|
67
75
|
return
|
68
76
|
end
|
69
|
-
return unless serializer&.object
|
70
|
-
return unless process_resource(serializer, include_slice)
|
77
|
+
return unless serializer&.object && process_resource(serializer, include_slice)
|
71
78
|
process_relationships(serializer, include_slice)
|
72
79
|
end
|
73
80
|
|
@@ -102,6 +109,7 @@ module ActiveModelSerializers
|
|
102
109
|
break nil if serializer.read_attribute_for_serialization(:iri).nil?
|
103
110
|
requested_fields = fieldset&.fields_for(type)
|
104
111
|
attributes_for(serializer, requested_fields)
|
112
|
+
custom_triples_for(serializer)
|
105
113
|
end
|
106
114
|
requested_associations = fieldset.fields_for(type) || '*'
|
107
115
|
relationships_for(serializer, requested_associations, include_slice)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Registers the N-Triples renderer
|
4
|
+
#
|
5
|
+
# And then in controllers, use `render nt: model`.
|
6
|
+
#
|
7
|
+
# For example, in a controller action, we can:
|
8
|
+
# respond_to do |format|
|
9
|
+
# format.nt { render nt: model }
|
10
|
+
# end
|
11
|
+
|
12
|
+
module RDF
|
13
|
+
module Serializers
|
14
|
+
module Renderers
|
15
|
+
def self.register(symbols, opts = {})
|
16
|
+
symbols = [symbols] unless symbols.respond_to?(:each)
|
17
|
+
symbols.each do |symbol|
|
18
|
+
format = RDF::Format.for(symbol)
|
19
|
+
raise "#{symbol} if not a known rdf format" if format.nil?
|
20
|
+
Mime::Type.register format.content_type.first, format.file_extension.first
|
21
|
+
add_renderer(format, opts)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.add_renderer(format, opts = {})
|
26
|
+
ActionController::Renderers.add format.file_extension.first do |resource, options|
|
27
|
+
self.content_type = format.content_type.first
|
28
|
+
get_serializer(resource, options.merge(adapter: :rdf)).adapter.dump(format.symbols.first, opts)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arthur Dingemans
|
@@ -66,10 +66,11 @@ extra_rdoc_files: []
|
|
66
66
|
files:
|
67
67
|
- lib/active_model_serializers/adapter/rdf.rb
|
68
68
|
- lib/active_model_serializers/adapter/rdf/relationship.rb
|
69
|
-
- lib/
|
70
|
-
- lib/
|
71
|
-
- lib/
|
72
|
-
|
69
|
+
- lib/active_model_serializers/serializer.rb
|
70
|
+
- lib/rdf/serializers.rb
|
71
|
+
- lib/rdf/serializers/renderers.rb
|
72
|
+
- lib/rdf/serializers/version.rb
|
73
|
+
homepage: https://github.com/argu-co/rdf-serializers
|
73
74
|
licenses: []
|
74
75
|
metadata: {}
|
75
76
|
post_install_message:
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Registers the N-Triples renderer
|
4
|
-
#
|
5
|
-
# And then in controllers, use `render nt: model`.
|
6
|
-
#
|
7
|
-
# For example, in a controller action, we can:
|
8
|
-
# respond_to do |format|
|
9
|
-
# format.nt { render nt: model }
|
10
|
-
# end
|
11
|
-
|
12
|
-
require 'active_model_serializers/adapter/rdf.rb'
|
13
|
-
|
14
|
-
module RDFSerializers
|
15
|
-
module Renderers
|
16
|
-
def self.register(symbols, opts = {})
|
17
|
-
symbols = [symbols] unless symbols.respond_to?(:each)
|
18
|
-
symbols.each do |symbol|
|
19
|
-
format = RDF::Format.for(symbol)
|
20
|
-
raise "#{symbol} if not a known rdf format" if format.nil?
|
21
|
-
Mime::Type.register format.content_type.first, format.file_extension.first
|
22
|
-
add_renderer(format, opts)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.add_renderer(format, opts = {})
|
27
|
-
ActionController::Renderers.add format.file_extension.first do |resource, options|
|
28
|
-
self.content_type = format.content_type.first
|
29
|
-
get_serializer(resource, options.merge(adapter: :rdf)).adapter.dump(format.symbols.first, opts)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|