class Pry::PluginManager::Plugin

Attributes

active[RW]
active?[RW]
enabled[RW]
enabled?[RW]
gem_name[RW]
name[RW]
spec[RW]

Public Class Methods

new(name, gem_name, spec, enabled) click to toggle source
# File lib/pry/plugins.rb, line 28
def initialize(name, gem_name, spec, enabled)
  @name = name
  @gem_name = gem_name
  @enabled = enabled
  @spec = spec
end

Public Instance Methods

activate!() click to toggle source

Activate the plugin (require the gem - enables/loads the plugin immediately at point of call, even if plugin is disabled) Does not reload plugin if it's already active.

# File lib/pry/plugins.rb, line 62
def activate!
  # Create the configuration object for the plugin.
  Pry.config.send("#{gem_name.tr('-', '_')}=", OpenStruct.new)

  begin
    require gem_name unless active?
  rescue LoadError => e
    warn "Found plugin #{gem_name}, but could not require '#{gem_name}'"
    warn e
  rescue StandardError => e
    warn "require '#{gem_name}' # Failed, saying: #{e}"
  end

  self.active = true
  self.enabled = true
end
disable!() click to toggle source

Disable a plugin. (prevents plugin from being loaded, cannot disable an already activated plugin)

# File lib/pry/plugins.rb, line 37
def disable!
  self.enabled = false
end
enable!() click to toggle source

Enable a plugin. (does not load it immediately but puts on 'white list' to be loaded)

# File lib/pry/plugins.rb, line 43
def enable!
  self.enabled = true
end
load_cli_options() click to toggle source

Load the Command line options defined by this plugin (if they exist)

# File lib/pry/plugins.rb, line 48
def load_cli_options
  cli_options_file = File.join(spec.full_gem_path, "lib/#{spec.name}/cli.rb")
  return unless File.exist?(cli_options_file)

  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.4.4")
    cli_options_file = File.realpath(cli_options_file)
  end
  require cli_options_file
end
supported?() click to toggle source
# File lib/pry/plugins.rb, line 82
def supported?
  pry_version = Gem::Version.new(VERSION)
  spec.dependencies.each do |dependency|
    if dependency.name == "pry"
      return dependency.requirement.satisfied_by?(pry_version)
    end
  end
  true
end