script/worker_analysis in image_optim-0.18.0 vs script/worker_analysis in image_optim-0.19.0

- old
+ new

@@ -1,9 +1,9 @@ #!/usr/bin/env ruby # encoding: UTF-8 -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +require 'bundler/setup' require 'image_optim' require 'image_optim/cmd' require 'progress' require 'shellwords' @@ -139,16 +139,20 @@ end end # Delegate to worker with short id class WorkerVariant < DelegateClass(ImageOptim::Worker) - attr_reader :klass, :id + attr_reader :cons_id, :id def initialize(klass, image_optim, options) - @klass = klass + allow_consecutive_on = Array(options.delete(:allow_consecutive_on)) @image_optim = image_optim - @id = "#{klass.bin_sym}#{options unless options.empty?}" + @id = klass.bin_sym.to_s + unless options.empty? + @id << "(#{options.map{ |k, v| "#{k}:#{v.inspect}" }.join(', ')})" + end __setobj__(klass.new(image_optim, options)) + @cons_id = [klass, allow_consecutive_on.map{ |key| [key, send(key)] }] end def cache_etag [ id, @@ -268,11 +272,11 @@ chain_result = ChainResult.new(src.format, steps) chain_result.difference = difference_with(result_image) block.call(chain_result) - workers_left = workers.reject{ |w| w.klass == worker.klass } + workers_left = workers.reject{ |w| w.cons_id == worker.cons_id } run_workers(result_image, workers_left, chain_result, &block) end end def run_worker(src, worker) @@ -425,20 +429,22 @@ image_optim = ImageOptim.new @workers_by_format = Hash.new{ |h, k| h[k] = [] } ImageOptim::Worker.klasses.each do |klass| worker_options_config = option_variants.delete(klass.bin_sym) || {} + allow_consecutive_on = worker_options_config.delete(:allow_consecutive_on) worker_option_variants = case worker_options_config when Array worker_options_config when Hash worker_options_config.variants else fail "Array or Hash expected, got #{worker_options_config}" end worker_option_variants.each do |options| options = HashHelpers.deep_symbolise_keys(options) + options[:allow_consecutive_on] = allow_consecutive_on worker = WorkerVariant.new(klass, image_optim, options) puts worker.id worker.image_formats.each do |format| @workers_by_format[format] << worker end @@ -515,9 +521,13 @@ - progressive: true - progressive: false optipng: # 6 worker variants by combining options level: [6, 7] interlace: [true, false, nil] + gifsicle: # allow variants with different interlace to run consecutively + allow_consecutive_on: interlace + interlace: [true, false] + careful: [true, false] # other workers will be used with default options HELP end analyser.analyse(ARGV)