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: a4391cb7d489b6d9803ef2e089c5a18ddccdefc7
4
- data.tar.gz: 8d6433403ea396f8c5d1b9c3d2ca3f8b31b2a518
3
+ metadata.gz: baf9653c33444a315a892a3720aa0be0503540db
4
+ data.tar.gz: ca4fbe6d2ad6b87d3fabd8f1b68167fd0470475b
5
5
  SHA512:
6
- metadata.gz: d677e2b57abb3e7e61e3e6e0093fde1bfb85bff31d656a9965e4a9a74cd11eaf3386a912397f3c60cdb06ebbcc20c21634034c1b2a340733301eb248a82f957d
7
- data.tar.gz: ad515fd70be7102bda3cd44b4ac48f70a8ad02ffce3d1b66e25a2a036d2a8008a8ebcce11d38b04f5dfea51d42a7e91a7af1a7f8bd2a5323a5580d943cf226ee
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, iri, value)
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(iri, predicate, v) }
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::Resource, ::RDF::Literal
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 << [::RDF::URI(subject), ::RDF::URI(predicate), obj]
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(:iri), serializer.attributes[key])
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?(:iri) || serializer.object.respond_to?(:iri)
90
- return false unless @resource_identifiers.add?(serializer.read_attribute_for_serialization(:iri))
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(:iri).nil?
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 |iri|
10
- raise "#{iri} is not a RDF::URI but a #{iri.class}" unless iri.is_a?(::RDF::URI)
11
- [subject, predicate, iri]
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
- iri_for_many(association).compact
20
+ objects_for_many(association).compact
21
21
  else
22
- [iri_for_one(association)].compact
22
+ [object_for_one(association)].compact
23
23
  end
24
24
  end
25
25
 
26
- def iri_for_many(association)
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(:iri)
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 iri_for_one(association)
37
+ def object_for_one(association)
38
38
  if belongs_to_id_on_self?(association)
39
- parent_serializer.read_attribute_for_serialization(:iri)
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(:iri)
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(:iri)
55
+ @subject ||= parent_serializer.read_attribute_for_serialization(:rdf_subject)
56
56
  end
57
57
  end
58
58
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RDFSerializers
4
4
  module Version
5
- VERSION = '0.0.3'
5
+ VERSION = '0.0.4'
6
6
  end
7
7
  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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Dingemans