7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/kafo/parser_cache_reader.rb', line 7
def self.new_from_file(cache_paths)
cache_paths = [cache_paths].compact unless cache_paths.is_a?(Array)
if cache_paths.empty?
logger.debug "No parser cache(s) configured in :parser_cache_path, skipping setup"
return nil
end
non_existent = cache_paths.select { |path| !File.exist?(path) }
unless non_existent.empty?
logger.warn "Parser cache(s) configured at #{non_existent.join(", ")} are missing, skipping setup"
return nil
end
parsed = cache_paths.map { |path| YAML.load(File.read(File.expand_path(path))) }
parsed.each_with_index do |cache, i|
if !cache.is_a?(Hash) || cache[:version] != PARSER_CACHE_VERSION || !cache[:files].is_a?(Hash)
logger.warn "Parser cache #{cache_paths[i]} is from a different version of Kafo, skipping setup"
return nil
end
end
logger.debug "Using #{cache_paths.join(", ")} cache with parsed modules"
merged_cache = {
:version => PARSER_CACHE_VERSION,
:files => parsed.map { |cache| cache[:files] }.reduce({}) { |ret, files| ret.merge!(files) }
}
new(merged_cache)
end
|