acts_as_rdf 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/acts_as_rdf.rb +19 -16
  3. data/test/test_to_rdf.rb +2 -3
  4. metadata +4 -4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
data/lib/acts_as_rdf.rb CHANGED
@@ -40,26 +40,26 @@ module ActsAsRdf
40
40
  module InstanceMethods
41
41
 
42
42
  # current tested formats are rdfxml, turtle, ntriples
43
- def to_rdf(host = "http://localhost", format = :rdfxml)
44
- graph = to_graph(host)
45
- return to_output(graph, host, format)
43
+ def to_rdf(request = nil, format = :rdfxml)
44
+ graph = to_graph(request)
45
+ return to_output(graph, request, format)
46
46
  end
47
47
 
48
48
  protected
49
49
 
50
- def to_graph(host, graph = RDF::Graph.new)
50
+ def to_graph(request, graph = RDF::Graph.new)
51
51
 
52
52
  if 'Array'.eql?(self.class.name) then
53
53
  self.each do |element|
54
- graph = self.to_graph(host, graph)
54
+ graph = self.to_graph(request, graph)
55
55
  end
56
56
  else
57
- graph << [to_uri(self, host), RDF.type, to_uri(self.class, host)]
57
+ graph << [to_uri(self, request), RDF.type, to_uri(self.class, request)]
58
58
 
59
59
  self.attributes.each do |attr, value|
60
- graph << [to_uri(self, host), to_uri(attr, host), RDF::Literal.new(value)]
60
+ graph << [to_uri(self, request), to_uri(attr, request), RDF::Literal.new(value)]
61
61
  if ('name'.eql?(attr)) then
62
- graph << [to_uri(self, host), RDF::RDFS.label, RDF::Literal.new(value)]
62
+ graph << [to_uri(self, request), RDF::RDFS.label, RDF::Literal.new(value)]
63
63
  end
64
64
  end
65
65
 
@@ -71,10 +71,10 @@ module ActsAsRdf
71
71
  if association_objects != nil then
72
72
  if 'Array'.eql?(association_objects.class.name) then
73
73
  association_objects.each do |obj|
74
- graph << [to_uri(self, host), to_uri(soc.class_name, host), to_uri(obj, host)]
74
+ graph << [to_uri(self, request), to_uri(soc.class_name, request), to_uri(obj, request)]
75
75
  end
76
76
  else
77
- graph << [to_uri(self, host), to_uri(soc.class_name, host), to_uri(association_objects, host)]
77
+ graph << [to_uri(self, request), to_uri(soc.class_name, request), to_uri(association_objects, request)]
78
78
  end
79
79
  end
80
80
  end
@@ -85,8 +85,8 @@ module ActsAsRdf
85
85
  return graph
86
86
  end
87
87
 
88
- def to_output(graph, host, format)
89
- base_uri = RDF::URI.new(host)
88
+ def to_output(graph, request, format)
89
+ base_uri = RDF::URI.new(get_base_uri(request))
90
90
 
91
91
  return RDF::Writer.for(format).buffer(:base_uri => base_uri, :default_namespace => base_uri, :prefixes => get_prefixes()) { |writer|
92
92
  graph.each_statement do |statement|
@@ -95,17 +95,20 @@ module ActsAsRdf
95
95
  }
96
96
  end
97
97
 
98
- def to_uri(thing, host)
98
+ def to_uri(thing, request)
99
99
  if (thing.class.name != nil)
100
100
  if ('String'.eql?(thing.class.name) || 'Class'.eql?(thing.class.name)) then
101
- return RDF::URI.new("#{host}/#{thing.to_s}")
101
+ return RDF::URI.new("#{get_base_uri(request)}/#{thing.to_s}")
102
102
  end
103
- return RDF::URI.new("#{host}/#{thing.class.name.tableize}/#{thing.id}")
103
+ return RDF::URI.new("#{get_base_uri(request)}/#{thing.class.name.tableize}/#{thing.id}")
104
104
  end
105
105
 
106
- return RDF::URI.new("#{host}##{thing.to_s}")
106
+ return RDF::URI.new("#{get_base_uri(request)}##{thing.to_s}")
107
107
  end
108
108
 
109
+ def get_base_uri(request)
110
+ request.nil? ? "http://locahost" : "#{request.protocol}://#{request.host}:#{request.port}"
111
+ end
109
112
  end
110
113
  end
111
114
 
data/test/test_to_rdf.rb CHANGED
@@ -13,14 +13,13 @@ class RdfTest < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  def test_to_rdf
16
- host = 'http://localhost'
17
16
  formats = [:rdfxml, :turtle, :ntriples]
18
17
  formats.each do |format|
19
18
  Mixin.find(:all).each do |o|
20
- puts o.to_rdf(host, format)
19
+ puts o.to_rdf(nil, format)
21
20
  end
22
21
  MixinRelation.find(:all).each do |o|
23
- puts o.to_rdf(host, format)
22
+ puts o.to_rdf(nil, format)
24
23
  end
25
24
  end
26
25
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_rdf
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Sodt
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-26 00:00:00 -07:00
18
+ date: 2010-10-28 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency