123456789_123456789_123456789_123456789_123456789_

Class: Gem::StubSpecification

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Gem::BasicSpecification
Defined in: lib/rubygems/stub_specification.rb

Overview

StubSpecification reads the stub: line from the gemspec. This prevents us having to eval the entire gemspec in order to find out certain information.

Class Method Summary

Instance Attribute Summary

BasicSpecification - Inherited

#base_dir

Returns the full path to the base gem directory.

#extension_dir

Returns full path to the directory where gem's extensions are installed.

#full_gem_path

The full path to the gem (install path + full name).

#loaded_from

The path this gemspec was loaded from.

#loaded_from=

Set the path the Specification was loaded from.

#activated?

True when the gem has been activated.

#default_gem?,
#stubbed?

Whether this specification is stubbed - i.e.

Instance Method Summary

BasicSpecification - Inherited

#contains_requirable_file?

Return true if this spec can require file.

#extensions_dir

Returns path to the extensions directory.

#full_name

Returns the full name (name-version) of this ::Gem.

#full_require_paths

Full paths in the gem to add to $LOAD_PATH when this gem is activated.

#gem_dir

Returns the full path to this spec's gem directory.

#gems_dir

Returns the full path to the gems directory containing this spec's gem directory.

#name

Name of the gem.

#platform

Platform of the gem.

#require_paths

Paths in the gem to add to $LOAD_PATH when this gem is activated.

#source_paths

Returns the paths to the source files for use with analysis and documentation tools.

#to_fullpath

Full path of the target library file.

#to_spec

Return a Specification from this gem.

#version

Version of the gem.

Constructor Details

.new(filename) ⇒ StubSpecification

[ GitHub ]

  
# File 'lib/rubygems/stub_specification.rb', line 41

def initialize(filename)
  self.loaded_from = filename
  @data            = nil
  @extensions      = nil
  @name            = nil
  @spec            = nil
end

Instance Attribute Details

#activated?Boolean (readonly)

True when this gem has been activated

[ GitHub ]

  
# File 'lib/rubygems/stub_specification.rb', line 52

def activated?
  @activated ||=
  begin
    loaded = Gem.loaded_specs[name]
    loaded && loaded.version == version
  end
end

#missing_extensions?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rubygems/stub_specification.rb', line 127

def missing_extensions?
  return false if default_gem?
  return false if extensions.empty?

  to_spec.missing_extensions?
end

#stubbed?Boolean (readonly)

Is there a stub line present for this StubSpecification?

[ GitHub ]

  
# File 'lib/rubygems/stub_specification.rb', line 191

def stubbed?
  data.is_a? StubLine
end

#valid?Boolean (readonly)

Is this StubSpecification valid? i.e. have we found a stub line, OR does the filename contain a valid gemspec?

[ GitHub ]

  
# File 'lib/rubygems/stub_specification.rb', line 177

def valid?
  data
end

Instance Method Details

#data (private)

If the gemspec contains a stubline, returns a StubSpecification::StubLine instance. Otherwise returns the full Specification.

[ GitHub ]

  
# File 'lib/rubygems/stub_specification.rb', line 71

def data
  unless @data
    @extensions = []

    open loaded_from, OPEN_MODE do |file|
      begin
        file.readline # discard encoding line
        stubline = file.readline.chomp
        if stubline.start_with?(PREFIX) then
          @data = StubLine.new stubline

          @extensions = $'.split "\0" if
            /\A#{PREFIX}/ =~ file.readline.chomp
        end
      rescue EOFError
      end
    end
  end

  @data ||= to_spec
end

#extensions

Extensions for this gem

[ GitHub ]

  
# File 'lib/rubygems/stub_specification.rb', line 98

def extensions
  return @extensions if @extensions

  data # load

  @extensions
end

#full_require_paths

Full paths in the gem to add to $LOAD_PATH when this gem is activated.

[ GitHub ]

  
# File 'lib/rubygems/stub_specification.rb', line 121

def full_require_paths
  @require_paths ||= data.require_paths

  super
end

#name

Name of the gem

[ GitHub ]

  
# File 'lib/rubygems/stub_specification.rb', line 137

def name
  @name ||= data.name
end

#platform

Platform of the gem

[ GitHub ]

  
# File 'lib/rubygems/stub_specification.rb', line 144

def platform
  @platform ||= data.platform
end

#require_paths

Require paths of the gem

[ GitHub ]

  
# File 'lib/rubygems/stub_specification.rb', line 151

def require_paths
  @require_paths ||= data.require_paths

  super
end

#to_spec

The full Specification for this gem, loaded from evalling its gemspec

[ GitHub ]

  
# File 'lib/rubygems/stub_specification.rb', line 160

def to_spec
  @spec ||= if @data then
              Gem.loaded_specs.values.find { |spec|
                spec.name == name and spec.version == version
              }
            end

  @spec ||= Gem::Specification.load(loaded_from)
  @spec.ignored = @ignored if instance_variable_defined? :@ignored

  @spec
end

#version

Version of the gem

[ GitHub ]

  
# File 'lib/rubygems/stub_specification.rb', line 184

def version
  @version ||= data.version
end