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



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

def initialize
  @plugins = []
end

Instance Method Details

#gem_located?(gem_name) ⇒ Boolean (private)

Returns:

  • (Boolean)


98
99
100
# File 'lib/pry/plugins.rb', line 98

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

#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