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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6db3307aae5e975df5c2a5d3dde85f6354d0b788
4
- data.tar.gz: b1ed8984ee9a8c054140d311e46e730d26f7bd10
3
+ metadata.gz: 1ed97dbe57a341549fb3bf366bebc5b630fcded0
4
+ data.tar.gz: ca39c6571dba789c392a76085e9548c4fc04bed0
5
5
  SHA512:
6
- metadata.gz: 5e1af6b5e5c7e641516b61cabbf8ced44fa2f85ee4e3954bf9e6d8819621c6716cbdba4efd8cdd86c77c0f4882be3c7dad149f713c49cfe193afdd689a17ee57
7
- data.tar.gz: 52ef788b59d23e5fef8bab0cce2a4874d956f89b77115d3e8bf67d6885884cfe14a5ab21b6a158d19b7b6c09a8da1adfdc6f465f3ee8eab422901987da8427ba
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,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveModel
4
+ class Serializer
5
+ class_attribute :_triples
6
+
7
+ def self.triples(attribute)
8
+ self._triples ||= []
9
+ self._triples << attribute
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_model_serializers/adapter/rdf'
4
+ require 'active_model_serializers/serializer'
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RDFSerializers
4
4
  module Version
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
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.1
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/rdf_serializers.rb
70
- - lib/rdf_serializers/renderers.rb
71
- - lib/rdf_serializers/version.rb
72
- homepage: http://rubygems.org/gems/rdf_serializers
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