lib/big_keeper/util/cache_operator.rb in bigkeeper-0.7.6 vs lib/big_keeper/util/cache_operator.rb in bigkeeper-0.7.7

- old
+ new

@@ -20,6 +20,75 @@ def clean FileUtils.rm_r(@cache_path) end end + + class ModuleCacheOperator + def initialize(path) + @cache_path = File.expand_path("#{path}/.bigkeeper") + @modules = {"git" => {"all" => [], "current" => []}, "path" => {"all" => [], "current" => []}} + + FileUtils.mkdir_p(@cache_path) unless File.exist?(@cache_path) + + if File.exist?("#{@cache_path}/module.cache") + file = File.open("#{@cache_path}/module.cache", 'r') + @modules = JSON.load(file.read()) + file.close + end + end + + def all_path_modules + @modules["path"]["all"] + end + + def current_path_modules + @modules["path"]["current"] + end + + def all_git_modules + @modules["git"]["all"] + end + + def current_git_modules + @modules["git"]["current"] + end + + def cache_path_modules(modules) + @modules["path"]["all"] = modules + cache_modules + end + + def cache_git_modules(modules) + @modules["git"]["all"] = modules + cache_modules + end + + def add_branch_module(module_name) + @modules["path"]["current"].delete(module_name) + @modules["git"]["current"] << module_name + cache_modules + end + + def del_branch_module(module_name) + @modules["git"]["current"].delete(module_name) + cache_modules + end + + def add_path_module(module_name) + @modules["git"]["current"].delete(module_name) + @modules["path"]["current"] << module_name + cache_modules + end + + def del_path_module(module_name) + @modules["path"]["current"].delete(module_name) + cache_modules + end + + def cache_modules + file = File.new("#{@cache_path}/module.cache", 'w') + file << @modules.to_json + file.close + end + end end