Skip to content

Commit

Permalink
add logging workers with options by file format
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Sep 4, 2014
1 parent bac1187 commit 24ff6be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/image_optim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def initialize(options = {})
config.for_worker(klass)
end

log_workers_by_format if verbose

config.assert_no_unused_options!
end

Expand Down Expand Up @@ -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 = {}
Expand Down
7 changes: 7 additions & 0 deletions lib/image_optim/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 24ff6be

Please sign in to comment.