Class: Hatchet::AnvilApp

Inherits:
App
  • Object
show all
Defined in:
lib/hatchet/anvil_app.rb

Instance Attribute Summary

Attributes inherited from App

#directory, #name, #repo_name

Instance Method Summary collapse

Methods inherited from App

#add_database, #api_key, #config, config, #debug?, #deploy, #deployed?, #get_config, #get_labs, #heroku, #in_directory, #lab_is_installed?, #not_debugging?, #output, #push, #retry_error_message, #run, #set_config, #set_lab, #set_labs!, #setup!

Constructor Details

#initialize(directory, options = {}) ⇒ AnvilApp

Returns a new instance of AnvilApp.



7
8
9
10
11
# File 'lib/hatchet/anvil_app.rb', line 7

def initialize(directory, options = {})
  @buildpack = options[:buildpack]
  @buildpack ||= File.expand_path('.')
  super
end

Instance Method Details

#push_without_retry!Object



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

def push_without_retry!
  out, err = wrap_stdout_and_rescue(Anvil::Builder::BuildError) do
    slug_url  = Anvil::Engine.build(".", :buildpack => @buildpack, :pipeline => true)
    puts "Releasing to http://#{@name}.herokuapp.com"
    response = release(@name, slug_url)
    while response.status == 202
      response = Excon.get("#{release_host}#{response.headers["Location"]}")
    end
  end

  err.string
end

#teardown!Object



49
50
51
52
# File 'lib/hatchet/anvil_app.rb', line 49

def teardown!
  super
  FileUtils.rm_rf("#{directory}/.anvil")
end

#wrap_stdout(orig_out = $stdout, orig_err = $stderr, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/hatchet/anvil_app.rb', line 38

def wrap_stdout(orig_out = $stdout, orig_err = $stderr, &block)
  $stderr  = StringIO.new
  $stdout  = StringIO.new
  yield orig_out, orig_err
  puts [$stdout.dup, $stderr.dup].inspect
  return $stdout.dup, $stderr.dup
ensure
  $stdout = orig_out
  $stderr = orig_err
end

#wrap_stdout_and_rescue(error, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hatchet/anvil_app.rb', line 26

def wrap_stdout_and_rescue(error, &block)
  wrap_stdout do |orig_out, orig_err|
    begin
      yield orig_out, orig_err
    rescue error => e
      return [$stdout.dup, $stderr.dup] if @allow_failure
      orig_out.puts $stderr.dup.string # print the errors to the test output
      raise e
    end
  end
end