Class: BigKeeper::ModuleCacheOperator

Inherits:
Object
  • Object
show all
Defined in:
lib/big_keeper/util/cache_operator.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ModuleCacheOperator

Returns a new instance of ModuleCacheOperator.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/big_keeper/util/cache_operator.rb', line 27

def initialize(path)
  @cache_path = File.expand_path("#{path}/.bigkeeper")

  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
  else
    @modules = {"git" => {"all" => [], "current" => []}, "path" => {"all" => [], "add" => [], "del" => [], "current" => []},"branch_name" => ""}
  end
end

Instance Method Details

#add_git_module(module_name) ⇒ Object



96
97
98
99
# File 'lib/big_keeper/util/cache_operator.rb', line 96

def add_git_module(module_name)
  @modules["git"]["current"] << module_name unless @modules["git"]["current"].include?(module_name)
  cache_modules
end

#add_path_module(module_name) ⇒ Object



106
107
108
109
# File 'lib/big_keeper/util/cache_operator.rb', line 106

def add_path_module(module_name)
  @modules["path"]["current"] << module_name unless @modules["path"]["current"].include?(module_name)
  cache_modules
end

#add_path_modulesObject



49
50
51
# File 'lib/big_keeper/util/cache_operator.rb', line 49

def add_path_modules
  @modules["path"]["add"]
end

#all_git_modulesObject



65
66
67
# File 'lib/big_keeper/util/cache_operator.rb', line 65

def all_git_modules
  @modules["git"]["all"]
end

#all_path_modulesObject



45
46
47
# File 'lib/big_keeper/util/cache_operator.rb', line 45

def all_path_modules
  @modules["path"]["all"]
end

#branch_nameObject



41
42
43
# File 'lib/big_keeper/util/cache_operator.rb', line 41

def branch_name
  @modules["branch_name"]
end

#cache_branch_name(branch_name) ⇒ Object



78
79
80
81
# File 'lib/big_keeper/util/cache_operator.rb', line 78

def cache_branch_name(branch_name)
  @modules["branch_name"] = branch_name
  cache_modules
end

#cache_git_modules(modules) ⇒ Object



91
92
93
94
# File 'lib/big_keeper/util/cache_operator.rb', line 91

def cache_git_modules(modules)
  @modules["git"]["all"] = modules.uniq
  cache_modules
end

#cache_modulesObject



122
123
124
125
126
127
# File 'lib/big_keeper/util/cache_operator.rb', line 122

def cache_modules
  file = File.new("#{@cache_path}/module.cache", 'w')
  p "module缓存地址:#{@cache_path}/module.cache"
  file << @modules.to_json
  file.close
end

#cache_path_modules(modules, add_modules, del_modules) ⇒ Object



84
85
86
87
88
89
# File 'lib/big_keeper/util/cache_operator.rb', line 84

def cache_path_modules(modules, add_modules, del_modules)
  @modules["path"]["all"] = modules.uniq
  @modules["path"]["add"] = add_modules.uniq
  @modules["path"]["del"] = del_modules.uniq
  cache_modules
end

#clean_modulesObject



116
117
118
119
120
# File 'lib/big_keeper/util/cache_operator.rb', line 116

def clean_modules
  branch_name = @modules["branch_name"]
  @modules = {"git" => {"all" => [], "current" => []}, "path" => {"all" => [], "add" => [], "del" => [], "current" => []},"branch_name" => branch_name}
  cache_modules
end

#current_git_modulesObject



69
70
71
# File 'lib/big_keeper/util/cache_operator.rb', line 69

def current_git_modules
  @modules["git"]["current"]
end

#current_path_modulesObject



57
58
59
# File 'lib/big_keeper/util/cache_operator.rb', line 57

def current_path_modules
  @modules["path"]["current"]
end

#del_git_module(module_name) ⇒ Object



101
102
103
104
# File 'lib/big_keeper/util/cache_operator.rb', line 101

def del_git_module(module_name)
  @modules["git"]["current"].delete(module_name) if @modules["git"]["current"].include?(module_name)
  cache_modules
end

#del_path_module(module_name) ⇒ Object



111
112
113
114
# File 'lib/big_keeper/util/cache_operator.rb', line 111

def del_path_module(module_name)
  @modules["path"]["current"].delete(module_name) if @modules["path"]["current"].include?(module_name)
  cache_modules
end

#del_path_modulesObject



53
54
55
# File 'lib/big_keeper/util/cache_operator.rb', line 53

def del_path_modules
  @modules["path"]["del"]
end

#remain_git_modulesObject



73
74
75
# File 'lib/big_keeper/util/cache_operator.rb', line 73

def remain_git_modules
  @modules["git"]["all"] - @modules["git"]["current"]
end

#remain_path_modulesObject



61
62
63
# File 'lib/big_keeper/util/cache_operator.rb', line 61

def remain_path_modules
  @modules["path"]["all"] - @modules["path"]["current"]
end