module Condenser::Rails::Utils
Constants
- END_OF_STRING
- NO_LEADING_DOT
- START_OF_FILENAME
Public Class Methods
glob_to_regex(glob_string)
click to toggle source
# File lib/condenser/rails/utils.rb, line 24 def self.glob_to_regex(glob_string) chars = smoosh(glob_string.split('')) curlies = 0 escaping = false string = chars.map do |char| if escaping escaping = false char else case char when '**' "([^/]+/)*" when '*' ".*" when "?" "." when "." "\\." when "{" curlies += 1 "(" when "}" if curlies > 0 curlies -= 1 ")" else char end when "," if curlies > 0 "|" else char end when "\\" escaping = true "\\" else char end end end.join Regexp.new(START_OF_FILENAME + string + END_OF_STRING) end
smoosh(chars)
click to toggle source
# File lib/condenser/rails/utils.rb, line 9 def self.smoosh chars out = [] until chars.empty? char = chars.shift if char == "*" and chars.first == "*" chars.shift chars.shift if chars.first == "/" out.push("**") else out.push(char) end end out end