Class: Hatchet::App

Inherits:
Object
  • Object
show all
Defined in:
lib/hatchet.rb,
lib/hatchet/app.rb

Direct Known Subclasses

AnvilApp, GitApp

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_name, options = {}) ⇒ App

Returns a new instance of App.



5
6
7
8
9
# File 'lib/hatchet/app.rb', line 5

def initialize(repo_name, options = {})
  @directory = config.path_for_name(repo_name)
  @name      = options[:name]  || "test-app-#{Time.now.to_f}".gsub('.', '-')
  @debug     = options[:debug] || options[:debugging]
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



3
4
5
# File 'lib/hatchet/app.rb', line 3

def directory
  @directory
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/hatchet/app.rb', line 3

def name
  @name
end

Class Method Details

.configObject

config is read only, should be threadsafe



12
13
14
# File 'lib/hatchet/app.rb', line 12

def self.config
  @config ||= Config.new
end

Instance Method Details

#configObject



16
17
18
# File 'lib/hatchet/app.rb', line 16

def config
  self.class.config
end

#debug?Boolean Also known as: debugging?

set debug: true when creating app if you don’t want it to be automatically destroyed, useful for debugging…bad for app limits. turn on global debug by setting HATCHET_DEBUG=true in the env

Returns:

  • (Boolean)


29
30
31
# File 'lib/hatchet/app.rb', line 29

def debug?
  @debug || ENV['HATCHET_DEBUG'] || false
end

#deploy(&block) ⇒ Object

creates a new app on heroku, “pushes” via anvil or git then yields to self so you can call self.run or self.deployed?



65
66
67
68
69
70
71
72
73
# File 'lib/hatchet/app.rb', line 65

def deploy(&block)
  Dir.chdir(directory) do
    self.setup!
    result, output = self.push!
    block.call(self, heroku, output)
  end
ensure
  self.teardown!
end

#deployed?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/hatchet/app.rb', line 39

def deployed?
  !heroku.get_ps(name).body.detect {|ps| ps["process"].include?("web") }.nil?
end

#not_debugging?Boolean Also known as: no_debug?

Returns:

  • (Boolean)


34
35
36
# File 'lib/hatchet/app.rb', line 34

def not_debugging?
  !debug?
end

#push!Object

Raises:

  • (NotImplementedError)


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

def push!
  raise NotImplementedError
end

#run(command, timeout = nil, &block) ⇒ Object

runs a command on heroku similar to ‘$ heroku run #foo` but programatically and with more control



22
23
24
# File 'lib/hatchet/app.rb', line 22

def run(command, timeout = nil, &block)
  ProcessSpawn.new(command, self, timeout).run(&block)
end

#setup!Object

creates a new heroku app via the API



44
45
46
47
# File 'lib/hatchet/app.rb', line 44

def setup!
  heroku.post_app(name: name)
  @app_is_setup = true
end

#teardown!Object



53
54
55
56
57
58
59
60
# File 'lib/hatchet/app.rb', line 53

def teardown!
  return false unless @app_is_setup
  if debugging?
    puts "Debugging App:#{name}"
    return false
  end
  heroku.delete_app(name)
end