Class: Vimmer::Installers::Github

Inherits:
Object
  • Object
show all
Defined in:
lib/vimmer/installers/github.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Github

Returns a new instance of Github.



11
12
13
14
15
16
17
# File 'lib/vimmer/installers/github.rb', line 11

def initialize(args={})
  if args[:path]
    initialize_with_path(args[:path])
  elsif args[:name]
    initialize_with_name(args[:name])
  end
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/vimmer/installers/github.rb', line 9

def path
  @path
end

#plugin_nameObject (readonly)

Returns the value of attribute plugin_name.



9
10
11
# File 'lib/vimmer/installers/github.rb', line 9

def plugin_name
  @plugin_name
end

Class Method Details

.is_github_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/vimmer/installers/github.rb', line 52

def self.is_github_url?(url)
  !(GITHUB_PUBLIC_URL_PATTERN.match(url) ||
    GITHUB_GIT_URL_PATTERN.match(url)).nil?
end

.match?(url) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/vimmer/installers/github.rb', line 48

def self.match?(url)
  is_github_url?(url)
end

Instance Method Details

#installObject



20
21
22
23
24
25
26
27
28
# File 'lib/vimmer/installers/github.rb', line 20

def install
  if path_exists?
    git_clone(path, File.join(Vimmer.bundle_path, plugin_name))
    Vimmer.add_plugin(plugin_name, path)
    puts "#{plugin_name} has been installed"
  else
    raise Vimmer::PluginNotFoundError
  end
end

#path_exists?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/vimmer/installers/github.rb', line 43

def path_exists?
  `curl --head -w %{http_code} -o /dev/null #{remove_extension(path)} 2> /dev/null`.chomp == "200"
end

#uninstallObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/vimmer/installers/github.rb', line 31

def uninstall
  plugin_path = File.join(Vimmer.bundle_path, plugin_name)
  if File.directory? plugin_path
    FileUtils.rm_rf(plugin_path)
    Vimmer.remove_plugin(plugin_name)
    puts "#{plugin_name} has been uninstalled"
  else
    raise Vimmer::PluginNotFoundError
  end
end