In Files

  • rubygems/specification_policy.rb

Parent

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 21
def initialize(specification)
  @warnings = 0

  super(specification)
end
            

Public Instance Methods

validate(strict = false) click to toggle source

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.

 
               # File rubygems/specification_policy.rb, line 39
def validate(strict = false)
  validate_nil_attributes

  validate_rubygems_version

  validate_required_attributes

  validate_name

  validate_require_paths

  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

  validate_permissions

  validate_lazy_metadata

  validate_values

  validate_dependencies

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

  true
end
            
validate_metadata() click to toggle source

Implementation for Specification#validate_metadata

 
               # File rubygems/specification_policy.rb, line 90
def validate_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_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 186
def validate_permissions
  return if Gem.win_platform?

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

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