Module: Retrospec::PluginLoader

Defined in:
lib/retrospec/plugin_loader.rb

Class Method Summary collapse

Class Method Details

.gem_directoriesObject

Internal: Retrieve a list of available gem paths from RubyGems.

Returns an Array of Pathname objects.



20
21
22
23
24
25
26
27
28
# File 'lib/retrospec/plugin_loader.rb', line 20

def self.gem_directories
  if has_rubygems?
    gemspecs.reject { |spec| spec.name == 'retrospec' }.map do |spec|
      Pathname.new(spec.full_gem_path) + 'lib'
    end
  else
    []
  end
end

.gemspecsObject

Internal: Retrieve a list of available gemspecs.

Returns an Array of Gem::Specification objects.



45
46
47
48
49
50
51
# File 'lib/retrospec/plugin_loader.rb', line 45

def self.gemspecs
  @gemspecs ||= if Gem::Specification.respond_to?(:latest_specs)
                  Gem::Specification.latest_specs
                else
                  Gem.searcher.init_gemspecs
                end
end

.has_rubygems?Boolean

Internal: Check if RubyGems is loaded and available.

Returns true if RubyGems is available, false if not.



38
39
40
# File 'lib/retrospec/plugin_loader.rb', line 38

def self.has_rubygems?
  defined? ::Gem
end

.load_from_gems(version = 'v1') ⇒ Object

Internal: Find any gems containing retrospec plugins and load the main file in them.

Returns nothing.



8
9
10
11
12
13
14
15
# File 'lib/retrospec/plugin_loader.rb', line 8

def self.load_from_gems(version='v1')
  retorspec_plugin_paths = gem_directories.select { |path| (path + File.join('retrospec','plugins')).directory? }
  retorspec_plugin_paths.each do |gem_path|
    Dir[File.join(gem_path,'*.rb')].each do |file|
      load file
    end
  end
end

.retrospec_gem_listObject

returns a list of retrospec gem plugin specs



31
32
33
# File 'lib/retrospec/plugin_loader.rb', line 31

def self.retrospec_gem_list
  gemspecs.reject { |spec| spec.name == 'retrospec' or ! File.directory?(File.join(spec.full_gem_path,'lib','retrospec','plugins')) }
end