Class: Azuki::Plugin
Defined Under Namespace
Classes: ErrorUpdatingSymlinkPlugin
Constant Summary
collapse
- DEPRECATED_PLUGINS =
%w(
azuki-cedar
azuki-certs
azuki-credentials
azuki-kill
azuki-labs
azuki-logging
azuki-netrc
azuki-pgdumps
azuki-postgresql
azuki-releases
azuki-shared-postgresql
azuki-sql-console
azuki-status
azuki-stop
azuki-suggest
pgbackups-automate
pgcmd
azuki-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, 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.
94
95
96
97
|
# File 'lib/azuki/plugin.rb', line 94
def initialize(uri)
@uri = uri
guess_name(uri)
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
31
32
33
|
# File 'lib/azuki/plugin.rb', line 31
def name
@name
end
|
#uri ⇒ Object
Returns the value of attribute uri.
31
32
33
|
# File 'lib/azuki/plugin.rb', line 31
def uri
@uri
end
|
Class Method Details
.check_for_deprecation(plugin) ⇒ Object
80
81
82
83
84
85
86
87
88
|
# File 'lib/azuki/plugin.rb', line 80
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 ⇒ Object
33
34
35
|
# File 'lib/azuki/plugin.rb', line 33
def self.directory
File.expand_path("#{home_directory}/.azuki/plugins")
end
|
.list ⇒ Object
37
38
39
40
41
|
# File 'lib/azuki/plugin.rb', line 37
def self.list
Dir["#{directory}/*"].sort.map do |folder|
File.basename(folder)
end
end
|
.load_plugin(plugin) ⇒ Object
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/azuki/plugin.rb', line 65
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
76
77
78
|
# File 'lib/azuki/plugin.rb', line 76
def self.remove_plugin(plugin)
FileUtils.rm_rf("#{self.directory}/#{plugin}")
end
|
.skip_plugins ⇒ Object
90
91
92
|
# File 'lib/azuki/plugin.rb', line 90
def self.skip_plugins
@skip_plugins ||= ENV["SKIP_PLUGINS"].to_s.split(/[ ,]/)
end
|
Instance Method Details
#install ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/azuki/plugin.rb', line 107
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
|
#path ⇒ Object
103
104
105
|
# File 'lib/azuki/plugin.rb', line 103
def path
"#{self.class.directory}/#{name}"
end
|
#to_s ⇒ Object
99
100
101
|
# File 'lib/azuki/plugin.rb', line 99
def to_s
name
end
|
#uninstall ⇒ Object
122
123
124
125
|
# File 'lib/azuki/plugin.rb', line 122
def uninstall
ensure_plugin_exists
FileUtils.rm_r(path)
end
|
#update ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/azuki/plugin.rb', line 127
def update
ensure_plugin_exists
if File.symlink?(path)
raise Azuki::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 `azuki plugins:install`.
ERROR
end
end
end
end
|