class Sftp::Sync::GlobBuilder

Public Class Methods

new(line) click to toggle source
# File lib/sftp/sync/glob_builder.rb, line 7
def initialize(line)
  @line = line
end

Public Instance Methods

globs() click to toggle source
# File lib/sftp/sync/glob_builder.rb, line 14
def globs

  line = @line.dup

  out = []

  #!pattern
  if negative?
    line.slice!(0,1) # trim negative token
  end

  ## allow for escaping of !
  if /^\\!/.match(line)
    line.slice!(0,1)
  end

  #

 # puts "LINE #{line} #{Globs::Glob.new(line).valid?}"


  unless Globs::Glob.new(line).valid?

    if /^\/[\w.]/.match(line)  #/a
      line.slice!(0,1)


      if /\/$/.match(line) #/a/ => a/**
        out << (line + '**/**')

      else # /\w$/.match(line) #/a => a, a/**
        out << line
        out << (line + '/**/**')

      end

    elsif /^[\w.]/.match(line) #a

    
      if (/\/$/.match(line)) #a/ => **/a/**, a/**
     
        out << (line + '**/**')
        out << ('**/' + line + '**/**')
      else #/\w$/.match(line) #a => a, **/a, a/**
        out << line
        out << (line + '/**/**')
        out << ( '**/' + line )
        out << ('**/' + line + '/**/**')

      end
    else

      if (/\/$/.match(line)) #a/ => a/**, a/**
     
        out << (line + '**/**')

      else
        out << line
        out << (line + '/**/**')
      end
    end
    
  else


    if /^\/\*\.\w+/.match(line)  #/*.xcv
      line.slice!(0,1) 
      out << line
    elsif /^\*\.\w+/.match(line)  #*.xcv
      out << line
      out << ( '**/' + line)
    else
  
      if /\w$/.match(line) #*/a => */a, */a/**
        out << line
        out << (line + '/**/**')

      elsif (/\/$/.match(line)) #*/a/ => */a/**
        out << (line + '**/**')
    
      elsif /\*$/.match(line) #a/* =>
        out << line
        out << (line + '/**/**') 
      else
         out << line
      end

    end



  end


  out
end
negative?() click to toggle source
# File lib/sftp/sync/glob_builder.rb, line 111
def negative?
  @line[0] == "!"
end