123456789_123456789_123456789_123456789_123456789_

Class: Gem::StubSpecification

Relationships & Source Files
Namespace Children
Classes:
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.

Constant Summary

Class Method Summary

Instance Attribute Summary

BasicSpecification - Inherited

#activated?

True when the gem has been activated.

#base_dir

Returns the full path to the base gem directory.

#default_gem?,
#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.

#stubbed?

Whether this specification is stubbed - i.e.

#have_extensions?,
#base_dir=

Allows installation of extensions for git: gems.

#extension_dir=

Sets the directory where extensions for this gem will be installed.

#full_gem_path=

Allows correct activation of git: and path: gems.

#ignored=

Is this specification ignored for activation purposes?

Instance Method Summary

BasicSpecification - Inherited

#contains_requirable_file?

Return true if this spec can require file.

#datadir

The path to the data directory for this gem.

#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.

#lib_dirs_glob

Returns a string usable in Dir.glob to match all requirable paths for this spec.

#matches_for_glob

Return all files in this gem that match for glob.

#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.

#this,
#to_fullpath

Full path of the target library file.

#to_spec

Return a Specification from this gem.

#version

Version of the gem.

#have_file?,
#gem_build_complete_path

The path to the gem.build_complete file within the extension install directory.

#internal_init, #raw_require_paths, #find_full_gem_path

Constructor Details

.new(filename, base_dir, gems_dir, default_gem) ⇒ StubSpecification

[ GitHub ]

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

def initialize(filename, base_dir, gems_dir, default_gem)
  super()
  filename.tap(&Gem::UNTAINT)

  self.loaded_from = filename
  @data            = nil
  @name            = nil
  @spec            = nil
  @base_dir        = base_dir
  @gems_dir        = gems_dir
  @default_gem     = default_gem
end

Class Method Details

.default_gemspec_stub(filename, base_dir, gems_dir)

[ GitHub ]

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

def self.default_gemspec_stub(filename, base_dir, gems_dir)
  new filename, base_dir, gems_dir, true
end

.gemspec_stub(filename, base_dir, gems_dir)

[ GitHub ]

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

def self.gemspec_stub(filename, base_dir, gems_dir)
  new filename, base_dir, gems_dir, false
end

Instance Attribute Details

#activated?Boolean (readonly)

True when this gem has been activated

[ GitHub ]

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

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

#base_dir (readonly)

[ GitHub ]

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

attr_reader :base_dir, :gems_dir

#default_gem?Boolean (readonly)

[ GitHub ]

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

def default_gem?
  @default_gem
end

#gems_dir (readonly)

[ GitHub ]

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

attr_reader :base_dir, :gems_dir

#missing_extensions?Boolean (readonly)

[ GitHub ]

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

def missing_extensions?
  return false if default_gem?
  return false if extensions.empty?
  return false if File.exist? gem_build_complete_path

  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 212

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 205

def valid?
  data
end

Instance Method Details

#build_extensions

This method is for internal use only.
[ GitHub ]

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

def build_extensions # :nodoc:
  return if default_gem?
  return if extensions.empty?

  to_spec.build_extensions
end

#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 111

def data
  unless @data
    begin
      saved_lineno = $.

      File.open loaded_from, OPEN_MODE do |file|
        begin
          file.readline # discard encoding line
          stubline = file.readline.chomp
          if stubline.start_with?(PREFIX)
            extensions = if /\A#{PREFIX}/ =~ file.readline.chomp
                           $'.split "\0"
                         else
                           StubLine::NO_EXTENSIONS
                         end

            @data = StubLine.new stubline, extensions
          end
        rescue EOFError
        end
      end
    ensure
      $. = saved_lineno
    end
  end

  @data ||= to_spec
end

#extensions

Extensions for this gem

[ GitHub ]

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

def extensions
  data.extensions
end

#full_name

[ GitHub ]

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

def full_name
  data.full_name
end

#name

Name of the gem

[ GitHub ]

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

def name
  data.name
end

#platform

Platform of the gem

[ GitHub ]

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

def platform
  data.platform
end

#raw_require_paths

This method is for internal use only.
[ GitHub ]

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

def raw_require_paths # :nodoc:
  data.require_paths
end

#to_spec

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

[ GitHub ]

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

def to_spec
  @spec ||= if @data
              loaded = Gem.loaded_specs[name]
              loaded if loaded && loaded.version == version
            end

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

  @spec
end

#version

Version of the gem

[ GitHub ]

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

def version
  data.version
end