Class: LibGems::Specification
- Inherits:
-
Object
- Object
- LibGems::Specification
- Defined in:
- lib/libgems/specification.rb
Overview
The Specification class contains the metadata for a LibGems. Typically defined in a .gemspec file or a Rakefile, and looks like this:
spec = LibGems::Specification.new do |s|
s.name = 'example'
s.version = '1.0'
s.summary = 'Example gem specification'
...
end
For a great way to package gems, use Hoe.
Constant Summary collapse
- NONEXISTENT_SPECIFICATION_VERSION =
The the version number of a specification that does not specify one (i.e. SlimGems 0.7 or earlier).
-1
- CURRENT_SPECIFICATION_VERSION =
The specification version applied to any new Specification instances created. This should be bumped whenever something in the spec format changes. – When updating this number, be sure to also update #to_ruby.
NOTE SlimGems < 1.2 cannot load specification versions > 2.
3
- SPECIFICATION_VERSION_HISTORY =
An informal list of changes to the specification. The highest-valued key should be equal to the CURRENT_SPECIFICATION_VERSION.
{ -1 => ["(#{LibGems::NAME} versions up to and including 0.7 did not have versioned specifications)"], 1 => [ 'Deprecated "test_suite_file" in favor of the new, but equivalent, "test_files"', '"test_file=x" is a shortcut for "test_files=[x]"' ], 2 => [ 'Added "required_rubygems_version"', 'Now forward-compatible with future versions', ], 3 => [ 'Added Fixnum validation to the specification_version' ] }
- MARSHAL_FIELDS =
:stopdoc:
{ -1 => 16, 1 => 16, 2 => 16, 3 => 17 }
- TODAY =
now - ((now.to_i + now.gmt_offset) % 86400)
- @@gather =
Optional block used to gather newly defined instances.
nil
- @@required_attributes =
List of attribute names: [:name, :version, …]
[]
- @@attributes =
List of all attributes and default values:
[[:name, nil], [:bindir, 'bin'], ...]
[]
- @@nil_attributes =
[]
- @@non_nil_attributes =
[:@original_platform]
- @@array_attributes =
List of array attributes
[]
- @@default_value =
Map of attribute names to default values.
{}
Instance Attribute Summary collapse
-
#loaded ⇒ Object
(also: #loaded?)
true when this gemspec has been loaded from a specifications directory.
-
#loaded_from ⇒ Object
Path this gemspec was loaded from.
-
#original_platform ⇒ Object
Allows deinstallation of gems with legacy platforms.
Class Method Summary collapse
-
._load(str) ⇒ Object
Load custom marshal format, re-initializing defaults as needed.
-
.array_attribute(name) ⇒ Object
Same as :attribute, but ensures that values assigned to the attribute are array values by applying :to_a to the value.
-
.array_attributes ⇒ Object
Specification attributes that are arrays (appendable and so-forth).
-
.attribute(name, default = nil) ⇒ Object
Specifies the
name
anddefault
for a specification attribute, and creates a reader and writer method like Module#attr_accessor. -
.attribute_alias_singular(singular, plural) ⇒ Object
Defines a singular version of an existing plural attribute (i.e. one whose value is expected to be an array).
-
.attribute_defaults ⇒ Object
Default values for specification attributes.
-
.attribute_names ⇒ Object
Names of all specification attributes.
-
.attributes(*args) ⇒ Object
Shortcut for creating several attributes at once (each with a default value of
nil
). -
.default_value(name) ⇒ Object
The default value for specification attribute
name
. -
.from_yaml(input) ⇒ Object
Special loader for YAML files.
-
.load(filename) ⇒ Object
Loads ruby format gemspec from
filename
. -
.normalize_yaml_input(input) ⇒ Object
Make sure the YAML specification is properly formatted with dashes.
-
.overwrite_accessor(name, &block) ⇒ Object
Some attributes require special behaviour when they are accessed.
-
.read_only(*names) ⇒ Object
Sometimes we don’t want the world to use a setter method for a particular attribute.
-
.required_attribute(*args) ⇒ Object
Same as attribute above, but also records this attribute as mandatory.
-
.required_attribute?(name) ⇒ Boolean
Is
name
a required attribute?. -
.required_attributes ⇒ Object
Required specification attributes.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
:nodoc:.
-
#==(other) ⇒ Object
(also: #eql?)
Tests specs for equality (across all attributes).
-
#_dump(limit) ⇒ Object
Dump only crucial instance variables.
-
#add_bindir(executables) ⇒ Object
Returns an array with bindir attached to each executable in the executables list.
-
#add_development_dependency(gem, *requirements) ⇒ Object
Adds a development dependency named
gem
withrequirements
to this LibGems. -
#add_runtime_dependency(gem, *requirements) ⇒ Object
(also: #add_dependency)
Adds a runtime dependency named
gem
withrequirements
to this LibGems. -
#assign_defaults ⇒ Object
Each attribute has a default value (possibly nil).
-
#author ⇒ Object
Singular accessor for #authors.
-
#authors ⇒ Object
:attr_accessor: authors.
-
#autorequire ⇒ Object
:attr_accessor: autorequire.
-
#bindir ⇒ Object
:attr_accessor: bindir.
-
#cert_chain ⇒ Object
:attr_accessor: cert_chain.
-
#date ⇒ Object
:attr_accessor: date.
-
#default_executable ⇒ Object
:attr_accessor: default_executable.
-
#dependencies ⇒ Object
:attr_reader: dependencies.
-
#dependent_gems ⇒ Object
Return a list of all gems that have a dependency on this gemspec.
-
#description ⇒ Object
:attr_accessor: description.
-
#development_dependencies ⇒ Object
List of dependencies that are used for development.
-
#email ⇒ Object
:attr_accessor: email.
-
#encode_with(coder) ⇒ Object
:nodoc:.
-
#executable ⇒ Object
Singular accessor for #executables.
-
#executables ⇒ Object
:attr_accessor: executables.
-
#extensions ⇒ Object
:attr_accessor: extensions.
-
#extra_rdoc_files ⇒ Object
:attr_accessor: extra_rdoc_files.
-
#file_name ⇒ Object
The default (generated) file name of the gem.
-
#files ⇒ Object
:attr_accessor: files.
-
#full_gem_path ⇒ Object
The full path to the gem (install path + full name).
-
#full_name ⇒ Object
Returns the full name (name-version) of this LibGems.
-
#has_rdoc ⇒ Object
(also: #has_rdoc?)
:attr_accessor: has_rdoc.
-
#has_unit_tests? ⇒ Boolean
(also: #has_test_suite?)
True if this gem has files in test_files.
-
#hash ⇒ Object
:nodoc:.
-
#homepage ⇒ Object
:attr_accessor: homepage.
-
#init_with(coder) ⇒ Object
:nodoc:.
-
#initialize(name = nil, version = nil) {|_self| ... } ⇒ Specification
constructor
Specification constructor.
-
#initialize_copy(other_spec) ⇒ Object
Duplicates array_attributes from
other_spec
so state isn’t shared. -
#installation_path ⇒ Object
The directory that this gem was installed into.
-
#lib_files ⇒ Object
Files in the LibGems under one of the require_paths.
-
#license ⇒ Object
Singular accessor for #licenses.
-
#licenses ⇒ Object
:attr_accessor: licenses.
-
#mark_version ⇒ Object
Sets the rubygems_version to the current SlimGems version.
-
#method_missing(sym, *a, &b) ⇒ Object
Ignore unknown attributes while loading.
-
#name ⇒ Object
:attr_accessor: name.
-
#normalize ⇒ Object
Normalize the list of files so that: * All file lists have redundancies removed.
-
#original_name ⇒ Object
Returns the full name (name-version) of this gemspec using the original platform.
-
#platform ⇒ Object
:attr_accessor: platform.
-
#post_install_message ⇒ Object
:attr_accessor: post_install_message.
-
#pretty_print(q) ⇒ Object
:nodoc:.
-
#rdoc_options ⇒ Object
:attr_accessor: rdoc_options.
-
#require_path ⇒ Object
Singular accessor for #require_paths.
-
#require_paths ⇒ Object
:attr_accessor: require_paths.
-
#required_ruby_version ⇒ Object
:attr_accessor: required_ruby_version.
-
#required_rubygems_version ⇒ Object
:attr_accessor: required_rubygems_version.
-
#requirements ⇒ Object
:attr_accessor: requirements.
-
#rubyforge_project ⇒ Object
:attr_accessor: rubyforge_project.
-
#rubygems_version ⇒ Object
:attr_accessor: rubygems_version.
-
#runtime_dependencies ⇒ Object
List of depedencies that will automatically be activated at runtime.
-
#satisfies_requirement?(dependency) ⇒ Boolean
Checks if this specification meets the requirement of
dependency
. -
#signing_key ⇒ Object
:attr_accessor: signing_key.
-
#sort_obj ⇒ Object
Returns an object you can use to sort specifications in #sort_by.
-
#spec_name ⇒ Object
The default name of the gemspec.
-
#specification_version ⇒ Object
:attr_accessor: specification_version.
-
#summary ⇒ Object
:attr_accessor: summary.
-
#test_file ⇒ Object
Singular accessor for #test_files.
-
#test_files ⇒ Object
:attr_accessor: test_files.
-
#test_suite_file ⇒ Object
:nodoc:.
-
#test_suite_file=(val) ⇒ Object
:nodoc:.
-
#to_ruby ⇒ Object
Returns a Ruby code representation of this specification, such that it can be eval’ed and reconstruct the same specification later.
-
#to_s ⇒ Object
:nodoc:.
-
#to_yaml(opts = {}) ⇒ Object
:nodoc:.
- #to_yaml_type ⇒ Object
-
#validate ⇒ Object
Checks that the specification contains all required fields, and does a very basic sanity check.
-
#version ⇒ Object
:attr_accessor: version.
-
#yaml_initialize(tag, vals) ⇒ Object
:nodoc:.
Constructor Details
#initialize(name = nil, version = nil) {|_self| ... } ⇒ Specification
Specification constructor. Assigns the default values to the attributes and yields itself for further initialization. Optionally takes name
and version
.
416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/libgems/specification.rb', line 416 def initialize name = nil, version = nil @new_platform = nil assign_defaults @loaded = false @loaded_from = nil self.name = name if name self.version = version if version yield self if block_given? @@gather.call(self) if @@gather end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *a, &b) ⇒ Object
Ignore unknown attributes while loading
533 534 535 536 537 538 539 540 |
# File 'lib/libgems/specification.rb', line 533 def method_missing(sym, *a, &b) # :nodoc: if @specification_version > CURRENT_SPECIFICATION_VERSION and sym.to_s =~ /=$/ then warn "ignoring #{sym} loading #{full_name}" if $DEBUG else super end end |
Instance Attribute Details
#loaded ⇒ Object Also known as: loaded?
true when this gemspec has been loaded from a specifications directory. This attribute is not persisted.
361 362 363 |
# File 'lib/libgems/specification.rb', line 361 def loaded @loaded end |
#loaded_from ⇒ Object
Path this gemspec was loaded from. This attribute is not persisted.
366 367 368 |
# File 'lib/libgems/specification.rb', line 366 def loaded_from @loaded_from end |
#original_platform ⇒ Object
Allows deinstallation of gems with legacy platforms.
33 34 35 |
# File 'lib/libgems/specification.rb', line 33 def original_platform @original_platform end |
Class Method Details
._load(str) ⇒ Object
Load custom marshal format, re-initializing defaults as needed
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/libgems/specification.rb', line 288 def self._load(str) array = Marshal.load str spec = LibGems::Specification.new spec.instance_variable_set :@specification_version, array[1] current_version = CURRENT_SPECIFICATION_VERSION field_count = if spec.specification_version > current_version then spec.instance_variable_set :@specification_version, current_version MARSHAL_FIELDS[current_version] else MARSHAL_FIELDS[spec.specification_version] end if array.size < field_count then raise TypeError, "invalid LibGems::Specification format #{array.inspect}" end spec.instance_variable_set :@rubygems_version, array[0] # spec version spec.instance_variable_set :@name, array[2] spec.instance_variable_set :@version, array[3] spec.instance_variable_set :@date, array[4] spec.instance_variable_set :@summary, array[5] spec.instance_variable_set :@required_ruby_version, array[6] spec.instance_variable_set :@required_rubygems_version, array[7] spec.instance_variable_set :@original_platform, array[8] spec.instance_variable_set :@dependencies, array[9] spec.instance_variable_set :@rubyforge_project, array[10] spec.instance_variable_set :@email, array[11] spec.instance_variable_set :@authors, array[12] spec.instance_variable_set :@description, array[13] spec.instance_variable_set :@homepage, array[14] spec.instance_variable_set :@has_rdoc, array[15] spec.instance_variable_set :@new_platform, array[16] spec.instance_variable_set :@platform, array[16].to_s spec.instance_variable_set :@license, array[17] spec.instance_variable_set :@loaded, false spec end |
.array_attribute(name) ⇒ Object
Same as :attribute, but ensures that values assigned to the attribute are array values by applying :to_a to the value.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/libgems/specification.rb', line 175 def self.array_attribute(name) @@non_nil_attributes << ["@#{name}".intern, []] @@array_attributes << name @@attributes << [name, []] @@default_value[name] = [] code = %{ def #{name} @#{name} ||= [] end def #{name}=(value) @#{name} = Array(value) end } module_eval code, __FILE__, __LINE__ - 9 end |
.array_attributes ⇒ Object
Specification attributes that are arrays (appendable and so-forth)
148 149 150 |
# File 'lib/libgems/specification.rb', line 148 def self.array_attributes @@array_attributes.dup end |
.attribute(name, default = nil) ⇒ Object
Specifies the name
and default
for a specification attribute, and creates a reader and writer method like Module#attr_accessor.
The reader method returns the default if the value hasn’t been set.
158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/libgems/specification.rb', line 158 def self.attribute(name, default=nil) ivar_name = "@#{name}".intern if default.nil? then @@nil_attributes << ivar_name else @@non_nil_attributes << [ivar_name, default] end @@attributes << [name, default] @@default_value[name] = default attr_accessor(name) end |
.attribute_alias_singular(singular, plural) ⇒ Object
Defines a singular version of an existing plural attribute (i.e. one whose value is expected to be an array). This means just creating a helper method that takes a single value and appends it to the array. These are created for convenience, so that in a spec, one can write
s.require_path = 'mylib'
instead of:
s.require_paths = ['mylib']
That above convenience is available courtesy of:
attribute_alias_singular :require_path, :require_paths
247 248 249 250 251 252 253 254 255 |
# File 'lib/libgems/specification.rb', line 247 def self.attribute_alias_singular(singular, plural) define_method("#{singular}=") { |val| send("#{plural}=", [val]) } define_method("#{singular}") { val = send("#{plural}") val.nil? ? nil : val.first } end |
.attribute_defaults ⇒ Object
Default values for specification attributes
120 121 122 |
# File 'lib/libgems/specification.rb', line 120 def self.attribute_defaults @@attributes.dup end |
.attribute_names ⇒ Object
Names of all specification attributes
113 114 115 |
# File 'lib/libgems/specification.rb', line 113 def self.attribute_names @@attributes.map { |name, default| name } end |
.attributes(*args) ⇒ Object
Shortcut for creating several attributes at once (each with a default value of nil
).
216 217 218 219 220 |
# File 'lib/libgems/specification.rb', line 216 def self.attributes(*args) args.each do |arg| attribute(arg, nil) end end |
.default_value(name) ⇒ Object
The default value for specification attribute name
127 128 129 |
# File 'lib/libgems/specification.rb', line 127 def self.default_value(name) @@default_value[name] end |
.from_yaml(input) ⇒ Object
Special loader for YAML files. When a Specification object is loaded from a YAML file, it bypasses the normal Ruby object initialization routine (#initialize). This method makes up for that and deals with gems of different ages.
‘input’ can be anything that YAML.load() accepts: String or IO.
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'lib/libgems/specification.rb', line 478 def self.from_yaml(input) input = normalize_yaml_input input spec = LibGems.with_rubygems_compat{ YAML.load input } if spec && spec.class == FalseClass then raise LibGems::EndOfYAMLException end unless LibGems::Specification === spec then raise LibGems::Exception, "YAML data doesn't evaluate to gem specification" end unless (spec.instance_variables.include? '@specification_version' or spec.instance_variables.include? :@specification_version) and spec.instance_variable_get :@specification_version spec.instance_variable_set :@specification_version, NONEXISTENT_SPECIFICATION_VERSION end spec end |
.load(filename) ⇒ Object
Loads ruby format gemspec from filename
503 504 505 506 507 508 509 510 511 512 |
# File 'lib/libgems/specification.rb', line 503 def self.load(filename) gemspec = nil raise "NESTED Specification.load calls not allowed!" if @@gather @@gather = proc { |gs| gemspec = gs } data = File.read filename LibGems.with_rubygems_compat{ eval(data, nil, filename) } gemspec ensure @@gather = nil end |
.normalize_yaml_input(input) ⇒ Object
Make sure the YAML specification is properly formatted with dashes
517 518 519 520 521 |
# File 'lib/libgems/specification.rb', line 517 def self.normalize_yaml_input(input) result = input.respond_to?(:read) ? input.read : input result = "--- " + result unless result =~ /\A--- / result.gsub(/ !!null \n/, " \n") end |
.overwrite_accessor(name, &block) ⇒ Object
Some attributes require special behaviour when they are accessed. This allows for that.
226 227 228 229 |
# File 'lib/libgems/specification.rb', line 226 def self.overwrite_accessor(name, &block) remove_method name define_method(name, &block) end |
.read_only(*names) ⇒ Object
Sometimes we don’t want the world to use a setter method for a particular attribute.
read_only
makes it private so we can still use it internally.
207 208 209 210 211 |
# File 'lib/libgems/specification.rb', line 207 def self.read_only(*names) names.each do |name| private "#{name}=" end end |
.required_attribute(*args) ⇒ Object
Same as attribute above, but also records this attribute as mandatory.
196 197 198 199 |
# File 'lib/libgems/specification.rb', line 196 def self.required_attribute(*args) @@required_attributes << args.first attribute(*args) end |
.required_attribute?(name) ⇒ Boolean
Is name
a required attribute?
141 142 143 |
# File 'lib/libgems/specification.rb', line 141 def self.required_attribute?(name) @@required_attributes.include? name.to_sym end |
.required_attributes ⇒ Object
Required specification attributes
134 135 136 |
# File 'lib/libgems/specification.rb', line 134 def self.required_attributes @@required_attributes.dup end |
Instance Method Details
#<=>(other) ⇒ Object
:nodoc:
648 649 650 |
# File 'lib/libgems/specification.rb', line 648 def <=>(other) # :nodoc: sort_obj <=> other.sort_obj end |
#==(other) ⇒ Object Also known as: eql?
Tests specs for equality (across all attributes).
655 656 657 |
# File 'lib/libgems/specification.rb', line 655 def ==(other) # :nodoc: self.class === other && same_attributes?(other) end |
#_dump(limit) ⇒ Object
Dump only crucial instance variables. – MAINTAIN ORDER!
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/libgems/specification.rb', line 262 def _dump(limit) Marshal.dump [ @rubygems_version, @specification_version, @name, @version, (Time === @date ? @date : (require 'time'; Time.parse(@date.to_s))), @summary, @required_ruby_version, @required_rubygems_version, @original_platform, @dependencies, @rubyforge_project, @email, @authors, @description, @homepage, @has_rdoc, @new_platform, @licenses ] end |
#add_bindir(executables) ⇒ Object
Returns an array with bindir attached to each executable in the executables list
372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/libgems/specification.rb', line 372 def add_bindir(executables) return nil if executables.nil? if @bindir then Array(executables).map { |e| File.join(@bindir, e) } else executables end rescue return nil end |
#add_development_dependency(gem, *requirements) ⇒ Object
Adds a development dependency named gem
with requirements
to this LibGems. For example:
spec.add_development_dependency 'jabber4r', '> 0.1', '<= 0.5'
Development dependencies aren’t installed by default and aren’t activated when a gem is required.
551 552 553 |
# File 'lib/libgems/specification.rb', line 551 def add_development_dependency(gem, *requirements) add_dependency_with_type(gem, :development, *requirements) end |
#add_runtime_dependency(gem, *requirements) ⇒ Object Also known as: add_dependency
Adds a runtime dependency named gem
with requirements
to this LibGems. For example:
spec.add_runtime_dependency 'jabber4r', '> 0.1', '<= 0.5'
561 562 563 |
# File 'lib/libgems/specification.rb', line 561 def add_runtime_dependency(gem, *requirements) add_dependency_with_type(gem, :runtime, *requirements) end |
#assign_defaults ⇒ Object
Each attribute has a default value (possibly nil). Here, we initialize all attributes to their default value. This is done through the accessor methods, so special behaviours will be honored. Furthermore, we take a copy of the default so each specification instance has its own empty arrays, etc.
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/libgems/specification.rb', line 452 def assign_defaults @@nil_attributes.each do |name| instance_variable_set name, nil end @@non_nil_attributes.each do |name, default| value = case default when Time, Numeric, Symbol, true, false, nil then default else default.dup end instance_variable_set name, value end # HACK instance_variable_set :@new_platform, LibGems::Platform::RUBY end |
#author ⇒ Object
Singular accessor for #authors
1349 |
# File 'lib/libgems/specification.rb', line 1349 attribute_alias_singular :author, :authors |
#authors ⇒ Object
:attr_accessor: authors
The list of author names who wrote this gem.
If you are providing multiple authors and multiple emails they should be in the same order such that:
Hash[*spec..zip(spec.emails).flatten]
Gives a hash of author name to email address.
1259 |
# File 'lib/libgems/specification.rb', line 1259 array_attribute :authors |
#autorequire ⇒ Object
:attr_accessor: autorequire
Autorequire was used by old SlimGems to automatically require a file. It no longer is supported.
1171 |
# File 'lib/libgems/specification.rb', line 1171 attribute :autorequire |
#bindir ⇒ Object
:attr_accessor: bindir
The path in the gem for executable scripts
1187 |
# File 'lib/libgems/specification.rb', line 1187 attribute :bindir, 'bin' |
#cert_chain ⇒ Object
:attr_accessor: cert_chain
The certificate chain used to sign this gem. See LibGems::Security for details.
1238 |
# File 'lib/libgems/specification.rb', line 1238 attribute :cert_chain, [] |
#date ⇒ Object
:attr_accessor: date
The date this gem was created
Do not set this, it is set automatically when the gem is packaged.
1104 |
# File 'lib/libgems/specification.rb', line 1104 required_attribute :date, TODAY |
#default_executable ⇒ Object
:attr_accessor: default_executable
The default executable for this gem.
This is not used.
1180 |
# File 'lib/libgems/specification.rb', line 1180 attribute :default_executable |
#dependencies ⇒ Object
:attr_reader: dependencies
A list of LibGems::Dependency objects this gem depends on.
Use #add_dependency or #add_development_dependency to add dependencies to a gem.
1335 |
# File 'lib/libgems/specification.rb', line 1335 array_attribute :dependencies |
#dependent_gems ⇒ Object
Return a list of all gems that have a dependency on this gemspec. The list is structured with entries that conform to:
[depending_gem, dependency, [list_of_gems_that_satisfy_dependency]]
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 |
# File 'lib/libgems/specification.rb', line 961 def dependent_gems out = [] LibGems.source_index.each do |name,gem| gem.dependencies.each do |dep| if self.satisfies_requirement?(dep) then sats = [] find_all_satisfiers(dep) do |sat| sats << sat end out << [gem, dep, sats] end end end out end |
#description ⇒ Object
:attr_accessor: description
A long description of this gem
1163 |
# File 'lib/libgems/specification.rb', line 1163 attribute :description |
#development_dependencies ⇒ Object
List of dependencies that are used for development
342 343 344 |
# File 'lib/libgems/specification.rb', line 342 def development_dependencies dependencies.select { |d| d.type == :development } end |
#email ⇒ Object
:attr_accessor: email
A contact email for this gem
If you are providing multiple authors and multiple emails they should be in the same order such that:
Hash[*spec..zip(spec.emails).flatten]
Gives a hash of author name to email address.
1141 |
# File 'lib/libgems/specification.rb', line 1141 attribute :email |
#encode_with(coder) ⇒ Object
:nodoc:
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
# File 'lib/libgems/specification.rb', line 679 def encode_with coder # :nodoc: mark_version attributes = @@attributes.map { |name,| name.to_s }.sort attributes = attributes - %w[name version platform] coder.add 'name', @name coder.add 'version', @version platform = case @original_platform when nil, '' then 'ruby' when String then @original_platform else @original_platform.to_s end coder.add 'platform', platform attributes.each do |name| coder.add name, instance_variable_get("@#{name}") end end |
#executable ⇒ Object
Singular accessor for #executables
1344 |
# File 'lib/libgems/specification.rb', line 1344 attribute_alias_singular :executable, :executables |
#executables ⇒ Object
:attr_accessor: executables
Executables included in the gem.
1309 |
# File 'lib/libgems/specification.rb', line 1309 array_attribute :executables |
#extensions ⇒ Object
:attr_accessor: extensions
Extensions to build when installing the gem. See LibGems::Installer#build_extensions for valid values.
1317 |
# File 'lib/libgems/specification.rb', line 1317 array_attribute :extensions |
#extra_rdoc_files ⇒ Object
:attr_accessor: extra_rdoc_files
Extra files to add to RDoc such as README or doc/examples.txt
1302 |
# File 'lib/libgems/specification.rb', line 1302 array_attribute :extra_rdoc_files |
#file_name ⇒ Object
The default (generated) file name of the gem. See also #spec_name.
spec.file_name # => "example-1.0.gem"
609 610 611 |
# File 'lib/libgems/specification.rb', line 609 def file_name full_name + '.gem' end |
#files ⇒ Object
:attr_accessor: files
Files included in this gem. You cannot append to this accessor, you must assign to it.
Only add files you can require to this list, not directories, etc.
Directories are automatically stripped from this list when building a gem, other non-files cause an error.
1280 |
# File 'lib/libgems/specification.rb', line 1280 array_attribute :files |
#full_gem_path ⇒ Object
The full path to the gem (install path + full name).
598 599 600 601 602 |
# File 'lib/libgems/specification.rb', line 598 def full_gem_path path = File.join installation_path, 'gems', full_name return path if File.directory? path File.join installation_path, 'gems', original_name end |
#full_name ⇒ Object
Returns the full name (name-version) of this LibGems. Platform information is included (name-version-platform) if it is specified and not the default Ruby platform.
575 576 577 578 579 580 581 |
# File 'lib/libgems/specification.rb', line 575 def full_name if platform == LibGems::Platform::RUBY or platform.nil? then "#{@name}-#{@version}" else "#{@name}-#{@version}-#{platform}" end end |
#has_rdoc ⇒ Object Also known as: has_rdoc?
:attr_accessor: has_rdoc
Indicates that this gem is RDoc-capable.
1194 |
# File 'lib/libgems/specification.rb', line 1194 attribute :has_rdoc, true |
#has_unit_tests? ⇒ Boolean Also known as: has_test_suite?
True if this gem has files in test_files
403 404 405 |
# File 'lib/libgems/specification.rb', line 403 def has_unit_tests? not test_files.empty? end |
#hash ⇒ Object
:nodoc:
673 674 675 676 677 |
# File 'lib/libgems/specification.rb', line 673 def hash # :nodoc: @@attributes.inject(0) { |hash_code, (name, default_value)| hash_code ^ self.send(name).hash } end |
#homepage ⇒ Object
:attr_accessor: homepage
The URL of this gem’s home page
1148 |
# File 'lib/libgems/specification.rb', line 1148 attribute :homepage |
#init_with(coder) ⇒ Object
:nodoc:
720 721 722 |
# File 'lib/libgems/specification.rb', line 720 def init_with coder # :nodoc: yaml_initialize coder.tag, coder.map end |
#initialize_copy(other_spec) ⇒ Object
Duplicates array_attributes from other_spec
so state isn’t shared.
433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/libgems/specification.rb', line 433 def initialize_copy(other_spec) other_ivars = other_spec.instance_variables other_ivars = other_ivars.map { |ivar| ivar.intern } if # for 1.9 other_ivars.any? { |ivar| String === ivar } self.class.array_attributes.each do |name| name = :"@#{name}" next unless other_ivars.include? name instance_variable_set name, other_spec.instance_variable_get(name).dup end end |
#installation_path ⇒ Object
The directory that this gem was installed into.
616 617 618 619 620 621 622 |
# File 'lib/libgems/specification.rb', line 616 def installation_path unless @loaded_from then raise LibGems::Exception, "spec #{full_name} is not from an installed gem" end File. File.dirname(File.dirname(@loaded_from)) end |
#lib_files ⇒ Object
Files in the LibGems under one of the require_paths
387 388 389 390 391 392 393 |
# File 'lib/libgems/specification.rb', line 387 def lib_files @files.select do |file| require_paths.any? do |path| file.index(path) == 0 end end end |
#license ⇒ Object
Singular accessor for #licenses
1354 |
# File 'lib/libgems/specification.rb', line 1354 attribute_alias_singular :license, :licenses |
#licenses ⇒ Object
:attr_accessor: licenses
The license(s) for the library. Each license must be a short name, no more than 64 characters.
1267 |
# File 'lib/libgems/specification.rb', line 1267 array_attribute :licenses |
#mark_version ⇒ Object
Sets the rubygems_version to the current SlimGems version
526 527 528 |
# File 'lib/libgems/specification.rb', line 526 def mark_version @rubygems_version = LibGems::VERSION end |
#name ⇒ Object
:attr_accessor: name
This gem’s name
1088 |
# File 'lib/libgems/specification.rb', line 1088 required_attribute :name |
#normalize ⇒ Object
Normalize the list of files so that:
-
All file lists have redundancies removed.
-
Files referenced in the extra_rdoc_files are included in the package file list.
946 947 948 949 950 951 952 953 |
# File 'lib/libgems/specification.rb', line 946 def normalize if defined?(@extra_rdoc_files) and @extra_rdoc_files then @extra_rdoc_files.uniq! @files ||= [] @files.concat(@extra_rdoc_files) end @files.uniq! if @files end |
#original_name ⇒ Object
Returns the full name (name-version) of this gemspec using the original platform. For use with legacy gems.
587 588 589 590 591 592 593 |
# File 'lib/libgems/specification.rb', line 587 def original_name # :nodoc: if platform == LibGems::Platform::RUBY or platform.nil? then "#{@name}-#{@version}" else "#{@name}-#{@version}-#{@original_platform}" end end |
#platform ⇒ Object
:attr_accessor: platform
The platform this gem runs on. See LibGems::Platform for details.
Setting this to any value other than LibGems::Platform::RUBY or LibGems::Platform::CURRENT is probably wrong.
1223 |
# File 'lib/libgems/specification.rb', line 1223 attribute :platform, LibGems::Platform::RUBY |
#post_install_message ⇒ Object
:attr_accessor: post_install_message
A message that gets displayed after the gem is installed
1245 |
# File 'lib/libgems/specification.rb', line 1245 attribute :post_install_message, nil |
#pretty_print(q) ⇒ Object
:nodoc:
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 |
# File 'lib/libgems/specification.rb', line 981 def pretty_print(q) # :nodoc: q.group 2, 'LibGems::Specification.new do |s|', 'end' do q.breakable attributes = @@attributes.sort_by { |attr_name,| attr_name.to_s } attributes.each do |attr_name, default| current_value = self.send attr_name if current_value != default or self.class.required_attribute? attr_name then q.text "s.#{attr_name} = " if attr_name == :date then current_value = current_value.utc q.text "Time.utc(#{current_value.year}, #{current_value.month}, #{current_value.day})" else q.pp current_value end q.breakable end end end end |
#rdoc_options ⇒ Object
:attr_accessor: rdoc_options
An ARGV style array of options to RDoc
1295 |
# File 'lib/libgems/specification.rb', line 1295 array_attribute :rdoc_options |
#require_path ⇒ Object
Singular accessor for #require_paths
1359 |
# File 'lib/libgems/specification.rb', line 1359 attribute_alias_singular :require_path, :require_paths |
#require_paths ⇒ Object
:attr_accessor: require_paths
Paths in the gem to add to $LOAD_PATH when this gem is activated.
The default ‘lib’ is typically sufficient.
1125 |
# File 'lib/libgems/specification.rb', line 1125 required_attribute :require_paths, ['lib'] |
#required_ruby_version ⇒ Object
:attr_accessor: required_ruby_version
The version of ruby required by this gem
1206 |
# File 'lib/libgems/specification.rb', line 1206 attribute :required_ruby_version, LibGems::Requirement.default |
#required_rubygems_version ⇒ Object
:attr_accessor: required_rubygems_version
The SlimGems version required by this gem
1213 |
# File 'lib/libgems/specification.rb', line 1213 attribute :required_rubygems_version, LibGems::Requirement.default |
#requirements ⇒ Object
:attr_accessor: requirements
An array or things required by this gem. Not used by anything presently.
1325 |
# File 'lib/libgems/specification.rb', line 1325 array_attribute :requirements |
#rubyforge_project ⇒ Object
:attr_accessor: rubyforge_project
The rubyforge project this gem lives under. i.e. SlimGems’ rubyforge_project is “libgems”.
1156 |
# File 'lib/libgems/specification.rb', line 1156 attribute :rubyforge_project |
#rubygems_version ⇒ Object
:attr_accessor: rubygems_version
The version of SlimGems used to create this gem.
Do not set this, it is set automatically when the gem is packaged.
1072 |
# File 'lib/libgems/specification.rb', line 1072 required_attribute :rubygems_version, LibGems::VERSION |
#runtime_dependencies ⇒ Object
List of depedencies that will automatically be activated at runtime.
335 336 337 |
# File 'lib/libgems/specification.rb', line 335 def runtime_dependencies dependencies.select { |d| d.type == :runtime || d.type == nil } end |
#satisfies_requirement?(dependency) ⇒ Boolean
Checks if this specification meets the requirement of dependency
.
627 628 629 630 |
# File 'lib/libgems/specification.rb', line 627 def satisfies_requirement?(dependency) return @name == dependency.name && dependency.requirement.satisfied_by?(@version) end |
#signing_key ⇒ Object
:attr_accessor: signing_key
The key used to sign this gem. See LibGems::Security for details.
1230 |
# File 'lib/libgems/specification.rb', line 1230 attribute :signing_key, nil |
#sort_obj ⇒ Object
Returns an object you can use to sort specifications in #sort_by.
635 636 637 |
# File 'lib/libgems/specification.rb', line 635 def sort_obj [@name, @version, @new_platform == LibGems::Platform::RUBY ? -1 : 1] end |
#spec_name ⇒ Object
The default name of the gemspec. See also #file_name
spec.spec_name # => "example-1.0.gemspec"
644 645 646 |
# File 'lib/libgems/specification.rb', line 644 def spec_name full_name + '.gemspec' end |
#specification_version ⇒ Object
:attr_accessor: specification_version
The LibGems::Specification version of this gemspec.
Do not set this, it is set automatically when the gem is packaged.
1081 |
# File 'lib/libgems/specification.rb', line 1081 required_attribute :specification_version, CURRENT_SPECIFICATION_VERSION |
#summary ⇒ Object
:attr_accessor: summary
A short summary of this gem’s description. Displayed in ‘gem list -d`.
The description should be more detailed than the summary. For example, you might wish to copy the entire README into the description.
As of SlimGems 1.3.2 newlines are no longer stripped.
1116 |
# File 'lib/libgems/specification.rb', line 1116 required_attribute :summary |
#test_file ⇒ Object
Singular accessor for #test_files
1364 |
# File 'lib/libgems/specification.rb', line 1364 attribute_alias_singular :test_file, :test_files |
#test_files ⇒ Object
:attr_accessor: test_files
Test files included in this gem. You cannot append to this accessor, you must assign to it.
1288 |
# File 'lib/libgems/specification.rb', line 1288 array_attribute :test_files |
#test_suite_file ⇒ Object
:nodoc:
346 347 348 349 |
# File 'lib/libgems/specification.rb', line 346 def test_suite_file # :nodoc: warn 'test_suite_file deprecated, use test_files' test_files.first end |
#test_suite_file=(val) ⇒ Object
:nodoc:
351 352 353 354 355 |
# File 'lib/libgems/specification.rb', line 351 def test_suite_file=(val) # :nodoc: warn 'test_suite_file= deprecated, use test_files=' @test_files = [] unless defined? @test_files @test_files << val end |
#to_ruby ⇒ Object
Returns a Ruby code representation of this specification, such that it can be eval’ed and reconstruct the same specification later. Attributes that still have their default values are omitted.
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 |
# File 'lib/libgems/specification.rb', line 738 def to_ruby mark_version result = [] result << "# -*- encoding: utf-8 -*-" result << nil result << "Gem::Specification.new do |s|" result << " s.name = #{ruby_code name}" result << " s.version = #{ruby_code version}" unless platform.nil? or platform == LibGems::Platform::RUBY then result << " s.platform = #{ruby_code original_platform}" end result << "" result << " s.required_rubygems_version = #{ruby_code required_rubygems_version} if s.respond_to? :required_rubygems_version=" handled = [ :dependencies, :name, :platform, :required_rubygems_version, :specification_version, :version, ] attributes = @@attributes.sort_by { |attr_name,| attr_name.to_s } attributes.each do |attr_name, default| next if handled.include? attr_name current_value = self.send(attr_name) if current_value != default or self.class.required_attribute? attr_name then result << " s.#{attr_name} = #{ruby_code current_value}" end end result << nil result << " if s.respond_to? :specification_version then" result << " s.specification_version = #{specification_version}" result << nil result << " if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then" unless dependencies.empty? then dependencies.each do |dep| version_reqs_param = dep.requirements_list.inspect dep.instance_variable_set :@type, :runtime if dep.type.nil? # HACK result << " s.add_#{dep.type}_dependency(%q<#{dep.name}>, #{version_reqs_param})" end end result << " else" unless dependencies.empty? then dependencies.each do |dep| version_reqs_param = dep.requirements_list.inspect result << " s.add_dependency(%q<#{dep.name}>, #{version_reqs_param})" end end result << ' end' result << " else" dependencies.each do |dep| version_reqs_param = dep.requirements_list.inspect result << " s.add_dependency(%q<#{dep.name}>, #{version_reqs_param})" end result << " end" result << "end" result << nil result.join "\n" end |
#to_s ⇒ Object
:nodoc:
977 978 979 |
# File 'lib/libgems/specification.rb', line 977 def to_s # :nodoc: "#<LibGems::Specification name=#{@name} version=#{@version}>" end |
#to_yaml(opts = {}) ⇒ Object
:nodoc:
702 703 704 705 706 707 708 709 710 711 712 713 714 |
# File 'lib/libgems/specification.rb', line 702 def to_yaml(opts = {}) # :nodoc: LibGems.load_yaml if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck? then super.gsub(/ !!null \n/, " \n").gsub("!ruby/object:LibGems", "!ruby/object:Gem") else # TODO: Make sure this outputs Gem compatible code YAML.quick_emit object_id, opts do |out| out.map taguri, to_yaml_style do |map| encode_with map end end end end |
#to_yaml_type ⇒ Object
716 717 718 |
# File 'lib/libgems/specification.rb', line 716 def to_yaml_type "!ruby/object:Gem::Specification" end |
#validate ⇒ Object
Checks that the specification contains all required fields, and does a very basic sanity check.
Raises InvalidSpecificationException if the spec does not pass the checks..
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 |
# File 'lib/libgems/specification.rb', line 819 def validate extend LibGems::UserInteraction normalize # TODO: Fix the versioning here if rubygems_version != LibGems::VERSION then raise LibGems::InvalidSpecificationException, "expected RubyGems version #{LibGems::VERSION}, was #{rubygems_version}" end @@required_attributes.each do |symbol| unless self.send symbol then raise LibGems::InvalidSpecificationException, "missing value for attribute #{symbol}" end end unless String === name then raise LibGems::InvalidSpecificationException, "invalid value for attribute name: \"#{name.inspect}\"" end if require_paths.empty? then raise LibGems::InvalidSpecificationException, 'specification must have at least one require_path' end @files.delete_if do |file| File.directory? file end @test_files.delete_if do |file| File.directory? file end @executables.delete_if do |file| File.directory? File.join(bindir, file) end @extra_rdoc_files.delete_if do |file| File.directory? file end @extensions.delete_if do |file| File.directory? file end non_files = files.select do |file| !File.file? file end unless non_files.empty? then non_files = non_files.map { |file| file.inspect } raise LibGems::InvalidSpecificationException, "[#{non_files.join ", "}] are not files" end unless specification_version.is_a?(Fixnum) raise LibGems::InvalidSpecificationException, 'specification_version must be a Fixnum (did you mean version?)' end case platform when LibGems::Platform, LibGems::Platform::RUBY then # ok else raise LibGems::InvalidSpecificationException, "invalid platform #{platform.inspect}, see LibGems::Platform" end unless Array === and .all? { || String === } then raise LibGems::InvalidSpecificationException, 'authors must be Array of Strings' end licenses.each { |license| if license.length > 64 raise LibGems::InvalidSpecificationException, "each license must be 64 characters or less" end } # reject FIXME and TODO unless .grep(/FIXME|TODO/).empty? then raise LibGems::InvalidSpecificationException, '"FIXME" or "TODO" is not an author' end unless Array(email).grep(/FIXME|TODO/).empty? then raise LibGems::InvalidSpecificationException, '"FIXME" or "TODO" is not an email address' end if description =~ /FIXME|TODO/ then raise LibGems::InvalidSpecificationException, '"FIXME" or "TODO" is not a description' end if summary =~ /FIXME|TODO/ then raise LibGems::InvalidSpecificationException, '"FIXME" or "TODO" is not a summary' end if homepage and not homepage.empty? and homepage !~ /\A[a-z][a-z\d+.-]*:/i then raise LibGems::InvalidSpecificationException, "\"#{homepage}\" is not a URI" end # Warnings %w[author description email homepage summary].each do |attribute| value = self.send attribute alert_warning "no #{attribute} specified" if value.nil? or value.empty? end if summary and not summary.empty? and description == summary then alert_warning 'description and summary are identical' end alert_warning "deprecated autorequire specified" if autorequire executables.each do |executable| executable_path = File.join bindir, executable shebang = File.read(executable_path, 2) == '#!' alert_warning "#{executable_path} is missing #! line" unless shebang end true end |
#version ⇒ Object
:attr_accessor: version
This gem’s version
1095 |
# File 'lib/libgems/specification.rb', line 1095 required_attribute :version |
#yaml_initialize(tag, vals) ⇒ Object
:nodoc:
724 725 726 727 728 729 730 731 |
# File 'lib/libgems/specification.rb', line 724 def yaml_initialize(tag, vals) # :nodoc: vals.each do |ivar, val| instance_variable_set "@#{ivar}", val end @original_platform = @platform # for backwards compatibility self.platform = LibGems::Platform.new @platform end |