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
Class Method Details
.build(plugin_attrs) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/vim-jar/plugin.rb', line 100 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
96 97 98 |
# File 'lib/vim-jar/plugin.rb', line 96 def self.config ::Vim::Jar::Config.instance end |
.exist?(name) ⇒ Boolean
23 24 25 26 27 28 29 30 |
# File 'lib/vim-jar/plugin.rb', line 23 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
32 33 34 35 36 37 38 39 40 |
# File 'lib/vim-jar/plugin.rb', line 32 def self.insert(attrs) #OPTIMIZE if self.exist? attrs["name"] return false else self.plugins << attrs return true end end |
.installed ⇒ Object
42 43 44 |
# File 'lib/vim-jar/plugin.rb', line 42 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
52 53 54 55 56 |
# File 'lib/vim-jar/plugin.rb', line 52 def self.remove_from_cache(name) Dir.chdir(config.vim_home) do system("git rm --cached bundle/#{name}") end end |
.remove_ref_from_git_config(name) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/vim-jar/plugin.rb', line 75 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
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/vim-jar/plugin.rb', line 58 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
91 92 93 94 |
# File 'lib/vim-jar/plugin.rb', line 91 def self.reset self.instance_variable_set("@plugins", nil) self.plugins end |
.uninstall(name) ⇒ Object
46 47 48 49 50 |
# File 'lib/vim-jar/plugin.rb', line 46 def self.uninstall(name) remove_ref_from_gitmodules(name) remove_ref_from_git_config(name) remove_from_cache(name) end |