Sha256: 5f72e23ce54c7b39a84848443c5457ab1f334cc588c18aa4d5c9fca88f581db1

Contents?: true

Size: 1.95 KB

Versions: 10

Compression:

Stored size: 1.95 KB

Contents

require 'fig/logging'
require 'fig/packageerror'
require 'fig/package/archive'
require 'fig/package/configuration'
require 'fig/package/resource'
require 'fig/package/retrieve'

module Fig; end

class Fig::Package
  attr_reader :package_name, :version_name, :directory, :statements
  attr_accessor :backtrace

  def initialize(package_name, version_name, directory, statements)
    @package_name = package_name || 'uninitialized'
    @version_name = version_name || 'default'
    @directory = directory
    @statements = statements
    @backtrace = nil
  end

  def [](config_name)
    @statements.each do |stmt|
      return stmt if stmt.is_a?(Configuration) && stmt.name == config_name
    end
    message =
      "Configuration not found: #{@package_name}/#{@version_name}:#{config_name}"
    Fig::Logging.fatal message
    raise Fig::PackageError.new message
  end

  def configs
    @statements.select { |statement| statement.is_a?(Configuration) }
  end

  def retrieves
    retrieves = {}
    statements.each { |statement| retrieves[statement.var] = statement.path if statement.is_a?(Retrieve) }
    retrieves
  end

  def archive_urls
    @statements.select{|s| s.is_a?(Archive)}.map{|s|s.url}
  end

  def resource_urls
    @statements.select{|s| s.is_a?(Resource)}.map{|s|s.url}
  end

  def walk_statements(&block)
    @statements.each do |statement|
      yield statement
      statement.walk_statements &block
    end
  end

  def unparse
    @statements.map { |statement| statement.unparse('') }.join("\n")
  end

  def ==(other)
    return false if other.nil?
    @package_name == other.package_name && @version_name == other.version_name && @statements.to_yaml == other.statements.to_yaml
  end

  def to_s
    @package_name + '/' + @version_name
  end
end

def unparse_statements(indent, prefix, statements, suffix)
  body = @statements.map { |statement| statement.unparse(indent+'  ') }.join("\n")
  return ["\n#{indent}#{prefix}", body, "#{indent}#{suffix}"].join("\n")
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
fig18-0.1.50-i386-mswin32 lib/fig/package.rb
fig18-0.1.50 lib/fig/package.rb
fig-0.1.50-java lib/fig/package.rb
fig-0.1.50 lib/fig/package.rb
fig18-0.1.50-i386-mingw32 lib/fig/package.rb
fig-0.1.49-java lib/fig/package.rb
fig-0.1.49 lib/fig/package.rb
fig18-0.1.49 lib/fig/package.rb
fig18-0.1.49-i386-mswin32 lib/fig/package.rb
fig18-0.1.49-i386-mingw32 lib/fig/package.rb