class Slugforge::SluginManager

Constants

PREFIX

Public Class Methods

new() click to toggle source
# File lib/slugforge/slugins.rb, line 83
def initialize
  @slugins = []
  locate_slugins
end

Public Instance Methods

activate_slugins(config) click to toggle source
# File lib/slugforge/slugins.rb, line 103
def activate_slugins(config)
  @slugins.each { |s| s.activate!(config) if s.enabled? }
end
load_slugins() click to toggle source

Require all enabled slugins, disabled slugins are skipped.

# File lib/slugforge/slugins.rb, line 99
def load_slugins
  @slugins.each(&:load!)
end
slugins() click to toggle source

@return [Hash] A hash with all slugin names (minus the prefix) as

keys and slugin objects as values.
# File lib/slugforge/slugins.rb, line 90
def slugins
  h = Hash.new { |_, key| NoSlugin.new(key) }
  @slugins.each do |slugin|
    h[slugin.name] = slugin
  end
  h
end

Private Instance Methods

gem_located?(gem_name) click to toggle source
# File lib/slugforge/slugins.rb, line 120
def gem_located?(gem_name)
  @slugins.any? { |slugin| slugin.gem_name == gem_name }
end
locate_slugins() click to toggle source

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

# File lib/slugforge/slugins.rb, line 110
def locate_slugins
  Gem.refresh
  (Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')).each do |gem|
    next if gem.name !~ PREFIX
    slugin_name = gem.name.split('-', 2).last
    @slugins << Slugin.new(slugin_name, gem.name, gem, true) if !gem_located?(gem.name)
  end
  @slugins
end