Skip to content

Commit 4d690c9

Browse files
committed
Release 1.99.0:
* exclude 2.x versions of the mongo gem dependency * Add :user and :password options to initialization, to authenticate against Mongo Connection. * Don't insert incomplete statements. * Use `graph_name`, not `context`.
2 parents 4e8e5fa + 0d3482c commit 4d690c9

9 files changed

Lines changed: 72 additions & 48 deletions

File tree

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ env:
55
- CI=true
66
rvm:
77
- 1.9.3
8-
- 2.0.0
9-
- jruby-19mode
10-
- rbx
8+
- 2.0
9+
- 2.1
10+
- 2.2
11+
- jruby
12+
- rbx-2
1113
services:
1214
- mongodb
15+
cache: bundler

Gemfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ source "http://rubygems.org"
22

33
gemspec
44

5-
gem "rdf", :git => "git://github.com/ruby-rdf/rdf.git", :branch => "develop"
5+
gem "rdf", git: "git://github.com/ruby-rdf/rdf.git", branch: "develop"
66

77
group :development do
8-
gem "rdf-spec", :git => "git://github.com/ruby-rdf/rdf-spec.git", :branch => "develop"
8+
gem "rdf-spec", git: "git://github.com/ruby-rdf/rdf-spec.git", branch: "develop"
99
gem "wirble"
1010
end
11+
12+
platforms :rbx do
13+
gem 'rubysl', '~> 2.0'
14+
gem 'rubinius', '~> 2.0'
15+
end

Rakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'rspec/core/rake_task'
55
namespace :gem do
66
desc "Build the rdf-mongo-#{File.read('VERSION').chomp}.gem file"
77
task :build do
8-
sh "gem build .gemspec && mv rdf-mongo-#{File.read('VERSION').chomp}.gem pkg/"
8+
sh "gem build rdf-mongo.gemspec && mv rdf-mongo-#{File.read('VERSION').chomp}.gem pkg/"
99
end
1010

1111
desc "Release the rdf-mongo-#{File.read('VERSION').chomp}.gem file"
@@ -34,5 +34,5 @@ namespace :doc do
3434
end
3535
end
3636

37-
task :default => :spec
38-
task :specs => :spec
37+
task default: :spec
38+
task specs: :spec

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.0
1+
1.99.0

lib/rdf/mongo.rb

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ def to_mongo
1414
end
1515

1616
##
17-
# Create BSON for a statement representation. Note that if the statement has no context,
17+
# Create BSON for a statement representation. Note that if the statement has no graph name,
1818
# a value of `false` will be used to indicate the default context
1919
#
2020
# @param [RDF::Statement] statement
2121
# @return [Hash] Generated BSON representation of statement.
2222
def self.from_mongo(statement)
2323
RDF::Statement.new(
24-
:subject => RDF::Mongo::Conversion.from_mongo(statement['s'], statement['st'], statement['sl']),
25-
:predicate => RDF::Mongo::Conversion.from_mongo(statement['p'], statement['pt'], statement['pl']),
26-
:object => RDF::Mongo::Conversion.from_mongo(statement['o'], statement['ot'], statement['ol']),
27-
:context => RDF::Mongo::Conversion.from_mongo(statement['c'], statement['ct'], statement['cl']))
24+
subject: RDF::Mongo::Conversion.from_mongo(statement['s'], statement['st'], statement['sl']),
25+
predicate: RDF::Mongo::Conversion.from_mongo(statement['p'], statement['pt'], statement['pl']),
26+
object: RDF::Mongo::Conversion.from_mongo(statement['o'], statement['ot'], statement['ol']),
27+
graph_name: RDF::Mongo::Conversion.from_mongo(statement['c'], statement['ct'], statement['cl']))
2828
end
2929
end
3030

@@ -37,9 +37,9 @@ class Conversion
3737
#
3838
# @param [RDF::Value, Symbol, false, nil] value
3939
# URI, BNode or Literal. May also be a Variable or Symbol to indicate
40-
# a pattern for a named context, or `false` to indicate the default context.
40+
# a pattern for a named graph, or `false` to indicate the default graph.
4141
# A value of `nil` indicates a pattern that matches any value.
42-
# @param [:subject, :predicate, :object, :context] place_in_statement
42+
# @param [:subject, :predicate, :object, :graph_name] place_in_statement
4343
# Position within statement.
4444
# @return [Hash] BSON representation of the statement
4545
def self.to_mongo(value, place_in_statement)
@@ -76,7 +76,7 @@ def self.to_mongo(value, place_in_statement)
7676
t, k1, lt = :pt, :p, :pl
7777
when :object
7878
t, k1, lt = :ot, :o, :ol
79-
when :context
79+
when :graph_name
8080
t, k1, lt = :ct, :c, :cl
8181
end
8282
h = {k1 => v, t => k, lt => ll}
@@ -92,9 +92,9 @@ def self.from_mongo(value, value_type = :u, literal_extra = nil)
9292
when :u
9393
RDF::URI.intern(value)
9494
when :ll
95-
RDF::Literal.new(value, :language => literal_extra.to_sym)
95+
RDF::Literal.new(value, language: literal_extra.to_sym)
9696
when :lt
97-
RDF::Literal.new(value, :datatype => RDF::URI.intern(literal_extra))
97+
RDF::Literal.new(value, datatype: RDF::URI.intern(literal_extra))
9898
when :l
9999
RDF::Literal.new(value)
100100
when :n
@@ -126,12 +126,15 @@ class Repository < ::RDF::Repository
126126
# @option options [String] :host
127127
# @option options [Integer] :port
128128
# @option options [String] :db
129+
# @option options [String] :user for authentication
130+
# @option options [String] :password for authentication
129131
# @option options [String] :collection ('quads')
130132
# @yield [repository]
131133
# @yieldparam [Repository] repository
132134
def initialize(options = {}, &block)
133-
options = {:host => 'localhost', :port => 27017, :db => 'quadb', :collection => 'quads'}.merge(options)
135+
options = {host: 'localhost', port: 27017, db: 'quadb', collection: 'quads'}.merge(options)
134136
@db = ::Mongo::Connection.new(options[:host], options[:port]).db(options[:db])
137+
@db.authenticate(options[:user], options[:password]) if options[:user] && options[:password]
135138
@coll = @db[options[:collection]]
136139
@coll.create_index("s")
137140
@coll.create_index("p")
@@ -146,21 +149,22 @@ def initialize(options = {}, &block)
146149
# @see RDF::Mutable#insert_statement
147150
def supports?(feature)
148151
case feature.to_sym
149-
when :context then true
152+
when :graph_name then true
150153
else false
151154
end
152155
end
153156

154157
def insert_statement(statement)
158+
raise ArgumentError, "Statement #{statement.inspect} is incomplete" if statement.incomplete?
155159
st_mongo = statement.to_mongo
156-
st_mongo[:ct] ||= :default # Indicate statement is in the default context
160+
st_mongo[:ct] ||= :default # Indicate statement is in the default graph
157161
#puts "insert statement: #{st_mongo.inspect}"
158-
@coll.update(st_mongo, st_mongo, :upsert => true)
162+
@coll.update(st_mongo, st_mongo, upsert: true)
159163
end
160164

161165
# @see RDF::Mutable#delete_statement
162166
def delete_statement(statement)
163-
case statement.context
167+
case statement.graph_name
164168
when nil
165169
@coll.remove(statement.to_mongo.merge('ct'=>:default))
166170
else
@@ -213,8 +217,8 @@ def each_statement(&block)
213217

214218
##
215219
# @private
216-
# @see RDF::Enumerable#has_context?
217-
def has_context?(value)
220+
# @see RDF::Enumerable#has_graph?
221+
def has_graph?(value)
218222
!!@coll.find_one(RDF::Mongo::Conversion.to_mongo(value, :context))
219223
end
220224

@@ -227,9 +231,9 @@ def has_context?(value)
227231
def query_pattern(pattern, &block)
228232
@nodes = {} # reset cache. FIXME this should probably be in Node.intern
229233

230-
# A pattern context of `false` is used to indicate the default context
234+
# A pattern graph_name of `false` is used to indicate the default graph
231235
pm = pattern.to_mongo
232-
pm.merge!(:c => nil, :ct => :default) if pattern.context == false
236+
pm.merge!(c: nil, ct: :default) if pattern.graph_name == false
233237
#puts "query using #{pm.inspect}"
234238
@coll.find(pm) do |cursor|
235239
cursor.each do |data|

rdf-mongo.gemfile

Lines changed: 0 additions & 1 deletion
This file was deleted.

.gemspec renamed to rdf-mongo.gemspec

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ Gem::Specification.new do |gem|
2727
gem.test_files = Dir.glob('spec/*.spec')
2828
gem.has_rdoc = false
2929

30-
gem.required_ruby_version = '>= 1.9.2'
30+
gem.required_ruby_version = '>= 1.9.3'
3131
gem.requirements = []
32-
gem.add_runtime_dependency 'rdf', '>= 1.1'
33-
gem.add_runtime_dependency 'mongo', '>= 1.8.6', '< 2.0'
32+
gem.add_runtime_dependency 'rdf', '~> 1.99'
33+
gem.add_runtime_dependency 'mongo', '~> 1.10'
3434

35-
gem.add_development_dependency 'rdf-spec', '>= 1.1'
36-
gem.add_development_dependency 'rspec', '>= 2.14.0'
37-
gem.add_development_dependency 'yard' , '>= 0.8.7'
35+
gem.add_development_dependency 'rdf-spec', '~> 1.99'
36+
gem.add_development_dependency 'rspec', '~> 3.0'
37+
gem.add_development_dependency 'rspec-its', '~> 1.0'
38+
gem.add_development_dependency 'yard' , '~> 0.8'
3839
gem.add_development_dependency 'bson_ext' unless defined?(:RUBY_ENGINE) && RUBY_ENGINE == "jruby"
3940

4041
# Rubinius has it's own dependencies

spec/mongo_repository_spec.rb

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,31 @@
55
require 'rdf/mongo'
66

77
describe RDF::Mongo::Repository do
8-
context "Mongo RDF Repository" do
9-
before :each do
10-
@repository = RDF::Mongo::Repository.new() # TODO: Do you need constructor arguments?
11-
@repository.coll.drop
12-
end
13-
14-
after :each do
15-
@repository.coll.drop
16-
end
8+
before :each do
9+
@repository = RDF::Mongo::Repository.new() # TODO: Do you need constructor arguments?
10+
@repository.coll.drop
11+
end
12+
13+
after :each do
14+
@repository.coll.drop
15+
end
1716

18-
# @see lib/rdf/spec/repository.rb in RDF-spec
19-
include RDF_Repository
17+
# @see lib/rdf/spec/repository.rb in RDF-spec
18+
it_behaves_like "an RDF::Repository" do
19+
let(:repository) {@repository}
2020
end
2121

22+
context "problemantic examples" do
23+
subject {@repository}
24+
{
25+
"Insert key too large to index" => %(
26+
<http://repository.librario.de/publications/0cbdc7f4-728d-4f85-ab09-01060c7b2922> <http://purl.org/ontology/bibo/abstract> "#{'a' * 1001}" .
27+
)
28+
}.each do |name, nt|
29+
it name do
30+
expect {subject << RDF::Graph.new << RDF::NTriples::Reader.new(nt)}.not_to raise_error
31+
end
32+
end
33+
end
2234
end
2335

spec/spec_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
require 'rdf/mongo'
55

66
RSpec.configure do |config|
7-
config.filter_run :focus => true
7+
config.filter_run focus: true
88
config.run_all_when_everything_filtered = true
99
config.exclusion_filter = {
10-
:ruby => lambda { |version| RUBY_VERSION.to_s !~ /^#{version}/},
10+
ruby: lambda { |version| RUBY_VERSION.to_s !~ /^#{version}/},
1111
}
1212
end

0 commit comments

Comments
 (0)