Class: Debian::Build::PBuilder

Inherits:
Object
  • Object
show all
Extended by:
BuildDirectoryMethods
Includes:
HelperMethods
Defined in:
lib/debian/build/pbuilder.rb

Constant Summary collapse

@@default_build_host =
nil
@@default_options =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BuildDirectoryMethods

build_directory, build_directory=

Methods included from HelperMethods

#get, #sudo, #uncompress

Constructor Details

#initialize {|_self| ... } ⇒ PBuilder

Returns a new instance of PBuilder.

Yields:

  • (_self)

Yield Parameters:



24
25
26
27
28
29
# File 'lib/debian/build/pbuilder.rb', line 24

def initialize
  @options = @@default_options.dup
  @before_exec_callbacks = []

  yield self if block_given?
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



22
23
24
# File 'lib/debian/build/pbuilder.rb', line 22

def options
  @options
end

Class Method Details

.default_build_host=(host) ⇒ Object



8
9
10
# File 'lib/debian/build/pbuilder.rb', line 8

def self.default_build_host=(host)
  @@default_build_host = host
end

.default_option(key, value) ⇒ Object



14
15
16
# File 'lib/debian/build/pbuilder.rb', line 14

def self.default_option(key, value)
  @@default_options[key] = value
end

.reset_default_options!Object



18
19
20
# File 'lib/debian/build/pbuilder.rb', line 18

def self.reset_default_options!
  @@default_options = {}    
end

Instance Method Details

#[](option) ⇒ Object



35
36
37
# File 'lib/debian/build/pbuilder.rb', line 35

def [](option)
  @options[option.to_sym]
end

#[]=(option, value) ⇒ Object



39
40
41
# File 'lib/debian/build/pbuilder.rb', line 39

def []=(option, value)
  @options[option.to_sym] = value
end

#before_exec(proc) ⇒ Object



61
62
63
# File 'lib/debian/build/pbuilder.rb', line 61

def before_exec(proc)
  @before_exec_callbacks << proc
end

#build_hostObject



31
32
33
# File 'lib/debian/build/pbuilder.rb', line 31

def build_host
  @@default_build_host
end

#exec(command, *arguments) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/debian/build/pbuilder.rb', line 65

def exec(command, *arguments)
  @before_exec_callbacks.each { |c| c.call }

  if build_host
    remote_exec command, *arguments
  else
    sudo "pbuilder", command, *(options_arguments + arguments)
  end
end

#options_argumentsObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/debian/build/pbuilder.rb', line 47

def options_arguments
  @options.collect do |option, argument| 
    command_option = "--#{option}"
    case argument
    when true
      command_option        
    when Array
      argument.collect { |a| "#{command_option} #{a}" }
    else 
      "#{command_option} #{argument}" 
    end
  end.flatten
end