Class: Pry::PluginManager

Inherits:
Object show all
Defined in:
lib/pry/plugins.rb

Defined Under Namespace

Classes: NoPlugin, Plugin

Constant Summary

PRY_PLUGIN_PREFIX =
/^pry-/

Instance Method Summary (collapse)

Constructor Details

- (PluginManager) initialize

Returns a new instance of PluginManager



63
64
65
# File 'lib/pry/plugins.rb', line 63

def initialize
  @plugins = []
end

Instance Method Details

- (Boolean) gem_located?(gem_name) (private)

Returns:

  • (Boolean)


96
97
98
# File 'lib/pry/plugins.rb', line 96

def gem_located?(gem_name)
  @plugins.any? { |plugin| plugin.gem_name == gem_name }
end

- (Object) load_plugins

Require all enabled plugins, disabled plugins are skipped.



89
90
91
92
93
# File 'lib/pry/plugins.rb', line 89

def load_plugins
  @plugins.each do |plugin|
    plugin.activate! if plugin.enabled?
  end
end

- (Object) locate_plugins

Find all installed Pry plugins and store them in an internal array.



68
69
70
71
72
73
74
75
76
# File 'lib/pry/plugins.rb', line 68

def locate_plugins
  Gem.refresh
  (Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')).each do |gem|
    next if gem.name !~ PRY_PLUGIN_PREFIX
    plugin_name = gem.name.split('-', 2).last
    @plugins << Plugin.new(plugin_name, gem.name, gem, true) if !gem_located?(gem.name)
  end
  @plugins
end

- (Hash) plugins

Returns A hash with all plugin names (minus the 'pry-') as keys and Plugin objects as values.

Returns:

  • (Hash)

    A hash with all plugin names (minus the 'pry-') as keys and Plugin objects as values.



80
81
82
83
84
85
86
# File 'lib/pry/plugins.rb', line 80

def plugins
  h = Hash.new { |_, key| NoPlugin.new(key) }
  @plugins.each do |plugin|
    h[plugin.name] = plugin
  end
  h
end