Skip to content

Instantly share code, notes, and snippets.

@EricR
Created May 4, 2012 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricR/2590782 to your computer and use it in GitHub Desktop.
Save EricR/2590782 to your computer and use it in GitHub Desktop.
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: raptor [app_directory] [options]"
end.parse!
class ProjectParser
def initialize
set_project_directory
@directories = get_project_directories
puts "*** Getting list of project files...\n\n"
@directories.each do |dir, contents|
puts "--- #{dir} ---"
puts contents.map { |c| " => #{c}" }
end
end
private
def set_project_directory
directory_option = "#{ARGV[0]}/app/"
if directory_option && File.directory?(directory_option)
Dir.chdir(directory_option)
elsif directory_option && !File.directory?(directory_option)
raise "Supplied Rails project directory doesn't seem to exist!"
end
end
def get_project_directories
directories = {}
[:controllers, :models].each do |dir|
unless File.directory?(dir.to_s)
raise "Could not find #{dir} directory! Are we in a Rails app?"
end
directories[dir] = recursive_directory_crawl(dir.to_s, node = nil)
end
directories
end
def recursive_directory_crawl(dir, node)
tree = branches = []
Dir.foreach(dir) do |branch|
next if (branch == ".." || branch == ".")
full_path = File.join(dir, branch)
if File.directory?(full_path)
recursive_directory_crawl(full_path, branch).each do |node|
branches << "#{branch}/#{node}"
end
else
branches << branch if branch =~ /\.rb$/
end
end
return tree
end
end
project = ProjectParser.new
raise project.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment