Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save moos3/1020958 to your computer and use it in GitHub Desktop.

Select an option

Save moos3/1020958 to your computer and use it in GitHub Desktop.
Repo parser
class Repo
attr_accessor :repo, :scm, :path, :files, :directories, :pattern
# setup new repo
def initialize(repo,scm,path,pattern)
@repo = repo
@scm = scm
@path = path
@files = Array.new
@directories = Array.new
@pattern = pattern
end
# get all directories
def getDirectories(path)
@directories << Dir[path+'/**/*/']
end
# get all files in a given that matches the given pattern
def getFiles(directory)
Dir[directory].sort.each do |name|
if File.file?(name) and name[@pattern]
@files = name
end
end
end
end
repo = Repo.new('include','svn', './include/', /.+.\php|inc|js|class$/)
repo.getDirectories(repo.path)
puts repo.directories
@moos3
Copy link
Copy Markdown
Author

moos3 commented Jun 11, 2011

class Repo
  attr_accessor :repo, :scm, :path, :files, :directories, :pattern

  # setup new repo
  def initialize(repo,scm,path,pattern)
    @repo = repo
    @scm = scm
    @path = path
    @files = Array.new
    @directories = Array.new
    @pattern = pattern
  end

  # get all directories  
  def getDirectories(path)
    require 'find'
    Find.find('#{path}') do |f|
      p Dir['**/*.*']
    end
    p.each do |entry|
      if File.directory?(entry)
        @directories = p
      end
    end
  end

  # get all files in a given that matches the given pattern
  def getFiles(direcotry)
    Dir[directory].sort.each do |name|
      if File.file?(name) and name[@pattern]
        @files = name
      end
    end
  end

end

repo = Repo.new('include','svn', './include/', /.+.\php|inc|js|class$/)

repo.getDirectories(repo.path)
puts repo.directories

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment