Class: Fig::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/fig/package.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Package.



5
6
7
8
9
10
# File 'lib/fig/package.rb', line 5

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

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



3
4
5
# File 'lib/fig/package.rb', line 3

def directory
  @directory
end

#package_nameObject (readonly)

Returns the value of attribute package_name.



3
4
5
# File 'lib/fig/package.rb', line 3

def package_name
  @package_name
end

#statementsObject (readonly)

Returns the value of attribute statements.



3
4
5
# File 'lib/fig/package.rb', line 3

def statements
  @statements
end

#version_nameObject (readonly)

Returns the value of attribute version_name.



3
4
5
# File 'lib/fig/package.rb', line 3

def version_name
  @version_name
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  @package_name == other.package_name && @version_name == other.version_name && @statements.to_yaml == other.statements.to_yaml
end

#[](config_name) ⇒ Object



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

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

#archive_urlsObject



24
25
26
# File 'lib/fig/package.rb', line 24

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

#publish_statementsObject



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

def publish_statements
  statements = []
  @statements.each{ |s| statements += s.statements if s.is_a?(Publish) }
  statements
end

#resource_urlsObject



28
29
30
# File 'lib/fig/package.rb', line 28

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

#retrievesObject



19
20
21
22
23
# File 'lib/fig/package.rb', line 19

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

#unparseObject



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

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