class Heroku::Plugin

Constants

DEPRECATED_PLUGINS

Attributes

name[R]
uri[R]

Public Class Methods

check_for_deprecation(plugin) click to toggle source
# File lib/heroku/plugin.rb, line 74
def self.check_for_deprecation(plugin)
  return unless STDIN.isatty

  if DEPRECATED_PLUGINS.include?(plugin)
    if confirm "The plugin #{plugin} has been deprecated. Would you like to remove it? (y/N)"
      remove_plugin(plugin)
    end
  end
end
directory() click to toggle source
# File lib/heroku/plugin.rb, line 27
def self.directory
  File.expand_path("#{home_directory}/.heroku/plugins")
end
list() click to toggle source
# File lib/heroku/plugin.rb, line 31
def self.list
  Dir["#{directory}/*"].sort.map do |folder|
    File.basename(folder)
  end
end
load!() click to toggle source
# File lib/heroku/plugin.rb, line 37
def self.load!
  list.each do |plugin|
    begin
      check_for_deprecation(plugin)
      next if skip_plugins.include?(plugin)
      load_plugin(plugin)
    rescue ScriptError, StandardError => e
      display "ERROR: Unable to load plugin #{plugin}: #{e.message}"
      display
    end
  end
  # check to see if we are using ddollar/heroku-accounts
  if list.include?('heroku-accounts') && Heroku::Auth.methods.include?(:fetch_from_account)
    # setup netrc to match the default, if one exists
    if default_account = %x{ git config heroku.account }.chomp
      account = Heroku::Auth.extract_account rescue nil
      if account && Heroku::Auth.read_credentials != [Heroku::Auth.user, Heroku::Auth.password]
        Heroku::Auth.credentials = [Heroku::Auth.user, Heroku::Auth.password]
        Heroku::Auth.write_credentials
        load("#{File.dirname(__FILE__)}/command/accounts.rb")
        # kill memoization in case '--account' was passed
        Heroku::Auth.instance_variable_set(:@account, nil)
      end
    end
  end
end
load_plugin(plugin) click to toggle source
# File lib/heroku/plugin.rb, line 64
def self.load_plugin(plugin)
  folder = "#{self.directory}/#{plugin}"
  $: << "#{folder}/lib"    if File.directory? "#{folder}/lib"
  load "#{folder}/init.rb" if File.exists?  "#{folder}/init.rb"
end
new(uri) click to toggle source
# File lib/heroku/plugin.rb, line 88
def initialize(uri)
  @uri = uri
  guess_name(uri)
end
remove_plugin(plugin) click to toggle source
# File lib/heroku/plugin.rb, line 70
def self.remove_plugin(plugin)
  FileUtils.rm_rf("#{self.directory}/#{plugin}")
end
skip_plugins() click to toggle source
# File lib/heroku/plugin.rb, line 84
def self.skip_plugins
  @skip_plugins ||= ENV["SKIP_PLUGINS"].to_s.split(%r ,/)
end

Public Instance Methods

install() click to toggle source
# File lib/heroku/plugin.rb, line 101
def install
  FileUtils.mkdir_p(path)
  Dir.chdir(path) do
    git("init -q")
    git("pull #{uri} master -q")
    unless $?.success?
      FileUtils.rm_rf path
      return false
    end
  end
  true
end
path() click to toggle source
# File lib/heroku/plugin.rb, line 97
def path
  "#{self.class.directory}/#{name}"
end
to_s() click to toggle source
# File lib/heroku/plugin.rb, line 93
def to_s
  name
end
uninstall() click to toggle source
# File lib/heroku/plugin.rb, line 114
def uninstall
  if File.directory?(path)
    FileUtils.rm_r(path)
    true
  else
    false
  end
end