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

#initializePluginManager

Returns a new instance of PluginManager



75
76
77
# File 'lib/pry/plugins.rb', line 75

def initialize
  @plugins = []
end

Instance Method Details

#gem_listObject (private)



112
113
114
115
# File 'lib/pry/plugins.rb', line 112

def gem_list
  Gem.refresh
  Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')
end

#load_pluginsObject

Require all enabled plugins, disabled plugins are skipped.



101
102
103
104
105
# File 'lib/pry/plugins.rb', line 101

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.



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

def locate_plugins
  gem_list.each do |gem|
    next if gem.name !~ PRY_PLUGIN_PREFIX
    plugin_name = gem.name.split('-', 2).last
    plugin = Plugin.new(plugin_name, gem.name, gem, false)
    @plugins << plugin.tap(&:enable!) if plugin.supported? && !plugin_located?(plugin)
  end
  @plugins
end

#plugin_located?(plugin) ⇒ Boolean (private)

Returns:

  • (Boolean)


108
109
110
# File 'lib/pry/plugins.rb', line 108

def plugin_located?(plugin)
  @plugins.any? { |existing| existing.gem_name == plugin.gem_name }
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.



92
93
94
95
96
97
98
# File 'lib/pry/plugins.rb', line 92

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