Module: Girb::GirbrcLoader
- Defined in:
- lib/girb/girbrc_loader.rb
Class Method Summary collapse
-
.find_config(filename, start_dir = Dir.pwd) ⇒ Object
Find config file by traversing from start_dir up to root, then fall back to home directory.
-
.find_girbrc(start_dir = Dir.pwd) ⇒ Object
Find .girbrc by traversing from start_dir up to root, then fall back to ~/.girbrc.
-
.load_girbrc(start_dir = Dir.pwd) ⇒ Object
Load .girbrc if found.
Class Method Details
.find_config(filename, start_dir = Dir.pwd) ⇒ Object
Find config file by traversing from start_dir up to root, then fall back to home directory
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/girb/girbrc_loader.rb', line 10 def find_config(filename, start_dir = Dir.pwd) dir = Pathname.new(start_dir). # Traverse up to find config file while dir != dir.parent candidate = dir.join(filename) return candidate if candidate.exist? dir = dir.parent end # Check root directory root_candidate = dir.join(filename) return root_candidate if root_candidate.exist? # Fall back to home directory home_config = Pathname.new(File.("~/#{filename}")) home_config.exist? ? home_config : nil end |
.find_girbrc(start_dir = Dir.pwd) ⇒ Object
Find .girbrc by traversing from start_dir up to root, then fall back to ~/.girbrc
31 32 33 |
# File 'lib/girb/girbrc_loader.rb', line 31 def find_girbrc(start_dir = Dir.pwd) find_config(".girbrc", start_dir) end |
.load_girbrc(start_dir = Dir.pwd) ⇒ Object
Load .girbrc if found
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/girb/girbrc_loader.rb', line 36 def load_girbrc(start_dir = Dir.pwd) girbrc = find_girbrc(start_dir) return false unless girbrc if Girb.configuration&.debug warn "[girb] Loading #{girbrc}" end load girbrc.to_s true rescue SyntaxError, LoadError, StandardError => e warn "[girb] Error loading #{girbrc}: #{e.}" false end |