Class: Heroku::Plugin

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

Defined Under Namespace

Classes: ErrorUpdatingSymlinkPlugin

Constant Summary collapse

DEPRECATED_PLUGINS =
%w(
  heroku-cedar
  heroku-certs
  heroku-credentials
  heroku-dyno-size
  heroku-kill
  heroku-labs
  heroku-logging
  heroku-netrc
  heroku-pgdumps
  heroku-postgresql
  heroku-releases
  heroku-shared-postgresql
  heroku-sql-console
  heroku-status
  heroku-stop
  heroku-suggest
  pgbackups-automate
  pgcmd
  heroku-fork
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

action, ask, confirm, confirm_billing, confirm_command, create_git_remote, deprecate, display, display_header, display_object, display_row, display_table, error, error_with_failure, error_with_failure=, extended, extended_into, fail, format_bytes, format_date, format_error, format_with_bang, get_terminal_environment, git, has_git?, home_directory, host_name, hprint, hputs, included, included_into, json_decode, json_encode, launchy, line_formatter, longest, output_with_bang, quantify, redisplay, retry_on_exception, run_command, running_on_a_mac?, running_on_windows?, set_buffer, shell, spinner, status, string_distance, styled_array, styled_error, styled_hash, styled_header, suggestion, time_ago, truncate, with_tty

Constructor Details

#initialize(uri) ⇒ Plugin

Returns a new instance of Plugin.



95
96
97
98
# File 'lib/heroku/plugin.rb', line 95

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



32
33
34
# File 'lib/heroku/plugin.rb', line 32

def name
  @name
end

#uriObject (readonly)

Returns the value of attribute uri.



32
33
34
# File 'lib/heroku/plugin.rb', line 32

def uri
  @uri
end

Class Method Details

.check_for_deprecation(plugin) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/heroku/plugin.rb', line 81

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

.directoryObject



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

def self.directory
  File.expand_path("#{home_directory}/.heroku/plugins")
end

.listObject



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

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

.load!Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/heroku/plugin.rb', line 44

def self.load!
  list.each do |plugin|
    check_for_deprecation(plugin)
    next if skip_plugins.include?(plugin)
    load_plugin(plugin)
  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  = %x{ git config heroku.account }.chomp
       = Heroku::Auth. rescue nil
      if  && 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) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/heroku/plugin.rb', line 66

def self.load_plugin(plugin)
  begin
    folder = "#{self.directory}/#{plugin}"
    $: << "#{folder}/lib"    if File.directory? "#{folder}/lib"
    load "#{folder}/init.rb" if File.exists?  "#{folder}/init.rb"
  rescue ScriptError, StandardError => error
    styled_error(error, "Unable to load plugin #{plugin}.")
    false
  end
end

.remove_plugin(plugin) ⇒ Object



77
78
79
# File 'lib/heroku/plugin.rb', line 77

def self.remove_plugin(plugin)
  FileUtils.rm_rf("#{self.directory}/#{plugin}")
end

.skip_pluginsObject



91
92
93
# File 'lib/heroku/plugin.rb', line 91

def self.skip_plugins
  @skip_plugins ||= ENV["SKIP_PLUGINS"].to_s.split(/[ ,]/)
end

Instance Method Details

#installObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/heroku/plugin.rb', line 108

def install
  if File.directory?(path)
    uninstall
  end
  FileUtils.mkdir_p(self.class.directory)
  Dir.chdir(self.class.directory) do
    git("clone #{uri}")
    unless $?.success?
      FileUtils.rm_rf path
      return false
    end
  end
  true
end

#pathObject



104
105
106
# File 'lib/heroku/plugin.rb', line 104

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

#to_sObject



100
101
102
# File 'lib/heroku/plugin.rb', line 100

def to_s
  name
end

#uninstallObject



123
124
125
126
# File 'lib/heroku/plugin.rb', line 123

def uninstall
  ensure_plugin_exists
  FileUtils.rm_r(path)
end

#updateObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/heroku/plugin.rb', line 128

def update
  ensure_plugin_exists
  if File.symlink?(path)
    raise Heroku::Plugin::ErrorUpdatingSymlinkPlugin
  else
    Dir.chdir(path) do
      unless git('config --get branch.master.remote').empty?
        message = git("pull")
        unless $?.success?
          error("Unable to update #{name}.\n" + message)
        end
      else
        error(<<-ERROR)
#{name} is a legacy plugin installation.
Enable updating by reinstalling with `pogo plugins:install`.
ERROR
      end
    end
  end
end