Class: Nanoc::Int::ConfigLoader Private
- Inherits:
-
Object
- Object
- Nanoc::Int::ConfigLoader
- Defined in:
- lib/nanoc/base/repos/config_loader.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: CyclicalConfigFileError, NoConfigFileFoundError, NoParentConfigFileFoundError
Class Method Summary collapse
- .config_filename_for_cwd ⇒ String private
- .cwd_is_nanoc_site? ⇒ Boolean private
Instance Method Summary collapse
Class Method Details
.config_filename_for_cwd ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 31 32 |
# File 'lib/nanoc/base/repos/config_loader.rb', line 28 def self.config_filename_for_cwd filenames = %w(nanoc.yaml config.yaml) candidate = filenames.find { |f| File.file?(f) } candidate && File.(candidate) end |
.cwd_is_nanoc_site? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 |
# File 'lib/nanoc/base/repos/config_loader.rb', line 23 def self.cwd_is_nanoc_site? !config_filename_for_cwd.nil? end |
Instance Method Details
#apply_parent_config(config, processed_paths = []) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/nanoc/base/repos/config_loader.rb', line 47 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::Int::Configuration.new(YAML.load_file(parent_path)) full_parent_config = apply_parent_config(parent_config, processed_paths + [parent_path]) full_parent_config.merge(config.without(:parent_config_file)) end |
#new_from_cwd ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/nanoc/base/repos/config_loader.rb', line 34 def new_from_cwd # Determine path filename = self.class.config_filename_for_cwd raise NoConfigFileFoundError if filename.nil? # Read apply_parent_config( Nanoc::Int::Configuration.new(YAML.load_file(filename)), [filename], ).with_defaults end |