Class: Gem::StubSpecification

Inherits:
BasicSpecification show all
Defined in:
lib/rubygems/stub_specification.rb

Overview

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

Defined Under Namespace

Classes: StubLine

Constant Summary collapse

PREFIX =

:nodoc:

"# stub: "
OPEN_MODE =

:nodoc:

if Object.const_defined? :Encoding then
  'r:UTF-8:-'
else
  'r'
end

Instance Attribute Summary

Attributes inherited from BasicSpecification

#base_dir, #extension_dir, #full_gem_path, #loaded_from

Instance Method Summary collapse

Methods inherited from BasicSpecification

#contains_requirable_file?, #default_gem?, default_specifications_dir, #extensions_dir, #full_name, #gem_dir, #gems_dir, #raw_require_paths

Constructor Details

#initialize(filename) ⇒ StubSpecification

Returns a new instance of StubSpecification.



41
42
43
44
45
46
# File 'lib/rubygems/stub_specification.rb', line 41

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

Instance Method Details

#activated?Boolean

True when this gem has been activated

Returns:

  • (Boolean)


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

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

#build_extensionsObject

:nodoc:



56
57
58
59
60
61
# File 'lib/rubygems/stub_specification.rb', line 56

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

  to_spec.build_extensions
end

#extensionsObject

Extensions for this gem



94
95
96
97
98
99
100
# File 'lib/rubygems/stub_specification.rb', line 94

def extensions
  return @extensions if @extensions

  data # load

  @extensions
end

#find_full_gem_pathObject

If a gem has a stub specification it doesn’t need to bother with compatibility with original_name gems. It was installed with the normalized name.



107
108
109
110
111
# File 'lib/rubygems/stub_specification.rb', line 107

def find_full_gem_path # :nodoc:
  path = File.expand_path File.join gems_dir, full_name
  path.untaint
  path
end

#full_require_pathsObject

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



117
118
119
120
121
# File 'lib/rubygems/stub_specification.rb', line 117

def full_require_paths
  @require_paths ||= data.require_paths

  super
end

#nameObject

Name of the gem



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

def name
  @name ||= data.name
end

#platformObject

Platform of the gem



133
134
135
# File 'lib/rubygems/stub_specification.rb', line 133

def platform
  @platform ||= data.platform
end

#require_pathsObject

Require paths of the gem



140
141
142
143
144
# File 'lib/rubygems/stub_specification.rb', line 140

def require_paths
  @require_paths ||= data.require_paths

  super
end

#stubbed?Boolean

Is there a stub line present for this StubSpecification?

Returns:

  • (Boolean)


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

def stubbed?
  data.is_a? StubLine
end

#to_specObject

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



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

def to_spec
  @spec ||= Gem::Specification.load(loaded_from)
end

#valid?Boolean

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

Returns:

  • (Boolean)


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

def valid?
  data
end

#versionObject

Version of the gem



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

def version
  @version ||= data.version
end