class VirtualFileSystem
Attributes
root[R]
Public Class Methods
new()
click to toggle source
# File lib/virtual_file_system.rb, line 11 def initialize() @root = VirtualTree.new({path: ""}, {}) end
Public Instance Methods
[](file_name)
click to toggle source
# File lib/virtual_file_system.rb, line 15 def [](file_name) @root.get_file(file_name) end
file_for_diff(commit, diff)
click to toggle source
# File lib/virtual_file_system.rb, line 19 def file_for_diff(commit, diff) if diff.operation == :move @root.move_file(diff.a_file_name, diff.b_file_name) elsif diff.operation == :delete @root.delete_file(diff.a_file_name) else file_name = diff.b_file_name file = @root.get_file(file_name) file = @root.set_file(file_name, VirtualFile.new(file_name, diff)) if file.nil? file end end
file_paths()
click to toggle source
# File lib/virtual_file_system.rb, line 60 def file_paths root .all_files() .map { |file| file.path } end
load!(commits, meta)
click to toggle source
# File lib/virtual_file_system.rb, line 32 def load!(commits, meta) commit = commits.first return commits if commit.nil? || commit.cached_files.nil? commit.cached_trees.each do |tree_object| tree_id = tree_object[:object_id] cached_tree = Cache.read_object(tree_id) @root.add_tree(VirtualTree.from_json(cached_tree)) end commit.cached_files.each do |file_object| file_id = file_object[:object_id] cached_file = Cache.read_object(file_id) if not cached_file.nil? @root.set_file(file_object[:path], VirtualFile.from_json(file_id, cached_file)) end end sync_meta!(commit, meta) commits end
save(commit)
click to toggle source
# File lib/virtual_file_system.rb, line 55 def save(commit) prune(commit) @root.save(commit) end
touch_tree(diff_tree, commit)
click to toggle source
# File lib/virtual_file_system.rb, line 51 def touch_tree(diff_tree, commit) @root.touch(diff_tree, commit) end
Private Instance Methods
prune(commit)
click to toggle source
# File lib/virtual_file_system.rb, line 68 def prune(commit) commit .trees .reverse() .each { |diff_tree| @root.prune(diff_tree, commit) } end
sync_meta!(commit, meta)
click to toggle source
# File lib/virtual_file_system.rb, line 75 def sync_meta!(commit, meta) meta[:errors] && meta[:errors].sync!(commit) end