Sha256: 1472cb68a03545db839996001353b312c5850e17dc9ed87173a4815d093a81d7

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

require 'pathname'

module Retrospec
  module PluginLoader
    # Internal: Find any gems containing retrospec plugins and load the main file in them.
    #
    # Returns nothing.
    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

    # Internal: Retrieve a list of available gem paths from RubyGems.
    #
    # Returns an Array of Pathname objects.
    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


    # returns a list of retrospec gem plugin specs
    def self.retrospec_gem_list
      gemspecs.reject { |spec| spec.name == 'retrospec' or ! File.directory?(File.join(spec.full_gem_path,'lib','retrospec','plugins')) }
    end

    # Internal: Check if RubyGems is loaded and available.
    #
    # Returns true if RubyGems is available, false if not.
    def self.has_rubygems?
      defined? ::Gem
    end

    # Internal: Retrieve a list of available gemspecs.
    #
    # Returns an Array of Gem::Specification objects.
    def self.gemspecs
      @gemspecs ||= if Gem::Specification.respond_to?(:latest_specs)
                      Gem::Specification.latest_specs
                    else
                      Gem.searcher.init_gemspecs
                    end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
retrospec-0.2.1 lib/retrospec/plugin_loader.rb
retrospec-0.2.0 lib/retrospec/plugin_loader.rb