mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
refactored plugin code: 1. should not warn when activate called twice on a gem that has already been activated (but ceases to be accessible due to bundler, robgleeson's bug). 2. calling activate on a non-existent plugin should warn not raise
This commit is contained in:
parent
be77470bd9
commit
aba38ea9e8
2 changed files with 19 additions and 9 deletions
|
@ -126,7 +126,6 @@ class Pry
|
|||
|
||||
ret = commands.run_command(context, command, *args)
|
||||
|
||||
# Tick, tock, im getting rid of this shit soon.
|
||||
options[:val].replace("")
|
||||
|
||||
ret
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
class Pry
|
||||
class PluginManager
|
||||
PRY_PLUGIN_PREFIX = /^pry-/
|
||||
PluginNotFound = Class.new(LoadError)
|
||||
|
||||
MessageSink = Object.new.tap { |o| def o.method_missing(*args) end }
|
||||
# Placeholder when no associated gem found, displays warning
|
||||
class NoPlugin
|
||||
def initialize(name)
|
||||
@name = name
|
||||
end
|
||||
|
||||
def method_missing(*args)
|
||||
$stderr.puts "Warning: The plugin '#{@name}' was not found! (no gem found)"
|
||||
end
|
||||
end
|
||||
|
||||
class Plugin
|
||||
attr_accessor :name, :gem_name, :enabled, :spec, :active
|
||||
|
@ -12,22 +20,25 @@ class Pry
|
|||
@name, @gem_name, @enabled, @spec = name, gem_name, enabled, spec
|
||||
end
|
||||
|
||||
# Disable a plugin.
|
||||
# Disable a plugin. (prevents plugin from being loaded, cannot
|
||||
# disable an already activated plugin)
|
||||
def disable!
|
||||
self.enabled = false
|
||||
end
|
||||
|
||||
# Enable a plugin.
|
||||
# Enable a plugin. (does not load it immediately but puts on
|
||||
# 'white list' to be loaded)
|
||||
def enable!
|
||||
self.enabled = true
|
||||
end
|
||||
|
||||
# Activate the plugin (require the gem).
|
||||
# Activate the plugin (require the gem - enables/loads the
|
||||
# plugin immediately at point of call, even if plugin is disabled)
|
||||
def activate!
|
||||
begin
|
||||
require gem_name
|
||||
require gem_name if !active?
|
||||
rescue LoadError
|
||||
$stderr.puts "Warning: The plugin '#{gem_name}' was not found!"
|
||||
$stderr.puts "Warning: The plugin '#{gem_name}' was not found! (gem found but could not be loaded)"
|
||||
end
|
||||
self.active = true
|
||||
self.enabled = true
|
||||
|
@ -55,7 +66,7 @@ class Pry
|
|||
# @return [Hash] A hash with all plugin names (minus the 'pry-') as
|
||||
# keys and Plugin objects as values.
|
||||
def plugins
|
||||
h = Pry.config.plugins.strict_loading ? {} : Hash.new { MessageSink }
|
||||
h = Hash.new { |_, key| NoPlugin.new(key) }
|
||||
@plugins.each do |plugin|
|
||||
h[plugin.name] = plugin
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue