rdf-serializers 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: baf9653c33444a315a892a3720aa0be0503540db
|
4
|
+
data.tar.gz: ca4fbe6d2ad6b87d3fabd8f1b68167fd0470475b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06fda50c2eaec5b6bb346e31f40d78d24645211c3d87eef0c6206492d47f481cbde8a0a540ae447a0fdc75a6e31be45e9686bdfd252121f7bb998aa89c7db9ac
|
7
|
+
data.tar.gz: 94a3b7701bd3291a3cff825782ff06945d1382336574de174030991f2c3f20558537c2ce6423fc8d8fd90c460094f3579c6f2d889abdf2af90c2215691ac8a2a
|
@@ -7,7 +7,7 @@ module ActiveModelSerializers
|
|
7
7
|
autoload :Relationship
|
8
8
|
|
9
9
|
delegate :object, to: :serializer
|
10
|
-
delegate :dump, to: :graph
|
10
|
+
delegate :dump, :triples, to: :graph
|
11
11
|
|
12
12
|
def initialize(serializer, options = {})
|
13
13
|
super
|
@@ -22,31 +22,31 @@ module ActiveModelSerializers
|
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
-
def add_attribute(data,
|
25
|
+
def add_attribute(data, subject, value)
|
26
26
|
predicate = data.options[:predicate]
|
27
27
|
return unless predicate
|
28
28
|
value = value.respond_to?(:each) ? value : [value]
|
29
|
-
value.compact.map { |v| add_triple(
|
29
|
+
value.compact.map { |v| add_triple(subject, predicate, v) }
|
30
30
|
end
|
31
31
|
|
32
32
|
def add_triple(subject, predicate, object)
|
33
33
|
obj =
|
34
34
|
case object
|
35
|
-
when ::RDF::
|
35
|
+
when ::RDF::Term
|
36
36
|
object
|
37
37
|
when ActiveSupport::TimeWithZone
|
38
38
|
::RDF::Literal(object.to_datetime)
|
39
39
|
else
|
40
40
|
::RDF::Literal(object)
|
41
41
|
end
|
42
|
-
@graph <<
|
42
|
+
@graph << ::RDF::Statement.new(subject, ::RDF::URI(predicate), obj)
|
43
43
|
end
|
44
44
|
|
45
45
|
def attributes_for(serializer, fields)
|
46
46
|
serializer.class._attributes_data.map do |key, data|
|
47
47
|
next if data.excluded?(serializer)
|
48
48
|
next unless fields.nil? || fields.include?(key)
|
49
|
-
add_attribute(data, serializer.read_attribute_for_serialization(:
|
49
|
+
add_attribute(data, serializer.read_attribute_for_serialization(:rdf_subject), serializer.attributes[key])
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -86,8 +86,8 @@ module ActiveModelSerializers
|
|
86
86
|
if serializer.is_a?(ActiveModel::Serializer::CollectionSerializer)
|
87
87
|
return serializer.map { |child| process_resource(child, include_slice) }
|
88
88
|
end
|
89
|
-
return unless serializer.respond_to?(:
|
90
|
-
return false unless @resource_identifiers.add?(serializer.read_attribute_for_serialization(:
|
89
|
+
return unless serializer.respond_to?(:rdf_subject) || serializer.object.respond_to?(:rdf_subject)
|
90
|
+
return false unless @resource_identifiers.add?(serializer.read_attribute_for_serialization(:rdf_subject))
|
91
91
|
resource_object_for(serializer, include_slice)
|
92
92
|
true
|
93
93
|
end
|
@@ -104,7 +104,7 @@ module ActiveModelSerializers
|
|
104
104
|
def resource_object_for(serializer, include_slice = {})
|
105
105
|
type = type_for(serializer, instance_options).to_s
|
106
106
|
serializer.fetch(self) do
|
107
|
-
break nil if serializer.read_attribute_for_serialization(:
|
107
|
+
break nil if serializer.read_attribute_for_serialization(:rdf_subject).nil?
|
108
108
|
requested_fields = fieldset&.fields_for(type)
|
109
109
|
attributes_for(serializer, requested_fields)
|
110
110
|
custom_triples_for(serializer)
|
@@ -6,9 +6,9 @@ module ActiveModelSerializers
|
|
6
6
|
class Relationship < JsonApi::Relationship
|
7
7
|
def triples
|
8
8
|
return [] if subject.blank? || predicate.blank? || data.empty?
|
9
|
-
data.map do |
|
10
|
-
raise "#{
|
11
|
-
|
9
|
+
data.map do |object|
|
10
|
+
raise "#{object} is not a RDF::Resource but a #{object.class}" unless object.is_a?(::RDF::Resource)
|
11
|
+
::RDF::Statement.new(subject, predicate, object)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -17,32 +17,32 @@ module ActiveModelSerializers
|
|
17
17
|
def data
|
18
18
|
@data ||=
|
19
19
|
if association.collection?
|
20
|
-
|
20
|
+
objects_for_many(association).compact
|
21
21
|
else
|
22
|
-
[
|
22
|
+
[object_for_one(association)].compact
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
26
|
+
def objects_for_many(association)
|
27
27
|
collection_serializer = association.lazy_association.serializer
|
28
28
|
if collection_serializer.respond_to?(:each)
|
29
29
|
collection_serializer.map do |serializer|
|
30
|
-
serializer.read_attribute_for_serialization(:
|
30
|
+
serializer.read_attribute_for_serialization(:rdf_subject)
|
31
31
|
end
|
32
32
|
else
|
33
33
|
[]
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
37
|
+
def object_for_one(association)
|
38
38
|
if belongs_to_id_on_self?(association)
|
39
|
-
parent_serializer.read_attribute_for_serialization(:
|
39
|
+
parent_serializer.read_attribute_for_serialization(:rdf_subject)
|
40
40
|
else
|
41
41
|
serializer = association.lazy_association.serializer
|
42
42
|
if (virtual_value = association.virtual_value)
|
43
43
|
virtual_value[:id]
|
44
44
|
elsif serializer && association.object
|
45
|
-
serializer.read_attribute_for_serialization(:
|
45
|
+
serializer.read_attribute_for_serialization(:rdf_subject)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -52,7 +52,7 @@ module ActiveModelSerializers
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def subject
|
55
|
-
@subject ||= parent_serializer.read_attribute_for_serialization(:
|
55
|
+
@subject ||= parent_serializer.read_attribute_for_serialization(:rdf_subject)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|