module ImageOptim::Runner::GlobHelpers

Helper methods for glob

Constants

BRACE_REGEXP

Match inner curly braces in glob Negative lookbehind is not used as is not supported by ruby before 1.9

Public Class Methods

expand_braces(original_glob) click to toggle source

Expand curly braces in glob as fnmatch in ruby before 2.0 doesn't support them

# File lib/image_optim/runner/glob_helpers.rb, line 30
def expand_braces(original_glob)
  expanded = []
  unexpanded = [original_glob]
  while (glob = unexpanded.shift)
    if (m = BRACE_REGEXP.match(glob))
      m[2].split(',', -1).each do |variant|
        unexpanded << "#{m[1]}#{variant}#{m[3]}"
      end
    else
      expanded << glob
    end
  end
  expanded.uniq
end