Created
May 4, 2012 00:55
-
-
Save EricR/2590782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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