From 24ff6becd0eaf3d9e4ab5b26cc122644526dfe3b Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Fri, 5 Sep 2014 01:35:22 +0200 Subject: [PATCH] add logging workers with options by file format --- lib/image_optim.rb | 15 +++++++++++++++ lib/image_optim/worker.rb | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/lib/image_optim.rb b/lib/image_optim.rb index 88621980..17b521ea 100644 --- a/lib/image_optim.rb +++ b/lib/image_optim.rb @@ -55,6 +55,8 @@ def initialize(options = {}) config.for_worker(klass) end + log_workers_by_format if verbose + config.assert_no_unused_options! end @@ -164,6 +166,19 @@ def env_path private + def log_workers_by_format + $stderr << "Workers by format:\n" + @workers_by_format.each do |format, workers| + $stderr << "#{format}:\n" + workers.each do |worker| + $stderr << " #{worker.class.bin_sym}:\n" + worker.options.each do |name, value| + $stderr << " #{name}: #{value.inspect}\n" + end + end + end + end + # Create hash with format mapped to list of workers sorted by run order def create_workers_by_format(&options_proc) by_format = {} diff --git a/lib/image_optim/worker.rb b/lib/image_optim/worker.rb index 19e9702d..b4b0e719 100644 --- a/lib/image_optim/worker.rb +++ b/lib/image_optim/worker.rb @@ -78,6 +78,13 @@ def initialize(image_optim, options = {}) assert_no_unknown_options!(options) end + # Return hash with worker options + def options + self.class.option_definitions.each_with_object({}) do |option, h| + h[option.name] = send(option.name) + end + end + # Optimize image at src, output at dst, must be overriden in subclass # return true on success def optimize(_src, _dst)