redlander 0.3.5 → 0.3.6

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.
data/lib/redland.rb ADDED
@@ -0,0 +1,84 @@
1
+ # FFI bindings
2
+
3
+ module Redland
4
+ if !defined?(RUBY_ENGINE) || RUBY_ENGINE=='ruby'
5
+ require 'ffi'
6
+ extend FFI::Library
7
+ ffi_lib "rdf.so.0"
8
+ else
9
+ extend FFI::Library
10
+ ffi_lib "librdf.so.0"
11
+ end
12
+
13
+ # World
14
+ attach_function :librdf_new_world, [], :pointer
15
+ attach_function :librdf_free_world, [:pointer], :void
16
+ attach_function :librdf_world_open, [:pointer], :void
17
+
18
+ # Storage
19
+ attach_function :librdf_new_storage, [:pointer, :string, :string, :string], :pointer
20
+ attach_function :librdf_free_storage, [:pointer], :void
21
+
22
+ # Model
23
+ attach_function :librdf_new_model, [:pointer, :pointer, :string], :pointer
24
+ attach_function :librdf_free_model, [:pointer], :void
25
+ attach_function :librdf_model_as_stream, [:pointer], :pointer
26
+ attach_function :librdf_model_size, [:pointer], :int
27
+ attach_function :librdf_model_find_statements, [:pointer, :pointer], :pointer
28
+ attach_function :librdf_model_add_statement, [:pointer, :pointer], :int
29
+ attach_function :librdf_model_remove_statement, [:pointer, :pointer], :int
30
+ attach_function :librdf_model_transaction_start, [:pointer], :int
31
+ attach_function :librdf_model_transaction_commit, [:pointer], :int
32
+ attach_function :librdf_model_transaction_rollback, [:pointer], :int
33
+
34
+ # Statement
35
+ attach_function :librdf_free_statement, [:pointer], :void
36
+ attach_function :librdf_new_statement_from_nodes, [:pointer, :pointer, :pointer, :pointer], :pointer
37
+ attach_function :librdf_new_statement_from_statement, [:pointer], :pointer
38
+ attach_function :librdf_statement_get_subject, [:pointer], :pointer
39
+ attach_function :librdf_statement_get_predicate, [:pointer], :pointer
40
+ attach_function :librdf_statement_get_object, [:pointer], :pointer
41
+ attach_function :librdf_statement_set_subject, [:pointer, :pointer], :void
42
+ attach_function :librdf_statement_set_predicate, [:pointer, :pointer], :void
43
+ attach_function :librdf_statement_set_object, [:pointer, :pointer], :void
44
+ attach_function :librdf_statement_to_string, [:pointer], :string
45
+
46
+ # Node
47
+ attach_function :librdf_free_node, [:pointer], :void
48
+ attach_function :librdf_new_node_from_blank_identifier, [:pointer, :string], :pointer
49
+ attach_function :librdf_new_node_from_uri_string, [:pointer, :string], :pointer
50
+ attach_function :librdf_new_node_from_node, [:pointer], :pointer
51
+ attach_function :librdf_new_node_from_typed_literal, [:pointer, :string, :string, :pointer], :pointer
52
+ attach_function :librdf_node_is_resource, [:pointer], :int
53
+ attach_function :librdf_node_is_literal, [:pointer], :int
54
+ attach_function :librdf_node_is_blank, [:pointer], :int
55
+ attach_function :librdf_node_get_literal_value_datatype_uri, [:pointer], :pointer
56
+ attach_function :librdf_node_equals, [:pointer, :pointer], :int
57
+ attach_function :librdf_node_to_string, [:pointer], :string
58
+ attach_function :librdf_node_get_uri, [:pointer], :pointer
59
+
60
+ # Stream
61
+ attach_function :librdf_free_stream, [:pointer], :void
62
+ attach_function :librdf_stream_end, [:pointer], :int
63
+ attach_function :librdf_stream_next, [:pointer], :int
64
+ attach_function :librdf_stream_get_object, [:pointer], :pointer
65
+
66
+ # Serializer
67
+ attach_function :librdf_new_serializer, [:pointer, :string, :string, :pointer], :pointer
68
+ attach_function :librdf_free_serializer, [:pointer], :void
69
+ attach_function :librdf_serializer_serialize_model_to_string, [:pointer, :pointer, :pointer], :string
70
+ attach_function :librdf_serializer_serialize_model_to_file, [:pointer, :string, :pointer, :pointer], :int
71
+
72
+ # Parser
73
+ attach_function :librdf_new_parser, [:pointer, :string, :string, :pointer], :pointer
74
+ attach_function :librdf_free_parser, [:pointer], :void
75
+ attach_function :librdf_parser_parse_into_model, [:pointer, :pointer, :pointer, :pointer], :int
76
+ attach_function :librdf_parser_parse_string_into_model, [:pointer, :string, :pointer, :pointer], :int
77
+ attach_function :librdf_parser_parse_string_as_stream, [:pointer, :string, :pointer], :pointer
78
+
79
+ # URI
80
+ attach_function :librdf_new_uri, [:pointer, :string], :pointer
81
+ attach_function :librdf_new_uri_from_uri, [:pointer], :pointer
82
+ attach_function :librdf_free_uri, [:pointer], :void
83
+ attach_function :librdf_uri_to_string, [:pointer], :string
84
+ end
@@ -0,0 +1,2 @@
1
+ # Generic Redland error
2
+ class RedlandError < RuntimeError; end
@@ -1,3 +1,8 @@
1
+ require 'redlander/storage'
2
+ require 'redlander/parser'
3
+ require 'redlander/serializer'
4
+ require 'redlander/model_proxy'
5
+
1
6
  module Redlander
2
7
  class Model
3
8
  include Redlander::ParsingInstanceMethods
@@ -28,9 +33,9 @@ module Redlander
28
33
  # (Does not work for all storages, in which case the changes are instanteous).
29
34
  def transaction
30
35
  if block_given?
31
- Redland.librdf_model_transaction_start(@rdf_model).zero? || RedlandError.new("Failed to initialize a transaction")
36
+ Redland.librdf_model_transaction_start(@rdf_model).zero? || raise(RedlandError, "Failed to initialize a transaction")
32
37
  yield
33
- Redland.librdf_model_transaction_commit(@rdf_model).zero? || RedlandError.new("Failed to commit the transaction")
38
+ Redland.librdf_model_transaction_commit(@rdf_model).zero? || raise(RedlandError, "Failed to commit the transaction")
34
39
  end
35
40
  rescue
36
41
  rollback
@@ -39,7 +44,7 @@ module Redlander
39
44
 
40
45
  # Rollback the transaction
41
46
  def rollback
42
- Redland.librdf_model_transaction_rollback(@rdf_model).zero? || RedlandError.new("Failed to rollback the latest transaction")
47
+ Redland.librdf_model_transaction_rollback(@rdf_model).zero? || raise(RedlandError, "Failed to rollback the latest transaction")
43
48
  end
44
49
  end
45
50
  end
@@ -1,3 +1,6 @@
1
+ require 'redlander/stream'
2
+ require 'redlander/stream_enumerator'
3
+
1
4
  module Redlander
2
5
  class ModelProxy
3
6
  include StreamEnumerator
@@ -1,3 +1,5 @@
1
+ require 'redlander/parser_proxy'
2
+
1
3
  module Redlander
2
4
  class Parser
3
5
  attr_reader :rdf_parser
@@ -1,3 +1,6 @@
1
+ require 'redlander/stream'
2
+ require 'redlander/stream_enumerator'
3
+
1
4
  module Redlander
2
5
  class ParserProxy
3
6
  include StreamEnumerator
@@ -1,3 +1,6 @@
1
+ require 'redlander/stream'
2
+ require "redlander/error_container"
3
+
1
4
  module Redlander
2
5
  class Statement
3
6
  include ErrorContainer
@@ -1,7 +1,5 @@
1
1
  module Redlander
2
2
  class Storage
3
- VALID_STORAGE_TYPES = [:memory, :hashes, :file, :uri, :tstore, :mysql, :sqlite, :postgresql]
4
-
5
3
  attr_reader :rdf_storage
6
4
 
7
5
  # Creates a store of the given type
@@ -15,7 +13,12 @@ module Redlander
15
13
  # :sqlite
16
14
  # :postgresql
17
15
  # :tstore
18
- # Options are:
16
+ # :virtuoso
17
+ # ... anything else that Redland can handle.
18
+ #
19
+ # Options are storage-specific.
20
+ # Read the documentation for the appropriate Redland Storage module.
21
+ #
19
22
  # :name - ?
20
23
  # :host - database host name (for store types: :postgres, :mysql, :tstore)
21
24
  # :port - database host port (for store types: :postgres, :mysql, :tstore)
@@ -34,15 +37,11 @@ module Redlander
34
37
  def initialize(options = {})
35
38
  storage_type, storage_options = split_options(options.dup)
36
39
 
37
- unless VALID_STORAGE_TYPES.include?(storage_type)
38
- raise RedlandError.new("Unknown storage type: #{storage_type}")
39
- end
40
-
41
40
  @rdf_storage = Redland.librdf_new_storage(Redlander.rdf_world,
42
41
  storage_type.to_s,
43
42
  storage_options.delete(:name).to_s,
44
43
  Redlander.to_rdf_options(storage_options))
45
- raise RedlandError.new("Failed to initialize storage") if @rdf_storage.null?
44
+ raise RedlandError.new("Failed to initialize '#{storage_type}' storage") if @rdf_storage.null?
46
45
  ObjectSpace.define_finalizer(self, proc { Redland.librdf_free_storage(@rdf_storage) })
47
46
  end
48
47
 
@@ -1,3 +1,3 @@
1
1
  module Redlander
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
data/lib/redlander.rb CHANGED
@@ -1,29 +1,15 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
-
4
1
  require 'uri'
5
2
  require 'xml_schema'
3
+ require 'redland'
4
+ require 'redlander/version'
6
5
 
7
- module Redlander
8
- require 'redland'
9
- require 'redlander/version'
10
-
11
- class RedlandError < RuntimeError; end
6
+ require "redlander/exceptions"
7
+ require 'redlander/uri'
8
+ require 'redlander/node'
9
+ require 'redlander/model'
10
+ require 'redlander/statement'
12
11
 
13
- autoload :ErrorContainer, 'redlander/error_container'
14
- autoload :Uri, 'redlander/uri'
15
- autoload :Parser, 'redlander/parser'
16
- autoload :ParserProxy, 'redlander/parser_proxy'
17
- autoload :Serializer, 'redlander/serializer'
18
- autoload :Model, 'redlander/model'
19
- autoload :ModelProxy, 'redlander/model_proxy'
20
- autoload :Node, 'redlander/node'
21
- autoload :Stream, 'redlander/stream'
22
- autoload :Storage, 'redlander/storage'
23
- autoload :ParsingInstanceMethods, 'redlander/parser'
24
- autoload :SerializingInstanceMethods, 'redlander/serializer'
25
- autoload :StreamEnumerator, 'redlander/stream_enumerator'
26
- autoload :Statement, 'redlander/statement'
12
+ module Redlander
27
13
 
28
14
  class << self
29
15
  def rdf_world
@@ -2,19 +2,11 @@ require "spec_helper"
2
2
 
3
3
  describe Model do
4
4
 
5
- it "should be created with default options" do
6
- lambda { Model.new }.should_not raise_exception
7
- end
5
+ before { @model = Model.new }
8
6
 
9
7
  describe "statements" do
10
8
 
11
- before :each do
12
- @model = Model.new
13
- end
14
-
15
- it do
16
- @model.statements.should be_an_instance_of(ModelProxy)
17
- end
9
+ it { @model.statements.should be_an_instance_of(ModelProxy) }
18
10
 
19
11
  it "should be created in the model" do
20
12
  lambda {
@@ -107,7 +99,6 @@ describe Model do
107
99
  describe "serialization" do
108
100
 
109
101
  before :each do
110
- @model = Model.new
111
102
  s = URI.parse("http://example.com/concepts#two-dimensional_seismic_imaging")
112
103
  p = URI.parse("http://www.w3.org/2000/01/rdf-schema#label")
113
104
  o = "2-D seismic imaging@en"
@@ -197,10 +188,6 @@ describe Model do
197
188
 
198
189
  describe "deserialization" do
199
190
 
200
- before :each do
201
- @model = Model.new
202
- end
203
-
204
191
  it "should be successful for RDF/XML data" do
205
192
  content = '<?xml version="1.0" encoding="utf-8"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="http://example.com/concepts#two-dimensional_seismic_imaging"><ns0:label xmlns:ns0="http://www.w3.org/2000/01/rdf-schema#" xml:lang="en">2-D seismic imaging</ns0:label></rdf:Description></rdf:RDF>'
206
193
  lambda {
@@ -227,4 +214,42 @@ foo:bar foo: : .'
227
214
 
228
215
  end
229
216
 
217
+ describe "transactions" do
218
+ before do
219
+ Redland.stub(:librdf_model_transaction_start => 0,
220
+ :librdf_model_transaction_commit => 0,
221
+ :librdf_model_transaction_rollback => 0)
222
+ end
223
+
224
+ context "when start fails" do
225
+ before { Redland.stub(:librdf_model_transaction_start => -1) }
226
+
227
+ it "should raise RedlandError" do
228
+ lambda {
229
+ @model.transaction { true }
230
+ }.should raise_exception RedlandError
231
+ end
232
+ end
233
+
234
+ context "when commit fails" do
235
+ before { Redland.stub(:librdf_model_transaction_commit => -1) }
236
+
237
+ it "should raise RedlandError" do
238
+ lambda {
239
+ @model.transaction { true }
240
+ }.should raise_exception RedlandError
241
+ end
242
+ end
243
+
244
+ context "when rollback fails" do
245
+ before { Redland.stub(:librdf_model_transaction_rollback => -1) }
246
+
247
+ it "should raise RedlandError" do
248
+ lambda {
249
+ @model.rollback
250
+ }.should raise_exception RedlandError
251
+ end
252
+ end
253
+ end
254
+
230
255
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,3 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), "..")) unless
2
- $:.include?(File.join(File.dirname(__FILE__), "..")) || $:.include?(File.expand_path(File.join(File.dirname(__FILE__), "..")))
3
-
4
1
  require 'spec/autorun'
5
2
 
6
3
  require 'lib/redlander'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redlander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-12 00:00:00.000000000 Z
12
+ date: 2012-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: xml_schema
16
- requirement: &9413040 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 0.0.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9413040
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.0.1
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: ffi
27
- requirement: &9412480 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '1.0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *9412480
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec
38
- requirement: &9411960 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: '1'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *9411960
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1'
47
62
  description: ! ' Advanced Redland bindings.
48
63
 
49
64
  '
@@ -53,8 +68,8 @@ extensions: []
53
68
  extra_rdoc_files:
54
69
  - README.rdoc
55
70
  files:
71
+ - lib/redland.rb
56
72
  - lib/redlander/error_container.rb
57
- - lib/redlander/model.rb
58
73
  - lib/redlander/model_proxy.rb
59
74
  - lib/redlander/parser.rb
60
75
  - lib/redlander/parser_proxy.rb
@@ -64,18 +79,19 @@ files:
64
79
  - lib/redlander/stream_enumerator.rb
65
80
  - lib/redlander/version.rb
66
81
  - lib/redlander/uri.rb
82
+ - lib/redlander/exceptions.rb
83
+ - lib/redlander/model.rb
67
84
  - lib/redlander/node.rb
68
85
  - lib/redlander/statement.rb
86
+ - lib/redlander.rb
69
87
  - spec/integration/memory_leak_spec.rb
70
88
  - spec/redlander/model_spec.rb
71
89
  - spec/redlander/parser_spec.rb
72
90
  - spec/redlander/serializer_spec.rb
73
91
  - spec/redlander/statement_spec.rb
74
92
  - spec/redlander/node_spec.rb
75
- - spec/spec.opts
76
93
  - spec/spec_helper.rb
77
94
  - Rakefile
78
- - lib/redlander.rb
79
95
  - README.rdoc
80
96
  homepage: https://github.com/cordawyn/redlander
81
97
  licenses: []
@@ -91,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
107
  version: '0'
92
108
  segments:
93
109
  - 0
94
- hash: 2648553403970259996
110
+ hash: -3193927855587243710
95
111
  required_rubygems_version: !ruby/object:Gem::Requirement
96
112
  none: false
97
113
  requirements:
@@ -100,10 +116,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
116
  version: '0'
101
117
  segments:
102
118
  - 0
103
- hash: 2648553403970259996
119
+ hash: -3193927855587243710
104
120
  requirements: []
105
121
  rubyforge_project:
106
- rubygems_version: 1.8.15
122
+ rubygems_version: 1.8.24
107
123
  signing_key:
108
124
  specification_version: 3
109
125
  summary: Advanced Redland bindings.
@@ -114,5 +130,3 @@ test_files:
114
130
  - spec/redlander/serializer_spec.rb
115
131
  - spec/redlander/statement_spec.rb
116
132
  - spec/redlander/node_spec.rb
117
- - spec/spec.opts
118
- - spec/spec_helper.rb
data/spec/spec.opts DELETED
@@ -1 +0,0 @@
1
- --color