lib/nanoc/base/repos/config_loader.rb in nanoc-4.11.0 vs lib/nanoc/base/repos/config_loader.rb in nanoc-4.11.1
- old
+ new
@@ -1,93 +1,95 @@
# frozen_string_literal: true
-module Nanoc::Int
- # @api private
- class ConfigLoader
- class NoConfigFileFoundError < ::Nanoc::Error
- def initialize
- super('No configuration file found')
+module Nanoc
+ module Int
+ # @api private
+ class ConfigLoader
+ class NoConfigFileFoundError < ::Nanoc::Error
+ def initialize
+ super('No configuration file found')
+ end
end
- end
- class NoParentConfigFileFoundError < ::Nanoc::Error
- def initialize(filename)
- super("There is no parent configuration file at #{filename}")
+ class NoParentConfigFileFoundError < ::Nanoc::Error
+ def initialize(filename)
+ super("There is no parent configuration file at #{filename}")
+ end
end
- end
- class CyclicalConfigFileError < ::Nanoc::Error
- def initialize(filename)
- super("The parent configuration file at #{filename} includes one of its descendants")
+ class CyclicalConfigFileError < ::Nanoc::Error
+ def initialize(filename)
+ super("The parent configuration file at #{filename} includes one of its descendants")
+ end
end
- end
- # @return [Boolean]
- def self.cwd_is_nanoc_site?
- !config_filename_for_cwd.nil?
- end
+ # @return [Boolean]
+ def self.cwd_is_nanoc_site?
+ !config_filename_for_cwd.nil?
+ end
- # @return [String]
- def self.config_filename_for_cwd
- filenames =
- if Nanoc::Feature.enabled?(Nanoc::Feature::TOML)
- %w[nanoc.yaml config.yaml nanoc.toml]
- else
- %w[nanoc.yaml config.yaml]
- end
- candidate = filenames.find { |f| File.file?(f) }
- candidate && File.expand_path(candidate)
- end
+ # @return [String]
+ def self.config_filename_for_cwd
+ filenames =
+ if Nanoc::Feature.enabled?(Nanoc::Feature::TOML)
+ %w[nanoc.yaml config.yaml nanoc.toml]
+ else
+ %w[nanoc.yaml config.yaml]
+ end
+ candidate = filenames.find { |f| File.file?(f) }
+ candidate && File.expand_path(candidate)
+ end
- def new_from_cwd
- # Determine path
- filename = self.class.config_filename_for_cwd
- raise NoConfigFileFoundError if filename.nil?
+ def new_from_cwd
+ # Determine path
+ filename = self.class.config_filename_for_cwd
+ raise NoConfigFileFoundError if filename.nil?
- # Read
- config =
- apply_parent_config(
- Nanoc::Int::Configuration.new(
- hash: load_file(filename),
- dir: File.dirname(filename),
- ),
- [filename],
- ).with_defaults
+ # 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
+ # Load environment
+ config.with_environment
+ end
- def load_file(filename)
- case File.extname(filename)
- when '.yaml'
- YAML.load_file(filename)
- when '.toml'
- Tomlrb.load_file(filename)
- else
- raise Nanoc::Int::Errors::InternalInconsistency, 'Unhandled config file extension'
+ def load_file(filename)
+ case File.extname(filename)
+ when '.yaml'
+ YAML.load_file(filename)
+ when '.toml'
+ Tomlrb.load_file(filename)
+ else
+ raise Nanoc::Int::Errors::InternalInconsistency, 'Unhandled config file extension'
+ end
end
- end
- # @api private
- def apply_parent_config(config, processed_paths = [])
- parent_path = config[:parent_config_file]
- return config if parent_path.nil?
+ # @api private
+ 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
+ # 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
+ # Check recursion
+ if processed_paths.include?(parent_path)
+ raise CyclicalConfigFileError.new(parent_path)
+ end
- # Load
- parent_config = Nanoc::Int::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))
+ # 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
end
end
end