Module: Vim::Jar::Plugin
- Defined in:
- lib/vim-jar/plugin.rb,
lib/vim-jar/plugin/git.rb
Defined Under Namespace
Classes: Git
Class Method Summary collapse
- .build(plugin_attrs) ⇒ Object
- .config ⇒ Object
- .exist?(name) ⇒ Boolean
- .find(plugin_name) ⇒ Object
- .insert(attrs) ⇒ Object
- .installed ⇒ Object
- .plugins ⇒ Object
- .remove_from_cache(name) ⇒ Object
- .remove_ref_from_git_config(name) ⇒ Object
- .remove_ref_from_gitmodules(name) ⇒ Object
- .reset ⇒ Object
- .uninstall(name) ⇒ Object
- .update ⇒ Object
Class Method Details
.build(plugin_attrs) ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/vim-jar/plugin.rb', line 106 def self.build(plugin_attrs) return nil unless plugin_attrs type = plugin_attrs["type"] case type when "git" ::Vim::Jar::Plugin::Git.new(plugin_attrs) else nil end end |
.config ⇒ Object
102 103 104 |
# File 'lib/vim-jar/plugin.rb', line 102 def self.config ::Vim::Jar::Config.instance end |
.exist?(name) ⇒ Boolean
29 30 31 32 33 34 35 36 |
# File 'lib/vim-jar/plugin.rb', line 29 def self.exist? name #OPTIMIZE @exist_list ||= {} return @exist_list[name] if @exist_list.has_key? name result = self.plugins.any? { |p| p["name"].strip.downcase == name.strip.downcase } @exist_list[name] = result result end |
.find(plugin_name) ⇒ Object
6 7 8 9 10 |
# File 'lib/vim-jar/plugin.rb', line 6 def self.find(plugin_name) #TODO use sqlite in the future plugin_attrs = plugins.detect { |p| p["name"].to_s.downcase == plugin_name.to_s.downcase } build(plugin_attrs) end |
.insert(attrs) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/vim-jar/plugin.rb', line 38 def self.insert(attrs) #OPTIMIZE if self.exist? attrs["name"] return false else self.plugins << attrs return true end end |
.installed ⇒ Object
48 49 50 |
# File 'lib/vim-jar/plugin.rb', line 48 def self.installed @installed ||= Dir[config.bundle_home.join("*")].map { |bundle_path| File.basename(bundle_path) } end |
.plugins ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/vim-jar/plugin.rb', line 12 def self.plugins return @plugins if @plugins if !File.exist? config.yaml_path FileUtils.touch config.yaml_path @plugins = [] else @plugins = YAML.load_file(config.yaml_path) || [] end @plugins end |
.remove_from_cache(name) ⇒ Object
58 59 60 61 62 |
# File 'lib/vim-jar/plugin.rb', line 58 def self.remove_from_cache(name) Dir.chdir(config.vim_home) do system("git rm -r --cached bundle/#{name}") end end |
.remove_ref_from_git_config(name) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/vim-jar/plugin.rb', line 81 def self.remove_ref_from_git_config(name) #TODO bundle name is different to submodule name f = File.new(config.gitconfig_file_path) lines = f.lines.to_a lines.delete_if do |x| x =~ /bundle\/#{name}/ || x =~ /#{name}\.git$/ end f.close File.open(config.gitconfig_file_path, "w") do |ff| lines.each do |l| ff.puts l end end end |
.remove_ref_from_gitmodules(name) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vim-jar/plugin.rb', line 64 def self.remove_ref_from_gitmodules(name) #TODO bundle name is different to submodule name f = File.new(config.gitmodules_file_path) lines = f.lines.to_a lines.delete_if do |x| x =~ /bundle\/#{name}/ || x =~ /#{name}\.git$/ end f.close File.open(config.gitmodules_file_path, "w") do |ff| lines.each do |l| ff.puts l end end end |
.reset ⇒ Object
97 98 99 100 |
# File 'lib/vim-jar/plugin.rb', line 97 def self.reset self.instance_variable_set("@plugins", nil) self.plugins end |
.uninstall(name) ⇒ Object
52 53 54 55 56 |
# File 'lib/vim-jar/plugin.rb', line 52 def self.uninstall(name) remove_ref_from_gitmodules(name) remove_ref_from_git_config(name) remove_from_cache(name) end |
.update ⇒ Object
23 24 25 26 27 |
# File 'lib/vim-jar/plugin.rb', line 23 def self.update Dir.chdir(config.vim_home) do system("git submodule update") end end |