Module: Wgit::Model
- Defined in:
- lib/wgit/database/model.rb
Overview
Module used to build the database collection objects, forming a data model.
Class Method Summary collapse
-
.common_insert_data ⇒ Hash
Common fields when inserting a record into the DB.
-
.common_update_data ⇒ Hash
Common fields when updating a record in the DB.
-
.document(doc) ⇒ Hash
The data model for a Wgit::Document collection object.
-
.select_bson_types(model_hash) ⇒ Hash
Returns the model having removed non bson types (for use with MongoDB).
-
.url(url) ⇒ Hash
The data model for a Wgit::Url collection object and for an embedded 'url' inside a Wgit::Document collection object.
Class Method Details
.common_insert_data ⇒ Hash
Common fields when inserting a record into the DB.
36 37 38 39 40 41 |
# File 'lib/wgit/database/model.rb', line 36 def self.common_insert_data { date_added: Wgit::Utils.time_stamp, date_modified: Wgit::Utils.time_stamp } end |
.common_update_data ⇒ Hash
Common fields when updating a record in the DB.
46 47 48 49 50 |
# File 'lib/wgit/database/model.rb', line 46 def self.common_update_data { date_modified: Wgit::Utils.time_stamp } end |
.document(doc) ⇒ Hash
The data model for a Wgit::Document collection object.
24 25 26 27 28 29 30 31 |
# File 'lib/wgit/database/model.rb', line 24 def self.document(doc) raise 'doc must respond_to? :to_h' unless doc.respond_to?(:to_h) model = doc.to_h(include_html: false, include_score: false) model['url'] = url(doc.url) # Expand Url String into full object. select_bson_types(model) end |
.select_bson_types(model_hash) ⇒ Hash
Returns the model having removed non bson types (for use with MongoDB).
56 57 58 |
# File 'lib/wgit/database/model.rb', line 56 def self.select_bson_types(model_hash) model_hash.select { |_k, v| v.respond_to?(:bson_type) } end |
.url(url) ⇒ Hash
The data model for a Wgit::Url collection object and for an embedded 'url' inside a Wgit::Document collection object.
13 14 15 16 17 18 |
# File 'lib/wgit/database/model.rb', line 13 def self.url(url) raise 'url must respond_to? :to_h' unless url.respond_to?(:to_h) model = url.to_h select_bson_types(model) end |