module Savvy::RootFinder
Constants
- ROOT_FILES
Something that, given a directory possessing such a file, would make it look like a potential root directory.
Public Class Methods
call(origin = Dir.pwd)
click to toggle source
@param [String, Pathname] origin @return [Pathname]
# File lib/savvy/root_finder.rb, line 33 def call(origin = Dir.pwd) if defined?(Rails) && Rails.root Rails.root elsif defined?(Bundler) && Bundler.root Bundler.root else find_potential_root_from(origin) end end
Public Instance Methods
find_potential_root_from(origin = Dir.pwd)
click to toggle source
# File lib/savvy/root_finder.rb, line 12 def find_potential_root_from(origin = Dir.pwd) start_root = Pathname.new(origin) start_root.ascend do |path| if looks_like_a_root_directory?(path) return path end end raise ArgumentError, "Could not find root from #{origin}" end
looks_like_a_root_directory?(path)
click to toggle source
# File lib/savvy/root_finder.rb, line 24 def looks_like_a_root_directory?(path) ROOT_FILES.any? do |filename| path.join(filename).exist? end end