Class: Hatchet::App
- Inherits:
-
Object
- Object
- Hatchet::App
- Defined in:
- lib/hatchet.rb,
lib/hatchet/app.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.config ⇒ Object
config is read only, should be threadsafe.
Instance Method Summary collapse
- #config ⇒ Object
-
#debug? ⇒ Boolean
(also: #debugging?)
set debug: true when creating app if you don’t want it to be automatically destroyed, useful for debugging…bad for app limits.
-
#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?.
- #deployed? ⇒ Boolean
-
#initialize(repo_name, options = {}) ⇒ App
constructor
A new instance of App.
- #not_debugging? ⇒ Boolean (also: #no_debug?)
- #push! ⇒ Object
-
#run(command, timeout = nil, &block) ⇒ Object
runs a command on heroku similar to ‘$ heroku run #foo` but programatically and with more control.
-
#setup! ⇒ Object
creates a new heroku app via the API.
- #teardown! ⇒ Object
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, = {}) @directory = config.path_for_name(repo_name) @name = [:name] || "test-app-#{Time.now.to_f}".gsub('.', '-') @debug = [:debug] || [:debugging] end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
3 4 5 |
# File 'lib/hatchet/app.rb', line 3 def directory @directory end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/hatchet/app.rb', line 3 def name @name end |
Class Method Details
Instance Method Details
#config ⇒ Object
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
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
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?
34 35 36 |
# File 'lib/hatchet/app.rb', line 34 def not_debugging? !debug? end |
#push! ⇒ Object
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 |