Class: Pry::PluginManager

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

Defined Under Namespace

Classes: NoPlugin, Plugin

Constant Summary collapse

PRY_PLUGIN_PREFIX =
/^pry-/

Instance Method Summary collapse

Constructor Details

#initializePluginManager

Returns a new instance of PluginManager.



65
66
67
# File 'lib/pry/plugins.rb', line 65

def initialize
  @plugins = []
end

Instance Method Details

#load_pluginsObject

Require all enabled plugins, disabled plugins are skipped.



91
92
93
94
95
# File 'lib/pry/plugins.rb', line 91

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

#locate_pluginsObject

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



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

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

#pluginsHash

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.



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

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