Class: Scruber::QueueAdapters::Mongo::Page
- Inherits:
-
AbstractAdapter::Page
- Object
- AbstractAdapter::Page
- Scruber::QueueAdapters::Mongo::Page
- Defined in:
- lib/scruber/queue_adapters/mongo.rb
Instance Method Summary collapse
-
#attrs ⇒ Hash
Generating hash with mongo doc attributes.
-
#delete ⇒ void
Delete record from Mongo collection.
- #id ⇒ Object
-
#processed! ⇒ void
Mark page as processed by parser and save it.
-
#save(options = {}, save_options = {}) ⇒ type
Saving page to queue.
Instance Method Details
#attrs ⇒ Hash
Generating hash with mongo doc attributes
52 53 54 |
# File 'lib/scruber/queue_adapters/mongo.rb', line 52 def attrs @options.with_indifferent_access.except('id', '_id').merge(id.present? ? {_id: id} : {}).merge (instance_variables.select{|ivar| !(ivar.to_s =~ /\@_/) }-[:@options, :@queue]).inject({}){|acc,ivar| acc[ivar[1..-1]] = instance_variable_get(ivar);acc }.with_indifferent_access end |
#delete ⇒ void
This method returns an undefined value.
Delete record from Mongo collection
60 61 62 |
# File 'lib/scruber/queue_adapters/mongo.rb', line 60 def delete @queue.collection.find({"_id" => self.id }).delete_one if self.id.present? end |
#id ⇒ Object
6 7 8 |
# File 'lib/scruber/queue_adapters/mongo.rb', line 6 def id @options[:_id] || @id end |
#processed! ⇒ void
This method returns an undefined value.
Mark page as processed by parser and save it
40 41 42 43 44 45 46 |
# File 'lib/scruber/queue_adapters/mongo.rb', line 40 def processed! # Monkey patch for processing error pages. if @fetched_at == 0 @fetched_at = -1 end super end |
#save(options = {}, save_options = {}) ⇒ type
Saving page to queue
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/scruber/queue_adapters/mongo.rb', line 16 def save(={}, ={}) if id.blank? @queue.collection.insert_one(attrs) else if [:new] @queue.collection.find_one_and_update( {"_id" => self.id }, {'$setOnInsert' => attrs }, {return_document: :after, upsert: true, projection: {_id: 1}}.merge() ) else @queue.collection.find_one_and_update( {"_id" => self.id }, {'$set' => attrs }, {return_document: :after, upsert: true, projection: {_id: 1}}.merge() ) end end end |