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. filter out the main retrospec gem, then filter out any plugin that is not a retrospec gem.

Returns an Array of Pathname objects.



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

def self.gem_directories
  dirs = []
  if has_rubygems?
   dirs = gemspecs.reject { |spec| spec.name == 'retrospec' }.map do |spec|
      lib_path = File.expand_path(File.join(spec.full_gem_path,'lib'))
      lib_path if File.exists? File.join(lib_path,'retrospec','plugins')
    end
  end
  dirs.reject { |dir| dir.nil? }
end

.gemspecsObject

Internal: Retrieve a list of available gemspecs.

Returns an Array of Gem::Specification objects.



48
49
50
51
52
53
54
# File 'lib/retrospec/plugin_loader.rb', line 48

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.

Returns:

  • (Boolean)


41
42
43
# File 'lib/retrospec/plugin_loader.rb', line 41

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
# File 'lib/retrospec/plugin_loader.rb', line 8

def self.load_from_gems(version='v1')
  gem_directories.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



34
35
36
# File 'lib/retrospec/plugin_loader.rb', line 34

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