lightrdf 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.2.5 2011-03-16
2
+
3
+ * Added pool of instantiated objects
4
+ * Support to subclassing proxy nodes
5
+
1
6
  === 0.2.4 2011-03-16
2
7
 
3
8
  * Removed unused prefixes in RDF and YARF serializations
@@ -1,11 +1,17 @@
1
1
  module RDF
2
2
  class Graph < Hash
3
3
  include Parser
4
+
4
5
  # Namespace set stored when parsing a file. Can be used for reference
5
6
  attr_accessor :ns
7
+
8
+ # Set of initialized RDF::NodeProxy objects
9
+ attr_accessor :pool
10
+
6
11
  def initialize triples=[]
7
12
  super(nil)
8
- @ns = {}
13
+ @ns = {}
14
+ @pool = {}
9
15
  self.triples = triples
10
16
  end
11
17
 
@@ -42,9 +48,16 @@ module RDF
42
48
  end
43
49
 
44
50
  # This is equivalent to [], but tries to return a NodeProxy
45
- def node id
46
- node = self[id]
47
- Node.classes[node.rdf::type.first].new node
51
+ # It stores created objects in a pool
52
+ def node id, type=nil
53
+ id = ID(id)
54
+ @pool[id] ||= begin
55
+ node = self[id]
56
+ type ||= node.rdf::type.first
57
+ klass = Node.classes[type]
58
+ raise Exception, "Unknown RDF-mapped type #{type}" unless klass
59
+ klass.new(node)
60
+ end
48
61
  end
49
62
 
50
63
  def find subject, predicate, object
@@ -4,10 +4,14 @@ module RDF
4
4
  def self.included base
5
5
  base.extend ClassMethods
6
6
  base.send :attr_reader, :node
7
- base.maps base.to_s.gsub("::",":").gsub(/\A.*:/) { |a| a.downcase }
7
+ base.maps(base.to_s.gsub("::",":").gsub(/\A.*:/) { |a| a.downcase })
8
8
  end
9
9
 
10
10
  module ClassMethods
11
+ def inherited subclass
12
+ subclass.maps(subclass.to_s.gsub("::",":").gsub(/\A.*:/) { |a| a.downcase })
13
+ end
14
+
11
15
  def maps id
12
16
  @rdf_type = Node(id)
13
17
  Node.classes.delete Node.classes.invert[self]
@@ -60,7 +64,7 @@ module RDF
60
64
 
61
65
  # Any other method (including any predicate) delegated to node
62
66
  def method_missing method, *args
63
- @node.send method, args
67
+ @node.send method, *args
64
68
  end
65
69
  end
66
70
  end
data/lib/lightrdf.rb CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module RDF
5
- VERSION = '0.2.4'
5
+ VERSION = '0.2.5'
6
6
  end
7
7
 
8
8
  require 'rubygems'
data/lightrdf.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{lightrdf}
5
- s.version = "0.2.4"
5
+ s.version = "0.2.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jose Ignacio"]
@@ -216,6 +216,7 @@ foaf: http://xmlns.com/foaf/0.1/
216
216
  person = graph.node(person_node)
217
217
  person.happy_birthday!
218
218
  assert_equal ["26"], person.foaf::age
219
+ assert_equal person.object_id, graph.node(person_node).object_id
219
220
  end
220
221
 
221
222
  def test_instance_equality
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 4
9
- version: 0.2.4
8
+ - 5
9
+ version: 0.2.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jose Ignacio