Class: Wgit::Database::DatabaseAdapter
- Inherits:
-
Object
- Object
- Wgit::Database::DatabaseAdapter
- Includes:
- Assertable
- Defined in:
- lib/wgit/database/database_adapter.rb
Overview
The parent DatabaseAdapter class that should be inherited from when creating an underlying Database adapter implementation class e.g. Wgit::Database::MongoDB.
Listed in this class are the methods that an implementer class must implement to work with Wgit. Failure to do so will result in a NotImplementedError being raised.
While not required, implementing the method #search_fields=(fields)
in an
adapter class will allow Wgit::Model.set_search_fields
to call
it. This allows the search fields to be set in one method call, from within
the Wgit::Model class. See this method's docs for more info.
Also listed in this class are common helper methods available to all Database implementer subclasses.
Constant Summary collapse
- NOT_IMPL_ERR =
The NotImplementedError message that gets raised if an implementor class doesn't implement a method required by Wgit.
"The DatabaseAdapter class you're using hasn't \ implemented this method"
Constants included from Assertable
Assertable::DEFAULT_DUCK_FAIL_MSG, Assertable::DEFAULT_REQUIRED_KEYS_MSG, Assertable::DEFAULT_TYPE_FAIL_MSG, Assertable::MIXED_ENUMERABLE_MSG, Assertable::NON_ENUMERABLE_MSG
Instance Method Summary collapse
-
#bulk_upsert(objs) ⇒ Integer
Bulk upserts the objects in the database collection.
-
#empty ⇒ Integer
Deletes everything in the urls and documents collections.
-
#initialize(connection_string = nil) ⇒ DatabaseAdapter
constructor
Initializes a DatabaseAdapter instance.
-
#search(query, case_sensitive: false, whole_sentence: true, limit: 10, skip: 0) {|doc| ... } ⇒ Array<Wgit::Document>
Searches the database's Documents for the given query.
-
#size ⇒ Integer
Returns the current size of the database.
-
#uncrawled_urls(limit: 0, skip: 0) {|url| ... } ⇒ Array<Wgit::Url>
Returns Url records that haven't yet been crawled.
-
#upsert(obj) ⇒ Boolean
Inserts or updates the object in the database.
Methods included from Assertable
#assert_arr_types, #assert_common_arr_types, #assert_required_keys, #assert_respond_to, #assert_types
Constructor Details
#initialize(connection_string = nil) ⇒ DatabaseAdapter
Initializes a DatabaseAdapter instance.
The implementor class should establish a DB connection here using the
given connection_string, falling back to ENV['WGIT_CONNECTION_STRING']
.
Don't forget to call super
.
44 |
# File 'lib/wgit/database/database_adapter.rb', line 44 def initialize(connection_string = nil); end |
Instance Method Details
#bulk_upsert(objs) ⇒ Integer
Bulk upserts the objects in the database collection. You cannot mix collection objs types, all must be Urls or Documents.
105 106 107 |
# File 'lib/wgit/database/database_adapter.rb', line 105 def bulk_upsert(objs) raise NotImplementedError, NOT_IMPL_ERR end |
#empty ⇒ Integer
Deletes everything in the urls and documents collections.
77 78 79 |
# File 'lib/wgit/database/database_adapter.rb', line 77 def empty raise NotImplementedError, NOT_IMPL_ERR end |
#search(query, case_sensitive: false, whole_sentence: true, limit: 10, skip: 0) {|doc| ... } ⇒ Array<Wgit::Document>
Searches the database's Documents for the given query. The
Wgit::Model.search_fields
should be searched for matches
against the given query. Documents should be sorted starting with the
most relevant. Each returned Document should have it's score
field set
for relevance.
68 69 70 71 72 |
# File 'lib/wgit/database/database_adapter.rb', line 68 def search( query, case_sensitive: false, whole_sentence: true, limit: 10, skip: 0 ) raise NotImplementedError, NOT_IMPL_ERR end |
#size ⇒ Integer
Returns the current size of the database.
49 50 51 |
# File 'lib/wgit/database/database_adapter.rb', line 49 def size raise NotImplementedError, NOT_IMPL_ERR end |
#uncrawled_urls(limit: 0, skip: 0) {|url| ... } ⇒ Array<Wgit::Url>
Returns Url records that haven't yet been crawled.
87 88 89 |
# File 'lib/wgit/database/database_adapter.rb', line 87 def uncrawled_urls(limit: 0, skip: 0) raise NotImplementedError, NOT_IMPL_ERR end |
#upsert(obj) ⇒ Boolean
Inserts or updates the object in the database.
95 96 97 |
# File 'lib/wgit/database/database_adapter.rb', line 95 def upsert(obj) raise NotImplementedError, NOT_IMPL_ERR end |