Class: Packager::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/packager/executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Executor

Returns a new instance of Executor.



9
10
11
12
# File 'lib/packager/executor.rb', line 9

def initialize(opts={})
  self.dryrun = !!opts[:dryrun]
  self.commands = []
end

Instance Attribute Details

#commandsObject

Returns the value of attribute commands.



7
8
9
# File 'lib/packager/executor.rb', line 7

def commands
  @commands
end

#dryrunObject

Returns the value of attribute dryrun.



7
8
9
# File 'lib/packager/executor.rb', line 7

def dryrun
  @dryrun
end

Instance Method Details

#create_package_for(item) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/packager/executor.rb', line 26

def create_package_for(item)
  unless item.files.empty?
    item.files.each do |file|
      dest = (file.dest || '').gsub /^\//, ''
      FileUtils.mkdir_p File.dirname(dest)
      FileUtils.cp_r(file.source, dest)
    end
  end

  cmd = Packager::Struct::Command.new(
    :name     => item.name,
    :version  => item.version,
    :target   => item.type,
    :requires => item.requires,
    :provides => item.provides,
    :before_install => item.before_install,
    :after_install  => item.after_install,
    :before_remove  => item.before_remove,
    :after_remove   => item.after_remove,
    :before_upgrade => item.before_upgrade,
    :after_upgrade  => item.after_upgrade,
  )

  Dir.glob('*') do |entry|
    if File.directory?(entry)
      cmd.add_directory(entry)
    end
  end

  commands.push(cmd)

  execute_command(cmd)
end

#execute_command(cmd) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/packager/executor.rb', line 60

def execute_command(cmd)
  return if dryrun

  x = `#{cmd.to_system.join(' ')}`
  rv = eval(x)
  raise rv[:error] if rv[:error]
  return rv[:path]
end

#execute_on(items) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/packager/executor.rb', line 14

def execute_on(items)
  curdir = Dir.pwd
  items.collect do |item|
    Dir.mktmpdir do |tempdir|
      Dir.chdir(tempdir) do
        path = create_package_for(item)
        FileUtils.mv(path, curdir) if path
      end
    end
  end
end