DRY config value fetching

Adds #get_config_value_with_override, refactoring the three fetch
methods to use it.
This commit is contained in:
Jim Meyer 2015-04-18 16:59:36 -07:00
parent 9c03fc3f27
commit 269662d0f0
1 changed files with 11 additions and 5 deletions

View File

@ -91,22 +91,28 @@ module Jekyll
reduce({}) { |hsh,(k,v)| hsh.merge(k.to_s => v) } reduce({}) { |hsh,(k,v)| hsh.merge(k.to_s => v) }
end end
def get_config_value_with_override(config_key, override)
override[config_key] || self[config_key] || DEFAULTS[config_key]
end
# Public: Directory of the Jekyll source folder # Public: Directory of the Jekyll source folder
# #
# override - the command-line options hash # override - the command-line options hash
# #
# Returns the path to the Jekyll source directory # Returns the path to the Jekyll source directory
def source(override) def source(override)
override['source'] || self['source'] || DEFAULTS['source'] get_config_value_with_override('source', override)
end end
def quiet?(override = {}) def quiet(override = {})
override['quiet'] || self['quiet'] || DEFAULTS['quiet'] get_config_value_with_override('quiet', override)
end end
alias_method :quiet?, :quiet
def verbose?(override = {}) def verbose(override = {})
override['verbose'] || self['verbose'] || DEFAULTS['verbose'] get_config_value_with_override('verbose', override)
end end
alias_method :verbose?, :verbose
def safe_load_file(filename) def safe_load_file(filename)
case File.extname(filename) case File.extname(filename)