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, #ignored, #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, #source_paths, #to_fullpath

Constructor Details

#initialize(filename) ⇒ StubSpecification

Returns a new instance of StubSpecification.



41
42
43
44
45
46
47
# 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 Method Details

#activated?Boolean

True when this gem has been activated

Returns:

  • (Boolean)


52
53
54
55
56
57
58
# File 'lib/rubygems/stub_specification.rb', line 52

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

#build_extensionsObject

:nodoc:



60
61
62
63
64
65
# File 'lib/rubygems/stub_specification.rb', line 60

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

  to_spec.build_extensions
end

#extensionsObject

Extensions for this gem



98
99
100
101
102
103
104
# File 'lib/rubygems/stub_specification.rb', line 98

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.



111
112
113
114
115
# File 'lib/rubygems/stub_specification.rb', line 111

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.



121
122
123
124
125
# File 'lib/rubygems/stub_specification.rb', line 121

def full_require_paths
  @require_paths ||= data.require_paths

  super
end

#missing_extensions?Boolean

Returns:

  • (Boolean)


127
128
129
130
131
132
# 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

#nameObject

Name of the gem



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

def name
  @name ||= data.name
end

#platformObject

Platform of the gem



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

def platform
  @platform ||= data.platform
end

#require_pathsObject

Require paths of the gem



151
152
153
154
155
# File 'lib/rubygems/stub_specification.rb', line 151

def require_paths
  @require_paths ||= data.require_paths

  super
end

#stubbed?Boolean

Is there a stub line present for this StubSpecification?

Returns:

  • (Boolean)


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

def stubbed?
  data.is_a? StubLine
end

#to_specObject

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



160
161
162
163
164
165
166
167
168
169
170
171
# 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

#valid?Boolean

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

Returns:

  • (Boolean)


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

def valid?
  data
end

#versionObject

Version of the gem



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

def version
  @version ||= data.version
end