Class: Fig::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/fig/package.rb,
lib/fig/package/set.rb,
lib/fig/package/path.rb,
lib/fig/package/archive.rb,
lib/fig/package/command.rb,
lib/fig/package/include.rb,
lib/fig/package/install.rb,
lib/fig/package/publish.rb,
lib/fig/package/override.rb,
lib/fig/package/resource.rb,
lib/fig/package/retrieve.rb,
lib/fig/package/statement.rb,
lib/fig/package/configuration.rb

Overview

The parsed representation of a configuration file. Contains the statement objects.

Defined Under Namespace

Modules: Statement Classes: Archive, Command, Configuration, Include, Install, Override, Path, Publish, Resource, Retrieve, Set

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package_name, version_name, directory, statements) ⇒ Package

Returns a new instance of Package.



16
17
18
19
20
21
22
# File 'lib/fig/package.rb', line 16

def initialize(package_name, version_name, directory, statements)
  @package_name = package_name
  @version_name = version_name
  @directory = directory
  @statements = statements
  @backtrace = nil
end

Instance Attribute Details

#backtraceObject

Returns the value of attribute backtrace.



14
15
16
# File 'lib/fig/package.rb', line 14

def backtrace
  @backtrace
end

#directoryObject (readonly)

Returns the value of attribute directory.



13
14
15
# File 'lib/fig/package.rb', line 13

def directory
  @directory
end

#package_nameObject (readonly)

Returns the value of attribute package_name.



13
14
15
# File 'lib/fig/package.rb', line 13

def package_name
  @package_name
end

#statementsObject (readonly)

Returns the value of attribute statements.



13
14
15
# File 'lib/fig/package.rb', line 13

def statements
  @statements
end

#version_nameObject (readonly)

Returns the value of attribute version_name.



13
14
15
# File 'lib/fig/package.rb', line 13

def version_name
  @version_name
end

Instance Method Details

#==(other) ⇒ Object



61
62
63
64
# File 'lib/fig/package.rb', line 61

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

#[](config_name) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/fig/package.rb', line 24

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}"
  raise Fig::PackageError.new message
end

#archive_urlsObject



42
43
44
# File 'lib/fig/package.rb', line 42

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

#configsObject



32
33
34
# File 'lib/fig/package.rb', line 32

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

#resource_urlsObject



46
47
48
# File 'lib/fig/package.rb', line 46

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

#retrievesObject



36
37
38
39
40
# File 'lib/fig/package.rb', line 36

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

#to_sObject



66
67
68
69
70
# File 'lib/fig/package.rb', line 66

def to_s
  package_name ||= 'uninitialized'
  version_name ||= 'uninitialized'
  package_name + '/' + version_name
end

#unparseObject



57
58
59
# File 'lib/fig/package.rb', line 57

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

#walk_statements(&block) ⇒ Object



50
51
52
53
54
55
# File 'lib/fig/package.rb', line 50

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