Class: RedcarPlugin

Inherits:
Thor
  • Object
show all
Defined in:
lib/redcar_plugin.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ RedcarPlugin

Returns a new instance of RedcarPlugin.



4
5
6
7
8
9
# File 'lib/redcar_plugin.rb', line 4

def initialize(args=[], options={}, config={})
  @list = YAML.load_file(REPOS_FILE)
  @plugins_dir = "#{ENV['HOME']}/.redcar/plugins/"
  @installed_plugins = Dir.entries(@plugins_dir).delete_if {|name| name =="." || name ==".."}
  super(args,options,config)
end

Instance Method Details

#install(plugin_name) ⇒ Object



12
13
14
15
16
# File 'lib/redcar_plugin.rb', line 12

def install(plugin_name)    
  name = plugin_name
  url  = @list['repos'][plugin_name]['url']
  clone_repo(name,url)
end

#installedObject



47
48
49
50
51
52
53
# File 'lib/redcar_plugin.rb', line 47

def installed
  puts ''
  puts " *** LIST OF INSTALLED PLUGINS ***"
  puts ''
  @installed_plugins.each {|name| puts name}
  puts ''
end

#listObject



56
57
58
59
60
61
62
63
64
# File 'lib/redcar_plugin.rb', line 56

def list
  puts ''
  puts " *** LIST OF AVAILBLE PLUGINS ***"
  puts ''
  @list['repos'].each do |key, value|
    puts "* #{key} - #{value['description']}"
  end
  puts ''
end

#uninstall(plugin_name) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/redcar_plugin.rb', line 37

def uninstall(plugin_name)
  if @installed_plugins.include?(plugin_name)
    command = "rm -rf #{@plugins_dir}#{plugin_name}"
    puts "Plugin #{plugin_name} successfully deleted" if system(command)
  else
    puts "Plugin is not installed"
  end
end

#update(plugin_name) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/redcar_plugin.rb', line 19

def update(plugin_name)
  if @installed_plugins.include?(plugin_name)
    command = "cd #{@plugins_dir}#{plugin_name} && git pull"
    puts "Plugin #{plugin_name} successfully updated" if system(command)
  else
    puts "Plugin #{plugin_name} not installed"
  end
end

#update_allObject



29
30
31
32
33
34
# File 'lib/redcar_plugin.rb', line 29

def update_all
  @installed_plugins.each do |name|
    command = "cd #{@plugins_dir}#{name} && git pull"
    system("cd #{@plugins_dir}#{name} && git pull")
  end
end