Skip to content

Commit 4228512

Browse files
committed
Update calling sequence to favor the use of a uri named argument containing all state needed to reproduce the connection.
1 parent ad4d604 commit 4228512

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

VERSION

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

lib/rdf/mongo.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,29 @@ class Repository < ::RDF::Repository
122122
#
123123
# @param [Hash{Symbol => Object}] options
124124
# @option options [URI, #to_s] :uri (nil)
125+
# URI in the form mongodb://host:port/db/collection
125126
# @option options [String, #to_s] :title (nil)
126127
# @option options [String] :host
127128
# @option options [Integer] :port
128-
# @option options [String] :db
129+
# @option options [String] :db ('quadb')
129130
# @option options [String] :user for authentication
130131
# @option options [String] :password for authentication
131132
# @option options [String] :collection ('quads')
132133
# @yield [repository]
133134
# @yieldparam [Repository] repository
134135
def initialize(options = {}, &block)
136+
if options[:uri]
137+
options = options.dup
138+
uri = RDF::URI(options[:uri])
139+
options[:host] ||= uri.host
140+
options[:port] ||= uri.port
141+
_, db, collection = uri.path.split('/')
142+
options[:db] ||= db
143+
options[:collection] ||= collection
144+
else
145+
warn "[DEPRECATION] RDF::Mongo::Repository#initialize expects a uri argument. Called from #{Gem.location_of_caller.join(':')}" unless options.empty?
146+
end
147+
135148
options = {host: 'localhost', port: 27017, db: 'quadb', collection: 'quads'}.merge(options)
136149
@db = ::Mongo::Connection.new(options[:host], options[:port]).db(options[:db])
137150
@db.authenticate(options[:user], options[:password]) if options[:user] && options[:password]
@@ -150,6 +163,7 @@ def initialize(options = {}, &block)
150163
def supports?(feature)
151164
case feature.to_sym
152165
when :graph_name then true
166+
when :validity then @options.fetch(:with_validity, true)
153167
else false
154168
end
155169
end

lib/rdf/mongo/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ def self.to_str() STRING end
1515

1616
##
1717
# @return [Array(Integer, Integer, Integer)]
18-
def self.to_a() [MAJOR, MINOR, TINY] end
18+
def self.to_a() STRING.split(".") end
1919
end
2020
end

spec/mongo_repository_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
describe RDF::Mongo::Repository do
88
before :each do
9-
@repository = RDF::Mongo::Repository.new() # TODO: Do you need constructor arguments?
9+
@load_durable = lambda {RDF::Mongo::Repository.new uri: "mongodb://localhost:27017/quadb/quads"}
10+
@repository = @load_durable.call
1011
@repository.coll.drop
1112
end
1213

0 commit comments

Comments
 (0)