Commit ae94566f authored by Vincent Isambart's avatar Vincent Isambart

Move caching from FileAccessor to PathList

parent 9e0b0762
......@@ -39,7 +39,6 @@ module Pod
@path_list = PathList.new(path_list)
end
@spec_consumer = spec_consumer
@paths_for_attribute = { false => {}, true => {} }
unless @spec_consumer
raise Informative, 'Attempt to initialize File Accessor without a specification consumer.'
......@@ -277,14 +276,13 @@ module Pod
# @return [Array<Pathname>] the paths.
#
def paths_for_attribute(attribute, include_dirs = false)
return @paths_for_attribute[include_dirs][attribute] if @paths_for_attribute[include_dirs][attribute]
file_patterns = spec_consumer.send(attribute)
options = {
:exclude_patterns => spec_consumer.exclude_files,
:dir_pattern => GLOB_PATTERNS[attribute],
:include_dirs => include_dirs,
}
@paths_for_attribute[include_dirs][attribute] = expanded_paths(file_patterns, options)
expanded_paths(file_patterns, options)
end
# Matches the given patterns to the file present in the root of the path
......
......@@ -21,6 +21,7 @@ module Pod
#
def initialize(root)
@root = root
@glob_cache = {}
end
# @return [Array<String>] The list of absolute the path of all the files
......@@ -46,6 +47,7 @@ module Pod
unless root.exist?
raise Informative, "Attempt to read non existent folder `#{root}`."
end
@glob_cache = {}
root_length = root.to_s.length + 1
escaped_root = escape_path_for_glob(root)
paths = Dir.glob(escaped_root + '**/*', File::FNM_DOTMATCH)
......@@ -101,6 +103,10 @@ module Pod
def relative_glob(patterns, options = {})
return [] if patterns.empty?
cache_key = options.merge(:patterns => patterns)
cached_value = @glob_cache[cache_key]
return cached_value if cached_value
dir_pattern = options[:dir_pattern]
exclude_patterns = options[:exclude_patterns]
include_dirs = options[:include_dirs]
......@@ -133,7 +139,7 @@ module Pod
exclude_options = { :dir_pattern => '**/*', :include_dirs => include_dirs }
list -= relative_glob(exclude_patterns, exclude_options)
end
list
@glob_cache[cache_key] = list
end
#-----------------------------------------------------------------------#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment