In Files

Parent

Box::Pack

Pack is the base class for all other packaging services.

This is a subclass of Path::Shell to provide shell utilities.

Attributes

location[R]
metadata[R]
project[R]

Public Class Methods

new(location, options={}) click to toggle source

New package creator.

Valid options:

:debug
:noop
:verbose
:quiet
:force
:spec
:manifest
# File lib/box/pack.rb, line 32
def initialize(location, options={})
  if $TRIAL || options[:trial]
    options[:noop] = true
    options[:verbose] = true
  end

  super(location, options)

  @force  = options[:force]
  @spec   = options[:spec]
  @manif  = options[:manifest]

  @project  = POM::Project.new(location, :lookup=>true) #, :load=>true)

  @location = @project.root     #dir(location)
  @metadata = @project.metadata #POM::Metadata.new(location.to_s)

  # If a dedicated package directory exists (ie. pkg/ or pack/)
  # use that instead of default locations.
  if options[:output]
    if File.directory?(options[:output])
      @pack_folder = dir(options[:output])
    else
      raise ArgumentError, "#{options[:output]} is not a directory"
    end
  elsif inside?
    # TODO: Should we go ahead and force project.pack?
    pkgdir = project.pack
    @pack_folder = dir(pkgdir) if File.directory?(pkgdir)
    #@temp_folder = @pack_folder
  else
    @pack_folder = dir(Dir.pwd) # or project.pack ?
  end
end

Public Instance Methods

current_platform() click to toggle source

Current platform.

# File lib/box/pack.rb, line 161
def current_platform
  Platform.local.to_s
end
extension() click to toggle source
# File lib/box/pack.rb, line 165
def extension
  raise "must override #extension"
end
force?() click to toggle source
# File lib/box/pack.rb, line 67
def force?    ; @force  ; end
inside?() click to toggle source

TODO: Pathname should have contains? too.

# File lib/box/pack.rb, line 74
def inside?
  FileTest.contains?(Dir.pwd, @location.to_s)
end
manifest() click to toggle source

Manifest list

# File lib/box/pack.rb, line 117
def manifest
  @manifest ||= (
    list = []
    manifest_file.readlines.each do |line|
      next if line =~ /^\s*$/
      next if line =~ /^\s*[#]/
      list << line.strip
    end
    list
  )
end
manifest?() click to toggle source
# File lib/box/pack.rb, line 71
def manifest? ; @manif  ; end
manifest_file() click to toggle source

Manifest file

# File lib/box/pack.rb, line 112
def manifest_file
  @manifest_file ||= location.glob('MANIFEST{,.txt}', :casefold).first
end
pack_folder() click to toggle source

Unless otherwise specified packages will be saved to current working directory.

# File lib/box/pack.rb, line 156
def pack_folder
  @pack_folder ||= location
end
package() click to toggle source
# File lib/box/pack.rb, line 79
def package
  unless package_needed? or force?
    report_package_already_built(package_file)
    return
  end

  if manifest? && !dryrun?
    files = metadata.distribute
    # generate manifest in root directory
    generate_manifest(location, *files)
  end

  if !manifest_file.exist?
    puts "MANIFEST file is missing"
    return
  end

  file = nil
  cd(location) do
    file = Pathname.new(package_build)
  end

  file = transfer(file, pack_folder)

  report_package_built(file)
end
package_build() click to toggle source

Overridden by subclasses for specific package formats.

# File lib/box/pack.rb, line 107
def package_build
   raise "subclass must override"
end
spec?() click to toggle source
# File lib/box/pack.rb, line 69
def spec?     ; @spec   ; end
temp_folder() click to toggle source

Unless otherwise specified temporary staging will be stored in operating system temprorary folder.

# File lib/box/pack.rb, line 148
def temp_folder
  @temp_folder ||= (
    Pathname.new(Dir.tmpdir) / 'box' / metadata.name
  )
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.