M lib/wordnet.rb +1 -1
@@ 15,7 15,7 @@ module WordNet
# Release version
- VERSION = '1.0.1'
+ VERSION = '1.1.0'
# VCS revision
REVISION = %q$Revision: $
M lib/wordnet/lexicon.rb +9 -24
@@ 9,6 9,13 @@ require 'wordnet' unless defined?( WordN
require 'wordnet/constants'
require 'wordnet/model'
+# Try to load the default database gem, ignoring it if it's not installed.
+begin
+ require 'wordnet-defaultdb'
+rescue LoadError
+ # No-op
+end
+
# WordNet lexicon class - provides access to the WordNet lexical
# database, and provides factory methods for looking up words[rdoc-ref:WordNet::Word]
@@ 129,30 136,8 @@ class WordNet::Lexicon
### Get the Sequel URI of the default database, if it's installed.
def self::default_db_uri
- self.log.debug "Fetching the default db URI"
-
- # Try to load the default database gem, ignoring it if it's not installed.
- begin
- gem 'wordnet-defaultdb'
- rescue Gem::LoadError
- end
-
- # Now try the gem datadir first, and fall back to a local installation of the
- # default db
- datadir = nil
- if Gem.datadir( 'wordnet-defaultdb' )
- datadir = Pathname( Gem.datadir('wordnet-defaultdb') )
- else
- self.log.warn " no defaultdb gem; looking for the development database"
- datadir = Pathname( __FILE__ ).dirname.parent.parent +
- 'wordnet-defaultdb/data/wordnet-defaultdb'
- end
-
- dbfile = datadir + 'wordnet31.sqlite'
- self.log.debug " dbfile is: %s" % [ dbfile ]
-
- if dbfile.exist?
- return "sqlite:#{dbfile}"
+ if defined?( WordNet::DefaultDB )
+ return WordNet::DefaultDB.uri
else
return nil
end
M spec/helpers.rb +3 -0
@@ 5,9 5,12 @@
# SimpleCov test coverage reporting; enable this using the :coverage rake task
require 'simplecov' if ENV['COVERAGE']
+$LOAD_PATH.unshift( 'wordnet-defaultdb/lib' )
+
require 'rspec'
require 'loggability/spechelpers'
require 'wordnet'
+require 'wordnet/defaultdb'
### RSpec helper functions.
M spec/wordnet/lexicon_spec.rb +1 -36
@@ 16,44 16,9 @@ describe WordNet::Lexicon do
end
- context "the default_db_uri method" do
-
- it "uses the wordnet-defaultdb database gem (if available)" do
- expect( Gem ).to receive( :datadir ).with( 'wordnet-defaultdb' ).at_least( :once ).
- and_return( '/tmp/foo' )
- expect( FileTest ).to receive( :exist? ).with( '/tmp/foo/wordnet31.sqlite' ).
- and_return( true )
-
- expect( WordNet::Lexicon.default_db_uri ).to eq( "sqlite:/tmp/foo/wordnet31.sqlite" )
- end
-
- it "uses the development version of the wordnet-defaultdb database gem if it's " +
- "not installed" do
- expect( Gem ).to receive( :datadir ).with( 'wordnet-defaultdb' ).
- and_return( nil )
- expect( FileTest ).to receive( :exist? ).with( devdb.to_s ).
- and_return( true )
-
- expect( WordNet::Lexicon.default_db_uri ).to eq( "sqlite:#{devdb}" )
- end
-
- it "returns nil if there is no default database" do
- expect( Gem ).to receive( :datadir ).with( 'wordnet-defaultdb' ).
- and_return( nil )
- expect( FileTest ).to receive( :exist? ).with( devdb.to_s ).
- and_return( false )
-
- expect( WordNet::Lexicon.default_db_uri ).to be_nil()
- end
-
- end
-
-
it "raises an exception if created with no arguments and no defaultdb is available" do
- expect( Gem ).to receive( :datadir ).with( 'wordnet-defaultdb' ).at_least( :once ).
+ expect( WordNet::DefaultDB ).to receive( :uri ).at_least( :once ).
and_return( nil )
- expect( FileTest ).to receive( :exist? ).with( devdb.to_s ).
- and_return( false )
expect {
WordNet::Lexicon.new
M wordnet-defaultdb/lib/wordnet-defaultdb.rb +3 -38
@@ 1,40 1,5 @@
-#!/usr/bin/env ruby
-
-require 'pathname'
-
-# This gem is a container for the default WordNetSQL database files required for
-# the 'wordnet' gem. It's mostly just a wrapper around the Sqlite database from:
-#
-# http://sqlunet.sourceforge.net/
-#
-# == Author/s
-#
-# * Michael Granger <ged@FaerieMUD.org>
-#
-module WordNet
- module DefaultDB
-
- # Library version constant
- VERSION = '2.0.0'
+# -*- ruby -*-
+#encoding: utf-8
- # Version-control revision constant
- REVISION = %q$Revision$
+require 'wordnet/defaultdb'
- # The data directory which contains the database file
- DATA_DIR = if ENV['WORDNET_DEFAULTDB_DATADIR']
- Pathname( ENV['WORDNET_DEFAULTDB_DATADIR'] )
- elsif Gem.datadir( 'wordnet-defaultdb' ) && File.directory?( Gem.datadir('wordnet-defaultdb') )
- Pathname( Gem.datadir('wordnet-defaultdb') )
- else
- Pathname( __FILE__ ).dirname.parent + 'data/wordnet-defaultdb'
- end
-
-
- ### The Sequel URI for the database
- def self::uri
-
- end
-
- end # module DefaultDB
-end # module Wordnet
-
A => wordnet-defaultdb/lib/wordnet/defaultdb.rb +41 -0
@@ 0,0 1,41 @@
+# -*- ruby -*-
+#encoding: utf-8
+
+require 'wordnet'
+require 'pathname'
+
+# This gem is a container for the default database files required for the
+# 'wordnet' gem. It's mostly just a wrapper around the Sqlite database from
+# SQLUNet:
+#
+# http://sqlunet.sourceforge.net/
+#
+module WordNet::DefaultDB
+
+ # Library version constant
+ VERSION = '2.0.0'
+
+ # Version-control revision constant
+ REVISION = %q$Revision$
+
+ # The data directory which contains the database file
+ DATA_DIR = if ENV['WORDNET_DEFAULTDB_DATADIR']
+ Pathname( ENV['WORDNET_DEFAULTDB_DATADIR'] )
+ elsif Gem.datadir( 'wordnet-defaultdb' ) && File.directory?( Gem.datadir('wordnet-defaultdb') )
+ Pathname( Gem.datadir('wordnet-defaultdb') )
+ else
+ Pathname( __FILE__ ).dirname.parent.parent + 'data/wordnet-defaultdb'
+ end
+
+ # The name of the bundled Sqlite database
+ DATABASE_FILENAME = 'wordnet31.sqlite'
+
+
+ ### Return the Sequel URI for the database
+ def self::uri
+ dbfile = WordNet::DefaultDB::DATA_DIR + DATABASE_FILENAME
+ return nil unless dbfile.exist?
+ return "sqlite:%s" % [ dbfile ]
+ end
+
+end # module WordNet::DefaultDB
A => wordnet-defaultdb/spec/spec_helper.rb +32 -0
@@ 0,0 1,32 @@
+#!/usr/bin/env rspec
+
+BEGIN {
+ require 'pathname'
+ $LOAD_PATH << Pathname( __FILE__ ).dirname.parent + 'lib'
+}
+
+require 'rspec'
+require 'wordnet/defaultdb'
+
+
+RSpec.configure do |config|
+ config.expect_with :rspec do |expectations|
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
+ end
+
+ config.mock_with :rspec do |mocks|
+ mocks.verify_partial_doubles = true
+ end
+
+ config.shared_context_metadata_behavior = :apply_to_host_groups
+
+ config.filter_run_when_matching :focus
+ config.example_status_persistence_file_path = "spec/.state"
+ config.disable_monkey_patching!
+ config.warnings = true
+
+ config.profile_examples = 10
+ config.order = :random
+ Kernel.srand config.seed
+end
+
A => wordnet-defaultdb/spec/wordnet/defaultdb_spec.rb +25 -0
@@ 0,0 1,25 @@
+#!/usr/bin/env rspec -cfd
+
+require_relative '../spec_helper'
+
+require 'rspec'
+
+require 'wordnet'
+require 'wordnet/defaultdb'
+
+
+RSpec.describe WordNet::DefaultDB do
+
+ it "knows what the URL of its database is" do
+ expect( described_class.uri ).to start_with( 'sqlite:' ).and( end_with('wordnet31.sqlite') )
+ end
+
+
+ it "returns nil if its data file does not exist" do
+ expect( FileTest ).to receive( :exist? ).with( a_string_ending_with('wordnet31.sqlite') ).
+ and_return( false )
+ expect( described_class.uri ).to be_nil
+ end
+
+end
+