Class: Volley::Dsl::PullAction

Inherits:
Action
  • Object
show all
Defined in:
lib/volley/dsl/pull_action.rb

Instance Attribute Summary

Attributes inherited from Action

#plan

Instance Method Summary collapse

Methods inherited from Action

#call, #command

Constructor Details

#initialize(name, options = {}, &block) ⇒ PullAction

Returns a new instance of PullAction.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/volley/dsl/pull_action.rb', line 6

def initialize(name, options={}, &block)
  @name = name.to_sym
  @stage = options.delete(:stage)
  @plan = options.delete(:plan)
  #@block = block
  @options = {
  }.merge(options)
  raise "stage instance must be set" unless @stage
  raise "plan instance must be set" unless @plan

  dir  = nil
  file = nil

  @plan.action :download do
    pr = project.name
    br = branch
    ve = version

    pub  = Volley::Dsl.publisher
    raise "publisher must be defined" unless pub
    file = pub.pull(pr, br, ve)

    dir = File.dirname(file)
  end

  @plan.action :unpack do
    FileUtils.mkdir_p("#{dir}/unpack")
    Volley::Log.info "changing directory: #{dir} (#{file})"
    Dir.chdir("#{dir}/unpack")
    tgz = %x{tar xvfz #{file} 2>/dev/null}
    File.open("#{dir}/tgz.log", "w") { |f| f.write(tgz) }
  end

  @plan.action :run do
    raise "failed to unpack: #{dir}/unpack" unless dir && File.directory?("#{dir}/unpack")
    yield "#{dir}/unpack"
  end
end