Class: GridCLI::Plugins

Inherits:
YMLHash
  • Object
show all
Defined in:
lib/gridcli/plugins.rb

Instance Method Summary collapse

Methods inherited from YMLHash

#save

Constructor Details

#initializePlugins

Returns a new instance of Plugins.



6
7
8
# File 'lib/gridcli/plugins.rb', line 6

def initialize
  super "plugins"
end

Instance Method Details

#default_configObject



10
11
12
13
14
15
# File 'lib/gridcli/plugins.rb', line 10

def default_config
  {
    'enabled' => [],
    'disabled' => []
  }
end

#include!Object



38
39
40
41
42
# File 'lib/gridcli/plugins.rb', line 38

def include!
  fetch('enabled', []).each { |m|
    require m
  }
end

#install(name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gridcli/plugins.rb', line 17

def install(name)
  name = "grid-plugin-#{name}" unless name.start_with?("grid-plugin-")
  Process.fork { Gem::GemRunner.new.run ["install", name, "--no-rdoc", "--no-ri"]; puts "done" }
  Process.wait

  if Gem::Specification.find_all_by_name(name).length == 0
    puts "There was an issue installing the plugin."
  elsif not fetch('enabled', []).include? name
    self['enabled'] << name
    save
  end
end

#uninstall(name) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/gridcli/plugins.rb', line 30

def uninstall(name)
  name = "grid-plugin-#{name}" unless name.start_with?("grid-plugin-")
  return unless fetch('enabled', []).include? name
  self['enabled'].delete(name)
  save
  Gem::GemRunner.new.run ["uninstall", name]
end