Move PathManager methods into its singleton class

This commit is contained in:
Ashwin Maroli 2020-11-05 17:30:59 +05:30
parent 9b96cdfa7d
commit 0dedc09ab3
1 changed files with 37 additions and 35 deletions

View File

@ -16,11 +16,12 @@ module Jekyll
# This class cannot be initialized from outside
private_class_method :new
class << self
# Wraps `File.join` to cache the frozen result.
# Reassigns `nil`, empty strings and empty arrays to a frozen empty string beforehand.
#
# Returns a frozen string.
def self.join(base, item)
def join(base, item)
base = "" if base.nil? || base.empty?
item = "" if item.nil? || item.empty?
@join ||= {}
@ -32,7 +33,7 @@ module Jekyll
# and prepends the questionable path with the base directory if false.
#
# Returns a frozen string.
def self.sanitized_path(base_directory, questionable_path)
def sanitized_path(base_directory, questionable_path)
@sanitized_path ||= {}
@sanitized_path[base_directory] ||= {}
@sanitized_path[base_directory][questionable_path] ||= begin
@ -59,4 +60,5 @@ module Jekyll
end
end
end
end
end