Class: Heroku::Plugin

Inherits:
Object
  • Object
show all
Extended by:
Helpers
Defined in:
lib/heroku/plugin.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

home_directory, running_on_a_mac?, running_on_windows?

Constructor Details

#initialize(uri) ⇒ Plugin

Returns a new instance of Plugin.



29
30
31
32
# File 'lib/heroku/plugin.rb', line 29

def initialize(uri)
	@uri = uri
	guess_name(uri)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/heroku/plugin.rb', line 9

def name
  @name
end

#uriObject (readonly)

Returns the value of attribute uri.



9
10
11
# File 'lib/heroku/plugin.rb', line 9

def uri
  @uri
end

Class Method Details

.directoryObject



11
12
13
# File 'lib/heroku/plugin.rb', line 11

def self.directory
	"#{home_directory}/.heroku/plugins"
end

.listObject



15
16
17
18
19
# File 'lib/heroku/plugin.rb', line 15

def self.list
	Dir["#{directory}/*"].map do |folder|
		File.basename(folder)
	end
end

.load!Object



21
22
23
24
25
26
27
# File 'lib/heroku/plugin.rb', line 21

def self.load!
	list.each do |plugin|
		folder = "#{self.directory}/#{plugin}"
		$: << "#{folder}/lib"    if File.directory? "#{folder}/lib"
		load "#{folder}/init.rb" if File.exists?    "#{folder}/init.rb"
	end
end

Instance Method Details

#installObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/heroku/plugin.rb', line 42

def install
	FileUtils.mkdir_p(path)
	Dir.chdir(path) do
		system("git init > /dev/null 2>&1")
		if !system("git pull --depth 1 #{uri}  > /dev/null 2>&1")
			FileUtils.rm_rf path
			return false
		end
	end
	true
end

#pathObject



38
39
40
# File 'lib/heroku/plugin.rb', line 38

def path
	"#{self.class.directory}/#{name}"
end

#to_sObject



34
35
36
# File 'lib/heroku/plugin.rb', line 34

def to_s
	name
end

#uninstallObject



54
55
56
# File 'lib/heroku/plugin.rb', line 54

def uninstall
	FileUtils.rm_r path if File.directory?(path)
end