Class: Debstep::Installation

Inherits:
Object
  • Object
show all
Defined in:
lib/debstep/installation.rb

Instance Method Summary collapse

Constructor Details

#initialize(workspace, path, &block) ⇒ Installation

Returns a new instance of Installation.

Raises:



3
4
5
6
7
8
9
10
11
# File 'lib/debstep/installation.rb', line 3

def initialize(workspace, path, &block)
  raise Exception.new('path is a required variable') if path.nil? || path.strip.empty?
  raise Exception.new('install path must be absolute (start with a "/")') unless path[0] == '/'

  @path = "#{workspace}#{path}"
  FileUtils.mkdir_p(@path)

  instance_eval(&block)
end

Instance Method Details

#folder(path, opts = {}) ⇒ Object Also known as: file



13
14
15
# File 'lib/debstep/installation.rb', line 13

def folder(path, opts={})
  FileUtils.cp_r(path, target(path, opts))
end

#template(path, opts = {}) ⇒ Object Also known as: erb



17
18
19
20
21
22
23
# File 'lib/debstep/installation.rb', line 17

def template(path, opts={})
  File.open(target(path, opts), 'w') do |file| 
    erb = File.open(path, 'r').read
    out = ERB.new(erb).result(opts[:binding] || TOPLEVEL_BINDING)
    file.write(out) 
  end
end