Class: Xapit::Config
- Inherits:
-
Object
- Object
- Xapit::Config
- Defined in:
- lib/xapit/config.rb
Overview
Singleton class for storing Xapit configuration settings. Currently this only includes the database path.
Class Attribute Summary collapse
-
.options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .breadcrumb_facets? ⇒ Boolean
-
.close_database ⇒ Object
Clear the current database from memory.
-
.database ⇒ Object
Fetch Xapian::Database object at configured path.
- .default_options ⇒ Object
- .indexer ⇒ Object
-
.path ⇒ Object
The configured path to the database.
- .query_parser ⇒ Object
-
.remove_database ⇒ Object
Removes the configured database file and clears the stored one in memory.
-
.setup(options = {}) ⇒ Object
See Xapit#setup.
-
.setup? ⇒ Boolean
See if setup options are already set.
- .spelling? ⇒ Boolean
- .stemming ⇒ Object
-
.writable_database ⇒ Object
Fetch Xapian::WritableDatabase object at configured path.
Class Attribute Details
.options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/xapit/config.rb', line 5 def @options end |
Class Method Details
.breadcrumb_facets? ⇒ Boolean
51 52 53 |
# File 'lib/xapit/config.rb', line 51 def @options[:breadcrumb_facets] end |
.close_database ⇒ Object
Clear the current database from memory. Unfortunately this is a hack because Xapian doesn’t provide a “close” method on the database. We just have to hope no other references are lying around.
77 78 79 80 81 |
# File 'lib/xapit/config.rb', line 77 def close_database @database = nil @writable_database = nil GC.start end |
.database ⇒ Object
Fetch Xapian::Database object at configured path. Database is stored in memory.
56 57 58 |
# File 'lib/xapit/config.rb', line 56 def database @writable_database || (@database ||= Xapian::Database.new(path)) end |
.default_options ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/xapit/config.rb', line 16 def { :indexer => SimpleIndexer, :query_parser => ClassicQueryParser, :spelling => true, :stemming => "english" } end |
.indexer ⇒ Object
39 40 41 |
# File 'lib/xapit/config.rb', line 39 def indexer @options[:indexer] end |
.path ⇒ Object
The configured path to the database.
31 32 33 |
# File 'lib/xapit/config.rb', line 31 def path @options[:database_path] end |
.query_parser ⇒ Object
35 36 37 |
# File 'lib/xapit/config.rb', line 35 def query_parser @options[:query_parser] end |
.remove_database ⇒ Object
Removes the configured database file and clears the stored one in memory.
68 69 70 71 72 |
# File 'lib/xapit/config.rb', line 68 def remove_database # this can be a bit dangers, maybe do some checking here first? FileUtils.rm_rf(path) if File.exist? path @database = nil @writable_database = nil end |
.setup(options = {}) ⇒ Object
See Xapit#setup
8 9 10 11 12 13 14 |
# File 'lib/xapit/config.rb', line 8 def setup( = {}) if @options && [:database_path] != @options[:database_path] @database = nil @writable_database = nil end @options = .reverse_merge() end |
.setup? ⇒ Boolean
See if setup options are already set.
26 27 28 |
# File 'lib/xapit/config.rb', line 26 def setup? @options end |
.spelling? ⇒ Boolean
43 44 45 |
# File 'lib/xapit/config.rb', line 43 def spelling? @options[:spelling] end |
.stemming ⇒ Object
47 48 49 |
# File 'lib/xapit/config.rb', line 47 def stemming @options[:stemming] end |
.writable_database ⇒ Object
Fetch Xapian::WritableDatabase object at configured path. Database is stored in memory. Creates the database directory if needed.
62 63 64 65 |
# File 'lib/xapit/config.rb', line 62 def writable_database FileUtils.mkdir_p(File.dirname(path)) unless File.exist?(File.dirname(path)) @writable_database ||= Xapian::WritableDatabase.new(path, Xapian::DB_CREATE_OR_OPEN) end |