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: ".freeze
OPEN_MODE =

:nodoc:

'r:UTF-8:-'.freeze

Instance Attribute Summary collapse

Attributes inherited from BasicSpecification

#extension_dir, #full_gem_path, #ignored, #loaded_from

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasicSpecification

#contains_requirable_file?, #datadir, default_specifications_dir, #extensions_dir, #full_require_paths, #gem_build_complete_path, #gem_dir, #internal_init, #lib_dirs_glob, #matches_for_glob, #plugins, #require_paths, #source_paths, #this, #to_fullpath

Methods included from Deprecate

#deprecate, next_rubygems_major_version, rubygems_deprecate, rubygems_deprecate_command, skip, skip=, skip_during

Constructor Details

#initialize(filename, base_dir, gems_dir, default_gem) ⇒ StubSpecification

Returns a new instance of StubSpecification.



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rubygems/stub_specification.rb', line 69

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

Instance Attribute Details

#base_dirObject (readonly)

Returns the value of attribute base_dir.



67
68
69
# File 'lib/rubygems/stub_specification.rb', line 67

def base_dir
  @base_dir
end

#gems_dirObject (readonly)

Returns the value of attribute gems_dir.



67
68
69
# File 'lib/rubygems/stub_specification.rb', line 67

def gems_dir
  @gems_dir
end

Class Method Details

.default_gemspec_stub(filename, base_dir, gems_dir) ⇒ Object



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

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) ⇒ Object



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

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

Instance Method Details

#activated?Boolean

True when this gem has been activated

Returns:

  • (Boolean)


85
86
87
88
89
90
91
# File 'lib/rubygems/stub_specification.rb', line 85

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

#build_extensionsObject

:nodoc:



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

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

  to_spec.build_extensions
end

#default_gem?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/rubygems/stub_specification.rb', line 93

def default_gem?
  @default_gem
end

#extensionsObject

Extensions for this gem



168
169
170
# File 'lib/rubygems/stub_specification.rb', line 168

def extensions
  data.extensions
end

#full_nameObject



179
180
181
# File 'lib/rubygems/stub_specification.rb', line 179

def full_name
  data.full_name
end

#missing_extensions?Boolean

Returns:

  • (Boolean)


143
144
145
146
147
148
149
# File 'lib/rubygems/stub_specification.rb', line 143

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

#nameObject

Name of the gem



154
155
156
# File 'lib/rubygems/stub_specification.rb', line 154

def name
  data.name
end

#platformObject

Platform of the gem



161
162
163
# File 'lib/rubygems/stub_specification.rb', line 161

def platform
  data.platform
end

#raw_require_pathsObject

:nodoc:



139
140
141
# File 'lib/rubygems/stub_specification.rb', line 139

def raw_require_paths # :nodoc:
  data.require_paths
end

#stubbed?Boolean

Is there a stub line present for this StubSpecification?

Returns:

  • (Boolean)


209
210
211
# File 'lib/rubygems/stub_specification.rb', line 209

def stubbed?
  data.is_a? StubLine
end

#to_specObject

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



186
187
188
189
190
191
192
193
194
195
196
# File 'lib/rubygems/stub_specification.rb', line 186

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

#valid?Boolean

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

Returns:

  • (Boolean)


202
203
204
# File 'lib/rubygems/stub_specification.rb', line 202

def valid?
  data
end

#versionObject

Version of the gem



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

def version
  data.version
end