Class: PathHelper
- Inherits:
-
Object
- Object
- PathHelper
- Defined in:
- lib/cookbook_creator/pathhelper.rb
Class Method Summary collapse
Class Method Details
.all_homes(*args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cookbook_creator/pathhelper.rb', line 10 def self.all_homes(*args) paths = [] paths << Dir.home if ENV['HOME'] paths = paths.map { |home_path| home_path.gsub(path_separator, ::File::SEPARATOR) if home_path } # Filter out duplicate paths and paths that don't exist. valid_paths = paths.select { |home_path| home_path && Dir.exists?(home_path) } valid_paths = valid_paths.uniq # Join all optional path elements at the end. # If a block is provided, invoke it - otherwise just return what we've got. joined_paths = valid_paths.map { |home_path| File.join(home_path, *args) } if block_given? joined_paths.each { |p| yield p } else joined_paths end end |
.home(*args) ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/cookbook_creator/pathhelper.rb', line 2 def self.home(*args) @@home_dir ||= self.all_homes { |p| break p } if @@home_dir path = File.join(@@home_dir, *args) block_given? ? (yield path) : path end end |
.path_separator ⇒ Object
30 31 32 |
# File 'lib/cookbook_creator/pathhelper.rb', line 30 def self.path_separator File::SEPARATOR end |