redlander 0.3.3 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -12,11 +12,12 @@ Note, that you will have to install Redlander (librdf) for Redlander to work.
12
12
 
13
13
  = Usage
14
14
 
15
- To start doing anything with Redland, you need to initialize a model first:
15
+ To start doing anything useful with Redlander, you need to initialize a model first:
16
16
 
17
17
  $ m = Redlander::Model.new
18
18
 
19
19
  This creates a model where all RDF statements are stored in the memory. Depending on the selected storage you may need to supply extra parameters like :user or :password. Look-up the options for Storage.initialize_storage method for the list of storage options.
20
+ Naturally, you don't need to create a model if you just want to play around with independent statements, nodes and the like.
20
21
 
21
22
  Now that you have created a model, you can access its RDF statements:
22
23
 
@@ -13,10 +13,10 @@ module Redlander
13
13
  # - any other Ruby object, which can be coerced into a literal.
14
14
  # If nothing else, a RedlandError is thrown.
15
15
  #
16
- # Note, that you cannot create a resource node from an URI string,
16
+ # Note that you cannot create a resource node from an URI string,
17
17
  # it must be an instance of URI. Otherwise it is treated as a string literal.
18
18
  def initialize(arg = nil, role = :subject)
19
- bound = false
19
+ @bound = false
20
20
  @rdf_node = case arg
21
21
  when NilClass
22
22
  Redland.librdf_new_node_from_blank_identifier(Redlander.rdf_world, nil)
@@ -25,14 +25,18 @@ module Redlander
25
25
  when Node
26
26
  Redland.librdf_new_node_from_node(arg.rdf_node)
27
27
  when Statement
28
- bound = true
28
+ # TODO: Bound nodes should better be produced
29
+ # using an explicit "factory" like Node.from_statement
30
+ # to keep the clutter in the constructor at minimum.
31
+ # (Esp. handling the "bound" stuff)
32
+ @bound = true
29
33
  case role
30
34
  when :subject
31
- Redland.librdf_statement_get_subject(arg.rdf_statement)
35
+ copy_rdf_node_on_initialize(Redland.librdf_statement_get_subject(arg.rdf_statement))
32
36
  when :object
33
- Redland.librdf_statement_get_object(arg.rdf_statement)
37
+ copy_rdf_node_on_initialize(Redland.librdf_statement_get_object(arg.rdf_statement))
34
38
  when :predicate
35
- Redland.librdf_statement_get_predicate(arg.rdf_statement)
39
+ copy_rdf_node_on_initialize(Redland.librdf_statement_get_predicate(arg.rdf_statement))
36
40
  else
37
41
  raise RedlandError.new("Invalid role specified")
38
42
  end
@@ -42,14 +46,20 @@ module Redlander
42
46
  Redland.librdf_new_node_from_typed_literal(Redlander.rdf_world, value, nil, datatype.rdf_uri)
43
47
  end
44
48
  if @rdf_node.null?
45
- raise RedlandError.new("Failed to create a new node") unless bound
49
+ raise RedlandError.new("Failed to create a new node") unless @bound
46
50
  else
47
51
  ObjectSpace.define_finalizer(self, proc { Redland.librdf_free_node(@rdf_node) })
48
52
  # bound nodes cannot be added to (other) statements
49
- freeze if bound
53
+ freeze if @bound
50
54
  end
51
55
  end
52
56
 
57
+ # Bound nodes are those belonging to a statement
58
+ # (bound nodes cannot be modified or added to other statements).
59
+ def bound?
60
+ @bound
61
+ end
62
+
53
63
  def resource?
54
64
  Redland.librdf_node_is_resource(@rdf_node) != 0
55
65
  end
@@ -93,5 +103,20 @@ module Redlander
93
103
  XmlSchema.instantiate(to_s)
94
104
  end
95
105
  end
106
+
107
+
108
+ private
109
+
110
+ def copy_rdf_node_on_initialize(n)
111
+ if n.null?
112
+ if bound?
113
+ n
114
+ else
115
+ raise RedlandError.new("Failed to create a new node")
116
+ end
117
+ else
118
+ Redland.librdf_new_node_from_node(n)
119
+ end
120
+ end
96
121
  end
97
122
  end
@@ -15,7 +15,7 @@ module Redlander
15
15
  @rdf_statement = case source
16
16
  when Stream
17
17
  # Pull a (current) statement from the stream
18
- Redland.librdf_stream_get_object(source.rdf_stream)
18
+ copy_rdf_statement_on_initialize(Redland.librdf_stream_get_object(source.rdf_stream))
19
19
  when Hash
20
20
  # Create a new statement from nodes
21
21
  s = source[:subject] && Node.new(source[:subject]).rdf_node
@@ -105,5 +105,13 @@ module Redlander
105
105
  yield
106
106
  end
107
107
  end
108
+
109
+ def copy_rdf_statement_on_initialize(s)
110
+ if s.null?
111
+ raise RedlandError.new("Failed to create a new statement")
112
+ else
113
+ Redland.librdf_new_statement_from_statement(s)
114
+ end
115
+ end
108
116
  end
109
117
  end
data/lib/redlander/uri.rb CHANGED
@@ -8,9 +8,9 @@ module Redlander
8
8
  Redland.librdf_new_uri(Redlander.rdf_world, source.to_s)
9
9
  when Node
10
10
  if source.resource?
11
- Redland.librdf_node_get_uri(source.rdf_node)
11
+ copy_rdf_uri_on_initialize(Redland.librdf_node_get_uri(source.rdf_node))
12
12
  elsif source.literal?
13
- Redland.librdf_node_get_literal_value_datatype_uri(source.rdf_node)
13
+ copy_rdf_uri_on_initialize(Redland.librdf_node_get_literal_value_datatype_uri(source.rdf_node))
14
14
  else
15
15
  raise NotImplementedError.new
16
16
  end
@@ -25,5 +25,16 @@ module Redlander
25
25
  def to_s
26
26
  Redland.librdf_uri_to_string(@rdf_uri)
27
27
  end
28
+
29
+
30
+ private
31
+
32
+ def copy_rdf_uri_on_initialize(u)
33
+ if u.null?
34
+ raise RedlandError.new("Failed to create URI")
35
+ else
36
+ Redland.librdf_new_uri_from_uri(u)
37
+ end
38
+ end
28
39
  end
29
40
  end
@@ -1,3 +1,3 @@
1
1
  module Redlander
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.5"
3
3
  end
data/lib/redlander.rb CHANGED
@@ -41,6 +41,10 @@ module Redlander
41
41
  # 1) Convert boolean values into 'yes/no' values
42
42
  # 2) Change underscores in key names into dashes ('dhar_ma' => 'dhar-ma')
43
43
  # 3) Join all options as "key='value'" pairs in a comma-separated string
44
+ #
45
+ # E.g.:
46
+ # to_rdf_options {:key => true, "key_board" => 3}
47
+ # # => "key='yes',key-board='3'"
44
48
  def to_rdf_options(options = {})
45
49
  options.inject([]){|opts, option_pair|
46
50
  key = option_pair[0].to_s.gsub(/_/, '-')
@@ -4,12 +4,14 @@ require 'date'
4
4
 
5
5
  describe Node do
6
6
 
7
- it "should be created with default options" do
8
- lambda { Node.new }.should_not raise_exception
9
- end
7
+ describe "blank" do
8
+ subject { Node.new }
9
+
10
+ it { should be_blank }
10
11
 
11
- it "should create a blank node" do
12
- Node.new.should be_blank
12
+ it "should have a blank identifier for a blank node" do
13
+ subject.value.should match(/^_:\w+$/)
14
+ end
13
15
  end
14
16
 
15
17
  it "should create a resource node" do
@@ -72,11 +74,6 @@ describe Node do
72
74
  node.value.xmlschema.should eql(t.xmlschema)
73
75
  end
74
76
 
75
- it "should have a blank identifier for a blank node" do
76
- node = Node.new
77
- node.value.should match(/^_:\w+$/)
78
- end
79
-
80
77
  it "should have an instance of URI for a resource node" do
81
78
  resource_uri = URI.parse('http://example.com/nodes#node_1')
82
79
  Node.new(resource_uri).value.should be_an_instance_of(URI::HTTP)
metadata CHANGED
@@ -1,139 +1,118 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: redlander
3
- version: !ruby/object:Gem::Version
4
- hash: 2933854275357264005
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.5
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 3
10
- version: 0.3.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Slava Kravchenko
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-11-13 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- type: :runtime
22
- prerelease: false
12
+ date: 2012-06-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
23
15
  name: xml_schema
24
- version_requirements: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &9413040 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 856480538658449761
30
- segments:
31
- - 0
32
- - 0
33
- - 1
20
+ - !ruby/object:Gem::Version
34
21
  version: 0.0.1
35
- requirement: *id001
36
- - !ruby/object:Gem::Dependency
37
22
  type: :runtime
38
23
  prerelease: false
24
+ version_requirements: *9413040
25
+ - !ruby/object:Gem::Dependency
39
26
  name: ffi
40
- version_requirements: &id002 !ruby/object:Gem::Requirement
27
+ requirement: &9412480 !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
29
+ requirements:
43
30
  - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 4428665182548103036
46
- segments:
47
- - 1
48
- - 0
49
- version: "1.0"
50
- requirement: *id002
51
- - !ruby/object:Gem::Dependency
52
- type: :development
31
+ - !ruby/object:Gem::Version
32
+ version: '1.0'
33
+ type: :runtime
53
34
  prerelease: false
35
+ version_requirements: *9412480
36
+ - !ruby/object:Gem::Dependency
54
37
  name: rspec
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
38
+ requirement: &9411960 !ruby/object:Gem::Requirement
56
39
  none: false
57
- requirements:
40
+ requirements:
58
41
  - - ~>
59
- - !ruby/object:Gem::Version
60
- hash: 1396078460937419743
61
- segments:
62
- - 1
63
- version: "1"
64
- requirement: *id003
65
- description: " Advanced Redland bindings.\n"
42
+ - !ruby/object:Gem::Version
43
+ version: '1'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *9411960
47
+ description: ! ' Advanced Redland bindings.
48
+
49
+ '
66
50
  email: slava.kravchenko@gmail.com
67
51
  executables: []
68
-
69
52
  extensions: []
70
-
71
- extra_rdoc_files:
53
+ extra_rdoc_files:
72
54
  - README.rdoc
73
- files:
55
+ files:
74
56
  - lib/redlander/error_container.rb
75
57
  - lib/redlander/model.rb
76
58
  - lib/redlander/model_proxy.rb
77
- - lib/redlander/node.rb
78
59
  - lib/redlander/parser.rb
79
60
  - lib/redlander/parser_proxy.rb
80
61
  - lib/redlander/serializer.rb
81
- - lib/redlander/statement.rb
82
62
  - lib/redlander/storage.rb
83
63
  - lib/redlander/stream.rb
84
64
  - lib/redlander/stream_enumerator.rb
85
- - lib/redlander/uri.rb
86
65
  - lib/redlander/version.rb
87
- - spec/spec.opts
88
- - spec/spec_helper.rb
66
+ - lib/redlander/uri.rb
67
+ - lib/redlander/node.rb
68
+ - lib/redlander/statement.rb
89
69
  - spec/integration/memory_leak_spec.rb
90
70
  - spec/redlander/model_spec.rb
91
- - spec/redlander/node_spec.rb
92
71
  - spec/redlander/parser_spec.rb
93
72
  - spec/redlander/serializer_spec.rb
94
73
  - spec/redlander/statement_spec.rb
74
+ - spec/redlander/node_spec.rb
75
+ - spec/spec.opts
76
+ - spec/spec_helper.rb
95
77
  - Rakefile
96
78
  - lib/redlander.rb
97
79
  - README.rdoc
98
80
  homepage: https://github.com/cordawyn/redlander
99
81
  licenses: []
100
-
101
82
  post_install_message:
102
83
  rdoc_options: []
103
-
104
- require_paths:
84
+ require_paths:
105
85
  - lib
106
- required_ruby_version: !ruby/object:Gem::Requirement
86
+ required_ruby_version: !ruby/object:Gem::Requirement
107
87
  none: false
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- hash: 2002549777813010636
112
- segments:
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ segments:
113
93
  - 0
114
- version: "0"
115
- required_rubygems_version: !ruby/object:Gem::Requirement
94
+ hash: 2648553403970259996
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
96
  none: false
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- hash: 2002549777813010636
121
- segments:
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ segments:
122
102
  - 0
123
- version: "0"
103
+ hash: 2648553403970259996
124
104
  requirements: []
125
-
126
105
  rubyforge_project:
127
- rubygems_version: 1.8.11
106
+ rubygems_version: 1.8.15
128
107
  signing_key:
129
108
  specification_version: 3
130
109
  summary: Advanced Redland bindings.
131
- test_files:
132
- - spec/spec.opts
133
- - spec/spec_helper.rb
110
+ test_files:
134
111
  - spec/integration/memory_leak_spec.rb
135
112
  - spec/redlander/model_spec.rb
136
- - spec/redlander/node_spec.rb
137
113
  - spec/redlander/parser_spec.rb
138
114
  - spec/redlander/serializer_spec.rb
139
115
  - spec/redlander/statement_spec.rb
116
+ - spec/redlander/node_spec.rb
117
+ - spec/spec.opts
118
+ - spec/spec_helper.rb