-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Extract OptionFetcher This class handles fetching the options from the user, and manages the various interrupt signals during input Fixes #81
- Loading branch information
Showing
3 changed files
with
29 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Liftoff | ||
class OptionFetcher | ||
def initialize(configuration) | ||
@configuration = configuration | ||
end | ||
|
||
def fetch_options | ||
fetch_option_for(:project_name, 'Project name') | ||
fetch_option_for(:company, 'Company name') | ||
fetch_option_for(:author, 'Author name') | ||
fetch_option_for(:prefix, 'Prefix') | ||
end | ||
|
||
private | ||
|
||
def fetch_option_for(attribute, prompt) | ||
value = ask("#{prompt}? ") { |q| q.default = @configuration.public_send(attribute) } | ||
@configuration.public_send("#{attribute}=", value) | ||
rescue EOFError | ||
puts | ||
fetch_option_for(attribute, prompt) | ||
rescue Interrupt | ||
exit 1 | ||
end | ||
end | ||
end |