class Scruber::QueueAdapters::Mongo::Page
Public Instance Methods
attrs()
click to toggle source
Generating hash with mongo doc attributes
@return [Hash] hash with page attributes
# 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()
click to toggle source
Delete record from Mongo
collection
@return [void]
# 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()
click to toggle source
# File lib/scruber/queue_adapters/mongo.rb, line 6 def id @options[:_id] || @id end
processed!()
click to toggle source
Mark page as processed by parser and save it
@return [void]
Calls superclass method
# 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={})
click to toggle source
Saving page to queue @param options [Hash] saving options @param save_options={} [type] [description]
@return [type] [description]
# File lib/scruber/queue_adapters/mongo.rb, line 16 def save(options={}, save_options={}) if id.blank? @queue.collection.insert_one(attrs) else if options[:new] @queue.collection.find_one_and_update( {"_id" => self.id }, {'$setOnInsert' => attrs }, {return_document: :after, upsert: true, projection: {_id: 1}}.merge(options) ) else @queue.collection.find_one_and_update( {"_id" => self.id }, {'$set' => attrs }, {return_document: :after, upsert: true, projection: {_id: 1}}.merge(options) ) end end end