lib/tobox.rb in tobox-0.6.1 vs lib/tobox.rb in tobox-0.7.0

- old
+ new

@@ -2,38 +2,36 @@ require "sequel" require_relative "tobox/version" -require "mutex_m" - module Tobox class Error < StandardError; end EMPTY = [].freeze module Plugins + PLUGINS_MUTEX = Thread::Mutex.new @plugins = {} - @plugins.extend(Mutex_m) # Loads a plugin based on a name. If the plugin hasn't been loaded, tries to load # it from the load path under "httpx/plugins/" directory. # def self.load_plugin(name) h = @plugins - unless (plugin = h.synchronize { h[name] }) + unless (plugin = PLUGINS_MUTEX.synchronize { h[name] }) require "tobox/plugins/#{name}" - raise "Plugin #{name} hasn't been registered" unless (plugin = h.synchronize { h[name] }) + raise "Plugin #{name} hasn't been registered" unless (plugin = PLUGINS_MUTEX.synchronize { h[name] }) end plugin end # Registers a plugin (+mod+) in the central store indexed by +name+. # def self.register_plugin(name, mod) h = @plugins - h.synchronize { h[name] = mod } + PLUGINS_MUTEX.synchronize { h[name] = mod } end end # when using batch sizes higher than 1, this method can be used to signal multiple errors # for a subset of the events which may have failed processing; these events are identified @@ -52,14 +50,15 @@ # end # # Tobox.raise_batch_error(batch_errors) # end def self.raise_batch_errors(batch_errors) - unless batch_errors.respond_to?(:to_hash) && batch_errors.all? { |k, v| k.is_a?(Integer) && v.is_a?(Exception) } - raise "batch errors must be an array of index-to-exception tuples" + batch_errors = Hash.try_convert(batch_errors) + unless batch_errors && batch_errors.all? { |k, v| k.is_a?(Integer) && v.is_a?(Exception) } + raise Error, "batch errors must be an array of index-to-exception tuples" end - throw(:tobox_batch_errors, batch_errors.to_h) + throw(:tobox_batch_errors, batch_errors) end end require_relative "tobox/fetcher" require_relative "tobox/worker"