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-push
heroku-releases
heroku-shared-postgresql
heroku-sql-console
heroku-status
heroku-stop
heroku-suggest
heroku-symbol
heroku-two-factor
pgbackups-automate
pgcmd
heroku-fork
heroku-orgs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

action, app_owner, ask, confirm, confirm_command, create_git_remote, debug, debugging?, default_org_host, deprecate, display, display_header, display_object, display_row, display_table, error, error_log, error_log_path, 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?, has_git_remote?, has_http_git_entry_in_netrc, home_directory, hprint, hputs, included, included_into, json_decode, json_encode, launchy, line_formatter, longest, org?, org_host, output_with_bang, quantify, redisplay, retry_on_exception, run_command, running_on_a_mac?, running_on_windows?, set_buffer, shell, spinner, status, stderr_print, stderr_puts, string_distance, styled_array, styled_error, styled_hash, styled_header, suggestion, time_ago, truncate, update_git_remote, warn_if_using_jruby, with_tty

Constructor Details

#initialize(uri) ⇒ Plugin

Returns a new instance of Plugin


85
86
87
88
# File 'lib/heroku/plugin.rb', line 85

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


36
37
38
# File 'lib/heroku/plugin.rb', line 36

def name
  @name
end

#uriObject (readonly)

Returns the value of attribute uri


36
37
38
# File 'lib/heroku/plugin.rb', line 36

def uri
  @uri
end

Class Method Details

.check_for_deprecation(plugin) ⇒ Object


71
72
73
74
75
76
77
78
79
# File 'lib/heroku/plugin.rb', line 71

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


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

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

.listObject


42
43
44
45
46
# File 'lib/heroku/plugin.rb', line 42

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

.load!Object


48
49
50
51
52
53
54
# File 'lib/heroku/plugin.rb', line 48

def self.load!
  list.each do |plugin|
    check_for_deprecation(plugin)
    next if skip_plugins.include?(plugin)
    load_plugin(plugin)
  end
end

.load_plugin(plugin) ⇒ Object


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

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


67
68
69
# File 'lib/heroku/plugin.rb', line 67

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

.skip_pluginsObject


81
82
83
# File 'lib/heroku/plugin.rb', line 81

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

Instance Method Details

#installObject


98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/heroku/plugin.rb', line 98

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


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

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

#to_sObject


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

def to_s
  name
end

#uninstallObject


113
114
115
116
# File 'lib/heroku/plugin.rb', line 113

def uninstall
  ensure_plugin_exists
  FileUtils.rm_r(path)
end

#updateObject


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/heroku/plugin.rb', line 118

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 `heroku plugins:install`.
ERROR
      end
    end
  end
end