### Home Classes Methods

### In Files

- lib/yard/rubygems/backports/source_index.rb

### Parent

Object

### Methods

- ::from_gems_in
- ::from_installed_gems
- ::installed_spec_directories
- ::load_specification
- ::new
- #add_spec
- #add_specs
- #all_gems
- #dump
- #each
- #find_name
- #gem_signature
- #index_signature
- #latest_specs
- #length
- #load_gems_in
- #old_initialize
- #outdated
- #prerelease_gems
- #prerelease_specs
- #refresh!
- #released_gems
- #released_specs
- #remove_spec
- #search
- #size
- #specification

### Included Modules

- Enumerable

### Files

- LICENSE.txt
- MIT.txt

### Class/Module Index

Quicksearch

- YARD
- YARD::CLI
- YARD::CLI::Command
- YARD::CLI::CommandParser
- YARD::CLI::Config
- YARD::CLI::Diff
- YARD::CLI::Display
- YARD::CLI::Gems
- YARD::CLI::Graph
- YARD::CLI::GraphOptions
- YARD::CLI::Help
- YARD::CLI::I18n
- YARD::CLI::List
- YARD::CLI::MarkupTypes
- YARD::CLI::Server
- YARD::CLI::Stats
- YARD::CLI::YRI
- YARD::CLI::Yardoc
- YARD::CLI::YardocOptions
- YARD::CLI::YardoptsCommand
- YARD::CodeObjects
- YARD::CodeObjects::Base
- YARD::CodeObjects::ClassObject
- YARD::CodeObjects::ClassVariableObject
- YARD::CodeObjects::CodeObjectList
- YARD::CodeObjects::ConstantObject
- YARD::CodeObjects::ExtendedMethodObject
- YARD::CodeObjects::ExtraFileObject
- YARD::CodeObjects::MacroObject
- YARD::CodeObjects::MethodObject
- YARD::CodeObjects::ModuleObject
- YARD::CodeObjects::NamespaceObject
- YARD::CodeObjects::Proxy
- YARD::CodeObjects::ProxyMethodError
- YARD::CodeObjects::RootObject
- YARD::Config
- YARD::Docstring
- YARD::DocstringParser
- YARD::Handlers
- YARD::Handlers::Base
- YARD::Handlers::C
- YARD::Handlers::C::AliasHandler
- YARD::Handlers::C::AttributeHandler
- YARD::Handlers::C::Base
- YARD::Handlers::C::ClassHandler
- YARD::Handlers::C::ConstantHandler
- YARD::Handlers::C::HandlerMethods
- YARD::Handlers::C::InitHandler
- YARD::Handlers::C::MethodHandler
- YARD::Handlers::C::MixinHandler
- YARD::Handlers::C::ModuleHandler
- YARD::Handlers::C::OverrideCommentHandler
- YARD::Handlers::C::PathHandler
- YARD::Handlers::C::StructHandler
- YARD::Handlers::C::SymbolHandler
- YARD::Handlers::HandlerAborted
- YARD::Handlers::NamespaceMissingError
- YARD::Handlers::Processor
- YARD::Handlers::Ruby
- YARD::Handlers::Ruby::AliasHandler
- YARD::Handlers::Ruby::AttributeHandler
- YARD::Handlers::Ruby::Base
- YARD::Handlers::Ruby::ClassConditionHandler
- YARD::Handlers::Ruby::ClassHandler
- YARD::Handlers::Ruby::ClassVariableHandler
- YARD::Handlers::Ruby::CommentHandler
- YARD::Handlers::Ruby::ConstantHandler
- YARD::Handlers::Ruby::DSLHandler
- YARD::Handlers::Ruby::DSLHandlerMethods
- YARD::Handlers::Ruby::ExceptionHandler
- YARD::Handlers::Ruby::ExtendHandler
- YARD::Handlers::Ruby::HandlesExtension
- YARD::Handlers::Ruby::Legacy
- YARD::Handlers::Ruby::Legacy::AliasHandler
- YARD::Handlers::Ruby::Legacy::AttributeHandler
- YARD::Handlers::Ruby::Legacy::Base
- YARD::Handlers::Ruby::Legacy::ClassConditionHandler
- YARD::Handlers::Ruby::Legacy::ClassHandler
- YARD::Handlers::Ruby::Legacy::ClassVariableHandler
- YARD::Handlers::Ruby::Legacy::CommentHandler
- YARD::Handlers::Ruby::Legacy::ConstantHandler
- YARD::Handlers::Ruby::Legacy::DSLHandler
- YARD::Handlers::Ruby::Legacy::ExceptionHandler
- YARD::Handlers::Ruby::Legacy::ExtendHandler
- YARD::Handlers::Ruby::Legacy::MethodHandler
- YARD::Handlers::Ruby::Legacy::MixinHandler
- YARD::Handlers::Ruby::Legacy::ModuleFunctionHandler
- YARD::Handlers::Ruby::Legacy::ModuleHandler
- YARD::Handlers::Ruby::Legacy::PrivateConstantHandler
- YARD::Handlers::Ruby::Legacy::VisibilityHandler
- YARD::Handlers::Ruby::Legacy::YieldHandler
- YARD::Handlers::Ruby::MethodCallWrapper
- YARD::Handlers::Ruby::MethodConditionHandler
- YARD::Handlers::Ruby::MethodHandler
- YARD::Handlers::Ruby::MixinHandler
- YARD::Handlers::Ruby::ModuleFunctionHandler
- YARD::Handlers::Ruby::ModuleHandler
- YARD::Handlers::Ruby::PrivateConstantHandler
- YARD::Handlers::Ruby::StructHandlerMethods
- YARD::Handlers::Ruby::TestNodeWrapper
- YARD::Handlers::Ruby::VisibilityHandler
- YARD::Handlers::Ruby::YieldHandler
- YARD::I18n
- YARD::I18n::Locale
- YARD::I18n::Message
- YARD::I18n::Messages
- YARD::I18n::PotGenerator
- YARD::I18n::Text
- YARD::Logger
- YARD::Options
- YARD::Parser
- YARD::Parser::Base
- YARD::Parser::C
- YARD::Parser::C::BodyStatement
- YARD::Parser::C::CParser
- YARD::Parser::C::Comment
- YARD::Parser::C::CommentParser
- YARD::Parser::C::Statement
- YARD::Parser::C::ToplevelStatement
- YARD::Parser::OrderedParser
- YARD::Parser::ParserSyntaxError
- YARD::Parser::Ruby
- YARD::Parser::Ruby::AstNode
- YARD::Parser::Ruby::ClassNode
- YARD::Parser::Ruby::CommentNode
- YARD::Parser::Ruby::ConditionalNode
- YARD::Parser::Ruby::KeywordNode
- YARD::Parser::Ruby::Legacy
- YARD::Parser::Ruby::Legacy::RubyLex
- YARD::Parser::Ruby::Legacy::RubyLex::BufferedReader
- YARD::Parser::Ruby::Legacy::RubyParser
- YARD::Parser::Ruby::Legacy::RubyToken
- YARD::Parser::Ruby::Legacy::RubyToken::TkBlockContents
- YARD::Parser::Ruby::Legacy::RubyToken::TkError
- YARD::Parser::Ruby::Legacy::RubyToken::TkId
- YARD::Parser::Ruby::Legacy::RubyToken::TkKW
- YARD::Parser::Ruby::Legacy::RubyToken::TkNode
- YARD::Parser::Ruby::Legacy::RubyToken::TkOPASGN
- YARD::Parser::Ruby::Legacy::RubyToken::TkOp
- YARD::Parser::Ruby::Legacy::RubyToken::TkStatementEnd
- YARD::Parser::Ruby::Legacy::RubyToken::TkUnknownChar
- YARD::Parser::Ruby::Legacy::RubyToken::TkVal
- YARD::Parser::Ruby::Legacy::RubyToken::TkWhitespace
- YARD::Parser::Ruby::Legacy::RubyToken::Token
- YARD::Parser::Ruby::Legacy::Statement
- YARD::Parser::Ruby::Legacy::StatementList
- YARD::Parser::Ruby::Legacy::TokenList
- YARD::Parser::Ruby::LiteralNode
- YARD::Parser::Ruby::LoopNode
- YARD::Parser::Ruby::MethodCallNode
- YARD::Parser::Ruby::MethodDefinitionNode
- YARD::Parser::Ruby::ModuleNode
- YARD::Parser::Ruby::ParameterNode
- YARD::Parser::Ruby::ReferenceNode
- YARD::Parser::Ruby::RipperParser
- YARD::Parser::Ruby::RubyParser
- YARD::Parser::SourceParser
- YARD::Parser::UndocumentableError
- YARD::Rake
- YARD::Rake::YardocTask
- YARD::Registry
- YARD::RegistryStore
- YARD::Serializers
- YARD::Serializers::Base
- YARD::Serializers::FileSystemSerializer
- YARD::Serializers::ProcessSerializer
- YARD::Serializers::StdoutSerializer
- YARD::Serializers::YardocSerializer
- YARD::Server
- YARD::Server::Adapter
- YARD::Server::Commands
- YARD::Server::Commands::Base
- YARD::Server::Commands::DisplayFileCommand
- YARD::Server::Commands::DisplayObjectCommand
- YARD::Server::Commands::FramesCommand
- YARD::Server::Commands::LibraryCommand
- YARD::Server::Commands::LibraryIndexCommand
- YARD::Server::Commands::LibraryOptions
- YARD::Server::Commands::ListCommand
- YARD::Server::Commands::SearchCommand
- YARD::Server::Commands::StaticFileCommand
- YARD::Server::DocServerHelper
- YARD::Server::DocServerSerializer
- YARD::Server::FinishRequest
- YARD::Server::LibraryNotPreparedError
- YARD::Server::LibraryVersion
- YARD::Server::NotFoundError
- YARD::Server::RackAdapter
- YARD::Server::RackMiddleware
- YARD::Server::Router
- YARD::Server::StaticCaching
- YARD::Server::WebrickAdapter
- YARD::Server::WebrickServlet
- YARD::StubProxy
- YARD::Tags
- YARD::Tags::AttributeDirective
- YARD::Tags::DefaultFactory
- YARD::Tags::DefaultTag
- YARD::Tags::Directive
- YARD::Tags::EndGroupDirective
- YARD::Tags::GroupDirective
- YARD::Tags::Library
- YARD::Tags::MacroDirective
- YARD::Tags::MethodDirective
- YARD::Tags::OptionTag
- YARD::Tags::OverloadTag
- YARD::Tags::ParseDirective
- YARD::Tags::RefTag
- YARD::Tags::RefTagList
- YARD::Tags::ScopeDirective
- YARD::Tags::Tag
- YARD::Tags::TagFormatError
- YARD::Tags::VisibilityDirective
- YARD::Templates
- YARD::Templates::Engine
- YARD::Templates::ErbCache
- YARD::Templates::Helpers
- YARD::Templates::Helpers::BaseHelper
- YARD::Templates::Helpers::FilterHelper
- YARD::Templates::Helpers::HtmlHelper
- YARD::Templates::Helpers::HtmlSyntaxHighlightHelper
- YARD::Templates::Helpers::Markup
- YARD::Templates::Helpers::Markup::RDocMarkdown
- YARD::Templates::Helpers::Markup::RDocMarkup
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkup
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkup::RDocMarkupToHtml
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkupToHtml
- YARD::Templates::Helpers::MarkupHelper
- YARD::Templates::Helpers::MethodHelper
- YARD::Templates::Helpers::ModuleHelper
- YARD::Templates::Helpers::TextHelper
- YARD::Templates::Helpers::UMLHelper
- YARD::Templates::Section
- YARD::Templates::Template
- YARD::Templates::Template::ClassMethods
- YARD::Templates::TemplateOptions
- YARD::Verifier
- Gem
- Gem::DocManager
- Gem::SourceIndex
- Gem::Specification
- Rack
- Rack::Request
- WEBrick
- WEBrick::HTTPRequest
- Array
- File
- Hash
- Insertion
- Module
- Object
- String
- SymbolHash

No matching classes.

# Gem::SourceIndex

The SourceIndex object indexes all the gems available from a particular source (e.g. a list of gem directories, or a remote source). A SourceIndex maps a gem full name to a gem specification.

NOTE | The class used to be named Cache, but that became confusing when cached source fetchers where introduced. The constant Gem::Cache is an alias for this class to allow old YAMLized source index objects to load properly.

### Attributes

spec_dirs[RW]

Directories to use to refresh this SourceIndex when calling refresh!

### Public Class Methods

from_gems_in(*spec_dirs) click to toggle source

Creates a new SourceIndex from the ruby format gem specifications in `spec_dirs`.

    # File lib/yard/rubygems/backports/source_index.rb, line 81
    def from_gems_in(*spec_dirs)
      source_index = new
      source_index.spec_dirs = spec_dirs
      source_index.refresh!
    end

from_installed_gems(*deprecated) click to toggle source

Factory method to construct a source index instance for a given path.

deprecated | If supplied, from_installed_gems will act just like `from_gems_in`. This argument is deprecated and is provided just for backwards compatibility, and should not generally be used.
return | SourceIndex instance

    # File lib/yard/rubygems/backports/source_index.rb, line 62
    def from_installed_gems(*deprecated)
      if deprecated.empty?
        from_gems_in(*installed_spec_directories)
      else
        from_gems_in(*deprecated) # HACK warn
      end
    end

installed_spec_directories() click to toggle source

Returns a list of directories from Gem.path that contain specifications.

    # File lib/yard/rubygems/backports/source_index.rb, line 73
    def installed_spec_directories
      Gem.path.collect { |dir| File.join(dir, "specifications") }
    end

load_specification(file_name) click to toggle source

Loads a ruby-format specification from `file_name` and returns the loaded spec.

    # File lib/yard/rubygems/backports/source_index.rb, line 91
    def load_specification(file_name)
      Gem::Specification.load file_name
    end

new(specifications={}) click to toggle source

Constructs a source index instance from the provided specifications, which is a Hash of gem full names and Gem::Specifications.

    # File lib/yard/rubygems/backports/source_index.rb, line 104
    def initialize(specifications={})
      @gems = {}
      specifications.each{ |full_name, spec| add_spec spec }
      @spec_dirs = nil
    end

Also aliased as: old_initialize

### Public Instance Methods

add_spec(gem_spec, name = gem_spec.full_name) click to toggle source

Add a gem specification to the source index.

    # File lib/yard/rubygems/backports/source_index.rb, line 195
    def add_spec(gem_spec, name = gem_spec.full_name)
      # No idea why, but the Indexer wants to insert them using original_name
      # instead of full_name. So we make it an optional arg.
      @gems[name] = gem_spec
    end

add_specs(*gem_specs) click to toggle source

Add gem specifications to the source index.

    # File lib/yard/rubygems/backports/source_index.rb, line 204
    def add_specs(*gem_specs)
      gem_specs.each do |spec|
        add_spec spec
      end
    end

all_gems() click to toggle source

TODO: remove method

    # File lib/yard/rubygems/backports/source_index.rb, line 111
    def all_gems
      @gems
    end

dump() click to toggle source

    # File lib/yard/rubygems/backports/source_index.rb, line 354
    def dump
      Marshal.dump(self)
    end

each() click to toggle source

Iterate over the specifications in the source index.

    # File lib/yard/rubygems/backports/source_index.rb, line 220
    def each(&block) # :yields: gem.full_name, gem
      @gems.each(&block)
    end

find_name(gem_name, requirement = Gem::Requirement.default) click to toggle source

Find a gem by an exact match on the short name.

    # File lib/yard/rubygems/backports/source_index.rb, line 258
    def find_name(gem_name, requirement = Gem::Requirement.default)
      dep = Gem::Dependency.new gem_name, requirement
      search dep
    end

gem_signature(gem_full_name) click to toggle source

The signature for the given gem specification.

    # File lib/yard/rubygems/backports/source_index.rb, line 244
    def gem_signature(gem_full_name)
      require 'digest'

      Digest::SHA256.new.hexdigest(@gems[gem_full_name].to_yaml).to_s
    end

index_signature() click to toggle source

The signature for the source index. Changes in the signature indicate a change in the index.

    # File lib/yard/rubygems/backports/source_index.rb, line 235
    def index_signature
      require 'digest'

      Digest::SHA256.new.hexdigest(@gems.keys.sort.join(',')).to_s
    end

latest_specs(include_prerelease=false) click to toggle source

Returns an Array specifications for the latest released versions of each gem in this index.

    # File lib/yard/rubygems/backports/source_index.rb, line 145
    def latest_specs(include_prerelease=false)
      result = Hash.new { |h,k| h[k] = [] }
      latest = {}

      sort.each do |_, spec|
        name = spec.name
        curr_ver = spec.version
        prev_ver = latest.key?(name) ? latest[name].version : nil

        next if !include_prerelease && curr_ver.prerelease?
        next unless prev_ver.nil? or curr_ver >= prev_ver or
                    latest[name].platform != Gem::Platform::RUBY

        if prev_ver.nil? or
           (curr_ver > prev_ver and spec.platform == Gem::Platform::RUBY) then
          result[name].clear
          latest[name] = spec
        end

        if spec.platform != Gem::Platform::RUBY then
          result[name].delete_if do |result_spec|
            result_spec.platform == spec.platform
          end
        end

        result[name] << spec
      end

      # TODO: why is this a hash while @gems is an array? Seems like
      # structural similarity would be good.
      result.values.flatten
    end

length() click to toggle source
Alias for: size
load_gems_in(*spec_dirs) click to toggle source

Reconstruct the source index from the specifications in `spec_dirs`.

    # File lib/yard/rubygems/backports/source_index.rb, line 126
    def load_gems_in(*spec_dirs)
      @gems.clear

      spec_dirs.reverse_each do |spec_dir|
        spec_files = Dir.glob File.join(spec_dir, '*.gemspec')

        spec_files.each do |spec_file|
          gemspec = Gem::Specification.load spec_file
          add_spec gemspec if gemspec
        end
      end

      self
    end

old_initialize(specifications={}) click to toggle source

Undef old methods

Alias for: new
outdated() click to toggle source

Returns an Array of Gem::Specifications that are not up to date.

    # File lib/yard/rubygems/backports/source_index.rb, line 332
    def outdated
      outdateds = []

      latest_specs.each do |local|
        dependency = Gem::Dependency.new local.name, ">= #{local.version}"

        fetcher = Gem::SpecFetcher.fetcher
        remotes = fetcher.find_matching dependency
        remotes = remotes.map { |(_, version, _), _| version }

        latest = remotes.sort.last

        outdateds << local.name if latest and local.version < latest
      end

      outdateds
    end

prerelease_gems() click to toggle source

    # File lib/yard/rubygems/backports/source_index.rb, line 115
    def prerelease_gems
      @gems.reject{ |name, gem| !gem.version.prerelease? }
    end

prerelease_specs() click to toggle source

An array including only the prerelease gemspecs

    # File lib/yard/rubygems/backports/source_index.rb, line 181
    def prerelease_specs
      prerelease_gems.values
    end

refresh!() click to toggle source

Replaces the gems in the source index from specifications in the directories this source index was created from. Raises an exception if this source index wasn't created from a directory (via from_gems_in or from_installed_gems, or having spec_dirs set).

    # File lib/yard/rubygems/backports/source_index.rb, line 324
    def refresh!
      raise 'source index not created from disk' if @spec_dirs.nil?
      load_gems_in(*@spec_dirs)
    end

released_gems() click to toggle source

    # File lib/yard/rubygems/backports/source_index.rb, line 119
    def released_gems
      @gems.reject{ |name, gem| gem.version.prerelease? }
    end

released_specs() click to toggle source

An array including only the released gemspecs

    # File lib/yard/rubygems/backports/source_index.rb, line 188
    def released_specs
      released_gems.values
    end

remove_spec(full_name) click to toggle source

Remove a gem specification named `full_name`.

    # File lib/yard/rubygems/backports/source_index.rb, line 213
    def remove_spec(full_name)
      @gems.delete full_name
    end

search(gem_pattern, platform_only = false) click to toggle source

Search for a gem by Gem::Dependency `gem_pattern`. If `only_platform` is true, only gems matching Gem::Platform.local will be returned. An Array of matching Gem::Specification objects is returned.

For backwards compatibility, a String or Regexp pattern may be passed as `gem_pattern`, and a Gem::Requirement for `platform_only`. This behavior is deprecated and will be removed.

    # File lib/yard/rubygems/backports/source_index.rb, line 272
    def search(gem_pattern, platform_only = false)
      requirement = nil
      only_platform = false

      # TODO - Remove support and warning for legacy arguments after 2008/11
      unless Gem::Dependency === gem_pattern
        warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated, use #find_name"
      end

      case gem_pattern
      when Regexp then
        requirement = platform_only || Gem::Requirement.default
      when Gem::Dependency then
        only_platform = platform_only
        requirement = gem_pattern.requirement

        gem_pattern = if Regexp === gem_pattern.name then
                        gem_pattern.name
                      elsif gem_pattern.name.empty? then
                        //
                      else
                        /^#{Regexp.escape gem_pattern.name}$/
                      end
      else
        requirement = platform_only || Gem::Requirement.default
        gem_pattern = /#{gem_pattern}/
      end

      unless Gem::Requirement === requirement then
        requirement = Gem::Requirement.create requirement
      end

      specs = all_gems.values.select do |spec|
        spec.name =~ gem_pattern and
          requirement.satisfied_by? spec.version
      end

      if only_platform then
        specs = specs.select do |spec|
          Gem::Platform.match spec.platform
        end
      end

      specs.sort_by { |s| s.sort_obj }
    end

size() click to toggle source

    # File lib/yard/rubygems/backports/source_index.rb, line 250
    def size
      @gems.size
    end

Also aliased as: length
specification(full_name) click to toggle source

The gem specification given a full gem spec name.

    # File lib/yard/rubygems/backports/source_index.rb, line 227
    def specification(full_name)
      @gems[full_name]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.