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.



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/big_keeper/util/cache_operator.rb', line 31

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', :encoding => 'UTF-8')
    @modules = JSON.load(file.read(), :encoding => 'UTF-8')
    file.close
  else
    @modules = {"git" => {"all" => [], "current" => []}, "path" => {"all" => [], "add" => [], "del" => [], "current" => []}}
  end
end

Instance Method Details

#add_git_module(module_name) ⇒ Object



89
90
91
92
# File 'lib/big_keeper/util/cache_operator.rb', line 89

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



99
100
101
102
# File 'lib/big_keeper/util/cache_operator.rb', line 99

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

#cache_git_modules(modules) ⇒ Object



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

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

#cache_modulesObject



114
115
116
117
118
# File 'lib/big_keeper/util/cache_operator.rb', line 114

def cache_modules
  file = File.new("#{@cache_path}/module.cache", 'w', :encoding => 'UTF-8')
  file << @modules.to_json
  file.close
end

#cache_path_modules(modules, add_modules, del_modules) ⇒ Object



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

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



109
110
111
112
# File 'lib/big_keeper/util/cache_operator.rb', line 109

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



94
95
96
97
# File 'lib/big_keeper/util/cache_operator.rb', line 94

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



104
105
106
107
# File 'lib/big_keeper/util/cache_operator.rb', line 104

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