Sha256: 96fb1c21093cc42b260f6d7c67cf54435ffc18f947975f10bc9fccf493a4e5df

Contents?: true

Size: 1.29 KB

Versions: 27

Compression:

Stored size: 1.29 KB

Contents

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

        # 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

27 entries across 27 versions & 3 rubygems

Version Path
image_optim-0.26.3 lib/image_optim/runner/glob_helpers.rb
image_optim-0.26.2 lib/image_optim/runner/glob_helpers.rb
discourse_image_optim-0.26.2 lib/image_optim/runner/glob_helpers.rb
discourse_image_optim-0.26.1 lib/image_optim/runner/glob_helpers.rb
image_optim-0.26.1 lib/image_optim/runner/glob_helpers.rb
image_optim-0.26.0 lib/image_optim/runner/glob_helpers.rb
image_optim-0.25.0 lib/image_optim/runner/glob_helpers.rb
discourse_image_optim-0.24.5 lib/image_optim/runner/glob_helpers.rb
image_optim-0.24.3 lib/image_optim/runner/glob_helpers.rb
discourse_image_optim-0.24.4 lib/image_optim/runner/glob_helpers.rb
image_optim-0.24.2 lib/image_optim/runner/glob_helpers.rb
image_optim-0.24.1 lib/image_optim/runner/glob_helpers.rb
image_optim-0.24.0 lib/image_optim/runner/glob_helpers.rb
image_optim-0.23.0 lib/image_optim/runner/glob_helpers.rb
image_optim-0.22.1 lib/image_optim/runner/glob_helpers.rb
image_optim-0.22.0 lib/image_optim/runner/glob_helpers.rb
openstreetmap-image_optim-0.21.0.1 lib/image_optim/runner/glob_helpers.rb
image_optim-0.21.0 lib/image_optim/runner/glob_helpers.rb
image_optim-0.20.2 lib/image_optim/runner/glob_helpers.rb
image_optim-0.20.1 lib/image_optim/runner/glob_helpers.rb