Sha256: 6998a7b26c4b811455229b3c988168d3139d50b49a4671aac187bcddfcabdc84

Contents?: true

Size: 1.33 KB

Versions: 12

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

class ImageOptim
  class Runner
    # Helper methods for glob
    module GlobHelpers
      class << self
        # Match inner curly braces in glob
        # Negative lookbehind is not used as is not supported by ruby before 1.9
        BRACE_REGEXP = /
          \A
          (
            (?:.*[^\\]|)  # anything ending not with slash or nothing
            (?:\\\\)*     # any number of self escaped slashes
          )
          \{              # open brace
          (
            (?:|.*?[^\\]) # nothing or non greedy anything ending not with slash
            (?:\\\\)*     # any number of self escaped slashes
          )
          \}              # close brace
          (
            .*            # what is left
          )
          \z
        /x.freeze

        # Expand curly braces in glob as fnmatch in ruby before 2.0 doesn't
        # support them
        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
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
image_optim-0.31.4 lib/image_optim/runner/glob_helpers.rb
image_optim-0.31.3 lib/image_optim/runner/glob_helpers.rb
image_optim-0.31.2 lib/image_optim/runner/glob_helpers.rb
image_optim-0.31.1 lib/image_optim/runner/glob_helpers.rb
image_optim-0.31.0 lib/image_optim/runner/glob_helpers.rb
image_optim-0.30.0 lib/image_optim/runner/glob_helpers.rb
image_optim-0.29.0 lib/image_optim/runner/glob_helpers.rb
image_optim-0.28.0 lib/image_optim/runner/glob_helpers.rb
image_optim-0.27.1 lib/image_optim/runner/glob_helpers.rb
image_optim-0.27.0 lib/image_optim/runner/glob_helpers.rb
image_optim-0.26.5 lib/image_optim/runner/glob_helpers.rb
image_optim-0.26.4 lib/image_optim/runner/glob_helpers.rb