class Gem::SpecificationPolicy

Constants

HOMEPAGE_URI_PATTERN
LAZY
LAZY_PATTERN

Attributes

packaging [RW]

If set to true, run packaging-specific checks, as well.

Public Class Methods

new (specification)
# File lib/rubygems/specification_policy.rb, line 26
def initialize(specification)
  @warnings = 0

  @specification = specification
end

Public Instance Methods

validate (strict = false)

Does a sanity check on the specification.

Raises InvalidSpecificationException if the spec does not pass the checks.

It also performs some validations that do not raise but print warning messages instead.

# File lib/rubygems/specification_policy.rb, line 46
def validate(strict = false)
  validate_required!
  validate_required_metadata!

  validate_optional(strict) if packaging || strict

  true
end
validate_for_resolution ()

Implementation for Specification#validate_for_resolution

# File lib/rubygems/specification_policy.rb, line 129
def validate_for_resolution
  validate_required!
end
validate_metadata ()

Implementation for Specification#validate_metadata

# File lib/rubygems/specification_policy.rb, line 136
def validate_metadata
  metadata = @specification.metadata

  unless Hash === metadata
    error "metadata must be a hash"
  end

  metadata.each do |key, value|
    entry = "metadata['#{key}']"
    unless key.is_a?(String)
      error "metadata keys must be a String"
    end

    if key.size > 128
      error "metadata key is too large (#{key.size} > 128)"
    end

    unless value.is_a?(String)
      error "#{entry} value must be a String"
    end

    if value.size > 1024
      error "#{entry} value is too large (#{value.size} > 1024)"
    end

    next unless METADATA_LINK_KEYS.include? key
    unless VALID_URI_PATTERN.match?(value)
      error "#{entry} has invalid link: #{value.inspect}"
    end
  end
end
validate_optional (strict)
# File lib/rubygems/specification_policy.rb, line 100
def validate_optional(strict)
  validate_licenses

  validate_permissions

  validate_values

  validate_dependencies

  validate_required_ruby_version

  validate_extensions

  validate_removed_attributes

  validate_unique_links

  if @warnings > 0
    if strict
      error "specification has warnings"
    else
      alert_warning help_text
    end
  end
end
validate_permissions ()

Issues a warning for each file to be packaged which is world-readable.

Implementation for Specification#validate_permissions

# File lib/rubygems/specification_policy.rb, line 253
def validate_permissions
  return if Gem.win_platform?

  @specification.files.each do |file|
    next unless File.file?(file)
    next if File.stat(file).mode & 0o444 == 0o444
    warning "#{file} is not world-readable"
  end

  @specification.executables.each do |name|
    exec = File.join @specification.bindir, name
    next unless File.file?(exec)
    next if File.stat(exec).executable?
    warning "#{exec} is not executable"
  end
end
validate_required! ()

Does a sanity check on the specification.

Raises InvalidSpecificationException if the spec does not pass the checks.

Only runs checks that are considered necessary for the specification to be functional.

# File lib/rubygems/specification_policy.rb, line 64
def validate_required!
  validate_nil_attributes

  validate_rubygems_version

  validate_required_attributes

  validate_name

  validate_require_paths

  @specification.keep_only_files_and_directories

  validate_non_files

  validate_self_inclusion_in_files_list

  validate_specification_version

  validate_platform

  validate_array_attributes

  validate_authors_field

  validate_licenses_length

  validate_duplicate_dependencies
end
validate_required_metadata! ()
# File lib/rubygems/specification_policy.rb, line 94
def validate_required_metadata!
  validate_metadata

  validate_lazy_metadata
end
validate_required_ruby_version ()
# File lib/rubygems/specification_policy.rb, line 242
def validate_required_ruby_version
  if @specification.required_ruby_version.requirements == [Gem::Requirement::DefaultRequirement]
    warning "make sure you specify the oldest ruby version constraint (like \">= 3.0\") that you want your gem to support by setting the `required_ruby_version` gemspec attribute"
  end
end