class Epuber::Compiler::FileDatabase
Attributes
@return [Hash<String, Epuber::Compiler::FileStat
>]
@return [String]
Public Class Methods
Source
# File lib/epuber/compiler/file_database.rb, line 20 def initialize(path) @store_file_path = path @all_files = Psych.load_file(path, permitted_classes: [Epuber::Compiler::FileStat, Time]) || {} rescue StandardError @all_files = {} end
@param [String] path
Public Instance Methods
Source
# File lib/epuber/compiler/file_database.rb, line 76 def add_dependency(file_path, to: nil) raise ArgumentError, ':to is required' if to.nil? file_paths = Array(file_path) to_stat = @all_files[to] raise ArgumentError, ":to (#{to}) file is not in database" if to_stat.nil? to_stat.add_dependency!(file_paths) begin file_paths.each do |path| update_metadata(path, load_stats: false) if @all_files[path].nil? end rescue Errno::ENOENT # no action, valid case where dependant file does not exist end end
@param [Array<String>, String] file_path path to file that will be dependent on @param [String] to path to original file, that will has new dependency
Source
# File lib/epuber/compiler/file_database.rb, line 29 def changed?(file_path, transitive: true, default_value: true) stat = @all_files[file_path] return default_value if stat.nil? result = (stat != FileStat.new(file_path)) if transitive result ||= stat.dependency_paths.any? do |path| changed?(path, transitive: transitive, default_value: false) end end result end
@param [String] file_path
Source
# File lib/epuber/compiler/file_database.rb, line 97 def cleanup(file_paths) to_remove = @all_files.keys - file_paths to_remove.each { |key| @all_files.delete(key) } @all_files.each_value do |stat| _cleanup_stat_dependency_list(file_paths, stat) end end
@param [Array<String>] file_paths
Source
# File lib/epuber/compiler/file_database.rb, line 48 def file_stat_for(file_path) @all_files[file_path] end
@param [String] file_path
@return [FileStat]
Source
# File lib/epuber/compiler/file_database.rb, line 108 def save_to_file(path = store_file_path) FileUtils.mkdir_p(File.dirname(path)) File.write(path, @all_files.to_yaml) end
@param [String] path
Source
# File lib/epuber/compiler/file_database.rb, line 54 def up_to_date?(file_path, transitive: true) !changed?(file_path, transitive: transitive) end
@param [String] file_path
Source
# File lib/epuber/compiler/file_database.rb, line 67 def update_all_metadata @all_files.each_key do |file_path| update_metadata(file_path) end end
Source
# File lib/epuber/compiler/file_database.rb, line 60 def update_metadata(file_path, load_stats: true) old_stat = @all_files[file_path] old_dependencies = old_stat ? old_stat.dependency_paths : [] @all_files[file_path] = FileStat.new(file_path, load_stats: load_stats, dependency_paths: old_dependencies) end
@param [String] file_path
Private Instance Methods
Source
# File lib/epuber/compiler/file_database.rb, line 122 def _cleanup_stat_dependency_list(file_paths, stat) stat.keep_dependencies!(file_paths) stat.dependency_paths.each do |path| next_stat = @all_files[path] next if next_stat.nil? _cleanup_stat_dependency_list(file_paths, next_stat) end end
@param [Array<String>] file_paths @param [FileStat] stat