lib/pupa/processor.rb in pupa-0.0.13 vs lib/pupa/processor.rb in pupa-0.1.0
- old
+ new
@@ -1,45 +1,44 @@
require 'pupa/processor/client'
require 'pupa/processor/dependency_graph'
require 'pupa/processor/helper'
-require 'pupa/processor/persistence'
+require 'pupa/processor/connection'
require 'pupa/processor/document_store'
require 'pupa/processor/yielder'
-require 'pupa/processor/document_store/file_store'
-require 'pupa/processor/document_store/redis_store'
-
module Pupa
# An abstract processor class from which specific processors inherit.
class Processor
extend Forwardable
include Helper
class_attribute :tasks
self.tasks = []
- attr_reader :report, :store, :client, :options
+ attr_reader :report, :store, :connection, :client, :options
def_delegators :@logger, :debug, :info, :warn, :error, :fatal
# @param [String] output_dir the directory or Redis address
# (e.g. `redis://localhost:6379`) in which to dump JSON documents
+ # @param [Boolean] pipelined whether to dump JSON documents all at once
# @param [String] cache_dir the directory or Memcached address
# (e.g. `memcached://localhost:11211`) in which to cache HTTP responses
# @param [Integer] expires_in the cache's expiration time in seconds
- # @param [Boolean] pipelined whether to dump JSON documents all at once
+ # @param [String] database_url the database URL
# @param [Boolean] validate whether to validate JSON documents
# @param [String] level the log level
# @param [String,IO] logdev the log device
# @param [Hash] options criteria for selecting the methods to run
- def initialize(output_dir, cache_dir: nil, expires_in: 86400, pipelined: false, validate: true, level: 'INFO', logdev: STDOUT, options: {})
- @store = DocumentStore.new(output_dir, pipelined: pipelined)
- @client = Client.new(cache_dir: cache_dir, expires_in: expires_in, level: level)
- @logger = Logger.new('pupa', level: level, logdev: logdev)
- @validate = validate
- @options = options
- @report = {}
+ def initialize(output_dir, pipelined: false, cache_dir: nil, expires_in: 86400, database_url: 'mongodb://localhost:27017/pupa', validate: true, level: 'INFO', logdev: STDOUT, options: {})
+ @store = DocumentStore.new(output_dir, pipelined: pipelined)
+ @client = Client.new(cache_dir: cache_dir, expires_in: expires_in, level: level)
+ @connection = Connection.new(database_url)
+ @logger = Logger.new('pupa', level: level, logdev: logdev)
+ @validate = validate
+ @options = options
+ @report = {}
end
# Retrieves and parses a document with a GET request.
#
# @param [String] url a URL to an HTML document
@@ -367,11 +366,11 @@
object.foreign_objects.each do |property|
value = object[property]
if value.present?
foreign_object = ForeignObject.new(value)
resolve_foreign_keys(foreign_object, map)
- document = Persistence.find(foreign_object.to_h)
+ document = connection.find(foreign_object.to_h)
if document
object["#{property}_id"] = document['_id']
else
raise Errors::MissingDatabaseIdError, "couldn't resolve foreign object: #{property} #{value}"
@@ -380,10 +379,10 @@
end
end
# @param [Object] object an object
def import_object(object)
- inserted, id = Persistence.new(object).save
+ inserted, id = connection.save(object)
@report[:import][object._type] ||= Hash.new(0)
if inserted
@report[:import][object._type][:insert] += 1
else
@report[:import][object._type][:update] += 1