class Nanoc::Core::ConfigLoader
@api private
Public Class Methods
config_filename_for_cwd()
click to toggle source
@return [String]
# File lib/nanoc/core/config_loader.rb, line 31 def self.config_filename_for_cwd filenames = %w[nanoc.yaml config.yaml] candidate = filenames.find { |f| File.file?(f) } candidate && File.expand_path(candidate) end
cwd_is_nanoc_site?()
click to toggle source
@return [Boolean]
# File lib/nanoc/core/config_loader.rb, line 26 def self.cwd_is_nanoc_site? !config_filename_for_cwd.nil? end
Public Instance Methods
apply_parent_config(config, processed_paths = [])
click to toggle source
@api private
# File lib/nanoc/core/config_loader.rb, line 61 def apply_parent_config(config, processed_paths = []) parent_path = config[:parent_config_file] return config if parent_path.nil? # Get absolute path parent_path = File.absolute_path(parent_path, File.dirname(processed_paths.last)) unless File.file?(parent_path) raise NoParentConfigFileFoundError.new(parent_path) end # Check recursion if processed_paths.include?(parent_path) raise CyclicalConfigFileError.new(parent_path) end # Load parent_config = Nanoc::Core::Configuration.new(hash: load_file(parent_path), dir: config.dir) full_parent_config = apply_parent_config(parent_config, processed_paths + [parent_path]) full_parent_config.merge(config.without(:parent_config_file)) end
load_file(filename)
click to toggle source
# File lib/nanoc/core/config_loader.rb, line 56 def load_file(filename) YAML.load_file(filename) end
new_from_cwd()
click to toggle source
# File lib/nanoc/core/config_loader.rb, line 37 def new_from_cwd # Determine path filename = self.class.config_filename_for_cwd raise NoConfigFileFoundError if filename.nil? # Read config = apply_parent_config( Nanoc::Core::Configuration.new( hash: load_file(filename), dir: File.dirname(filename), ), [filename], ).with_defaults # Load environment config.with_environment end