Sha256: f70bfede4ea15c5c2a3f0fdff94e358441965192438a1ab21bf6cd84c6e69ab7

Contents?: true

Size: 1.59 KB

Versions: 1

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

1 entries across 1 versions & 1 rubygems

Version Path
retrospec-0.1.0 lib/retrospec/plugin_loader.rb