In Files

  • rubygems/specification_policy.rb

Class/Module Index [+]

Quicksearch

Gem::SpecificationPolicy

Attributes

packaging[RW]

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

Public Class Methods

new(specification) click to toggle source
 
               # File rubygems/specification_policy.rb, line 23
def initialize(specification)
  @warnings = 0

  @specification = specification
end
            

Public Instance Methods

validate(strict = false) click to toggle source

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 rubygems/specification_policy.rb, line 43
def validate(strict = false)
  validate_required!

  validate_optional(strict) if packaging || strict

  true
end
            
validate_metadata() click to toggle source

Implementation for Specification#validate_metadata

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

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

  metadata.each do |key, value|
    if !key.kind_of?(String)
      error "metadata keys must be a String"
    end

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

    if !value.kind_of?(String)
      error "metadata values must be a String"
    end

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

    if METADATA_LINK_KEYS.include? key
      if value !~ VALID_URI_PATTERN
        error "metadata['#{key}'] has invalid link: #{value.inspect}"
      end
    end
  end
end
            
validate_optional(strict) click to toggle source
 
               # File rubygems/specification_policy.rb, line 94
def validate_optional(strict)
  validate_licenses

  validate_permissions

  validate_values

  validate_dependencies

  validate_extensions

  validate_removed_attributes

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

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

Implementation for Specification#validate_permissions

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

  @specification.files.each do |file|
    next unless File.file?(file)
    next if File.stat(file).mode & 0444 == 0444
    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!() click to toggle source

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 rubygems/specification_policy.rb, line 60
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_metadata

  validate_licenses_length

  validate_lazy_metadata

  validate_duplicate_dependencies
end