-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from seanpdoyle/runner
Add Runner class to monitor and activate ember apps
- Loading branch information
Showing
5 changed files
with
80 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module EmberCLI | ||
class Runner | ||
TRUE_PROC = ->(*){ true } | ||
|
||
attr_reader :app, :path | ||
|
||
def initialize(app, path) | ||
@app, @path = app, path | ||
end | ||
|
||
def process | ||
return if skip? | ||
|
||
if EmberCLI.env.development? | ||
start_or_restart! | ||
else | ||
compile! | ||
end | ||
|
||
wait! | ||
end | ||
|
||
private | ||
|
||
def skip? | ||
invoker = app.options.fetch(:enable, TRUE_PROC) | ||
!invoker.call(path) | ||
end | ||
|
||
def start_or_restart! | ||
run! unless app.pid && still_running? | ||
end | ||
|
||
def still_running? | ||
Process.getpgid app.pid | ||
true | ||
rescue Errno::ESRCH # no such process | ||
false | ||
end | ||
|
||
def wait! | ||
app.wait | ||
end | ||
|
||
def compile! | ||
app.compile | ||
end | ||
|
||
def run! | ||
app.run | ||
end | ||
end | ||
end |