Sha256: 530cb6c8cd82d8a06579416a797cf7ff04750bd8957878d24cfb41fdb8e58cca
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
module Spackle module Helpers module RubyProjectRoot class << self # Search recursively from the current working directory up for something # that looks like the root directory of a Ruby project. # # Returns the path to the found project dir, if any. Nil otherwise. # # Stops looking when it reaches the top of the tree, or the user's # home directory. # # Detects a project dir via any of: # * a config/environment.rb file # * a spec/spec_helper.rb file # * a features/step_definitions directory def search(directory) directory = File.expand_path(directory) while directory != '/' return directory if is_project_dir?(directory) directory = File.expand_path(directory + '/..') end nil end def is_project_dir?(path) File.exists?(File.join(path, "config/environment.rb")) || File.exists?(File.join(path, "spec/spec_helper.rb")) || File.directory?(File.join(path, "features/step_definitions")) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
spackle-0.0.1 | lib/spackle/helpers/ruby_project_root.rb |