From 88f55e4e1644269ec4e72512dcf2ffdf6e958bb0 Mon Sep 17 00:00:00 2001 From: Gordon Fontenot Date: Tue, 11 Mar 2014 15:52:03 -0400 Subject: [PATCH] Trap interrupt during option input * Extract OptionFetcher This class handles fetching the options from the user, and manages the various interrupt signals during input Fixes #81 --- lib/liftoff.rb | 1 + lib/liftoff/launchpad.rb | 7 ++----- lib/liftoff/option_fetcher.rb | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 lib/liftoff/option_fetcher.rb diff --git a/lib/liftoff.rb b/lib/liftoff.rb index 1e35a0d..2dcffc7 100644 --- a/lib/liftoff.rb +++ b/lib/liftoff.rb @@ -16,6 +16,7 @@ require 'liftoff/git_setup' require 'liftoff/launchpad' require 'liftoff/object_picker' +require 'liftoff/option_fetcher' require 'liftoff/project' require 'liftoff/project_builder' require 'liftoff/project_configuration' diff --git a/lib/liftoff/launchpad.rb b/lib/liftoff/launchpad.rb index c0cb5c6..95e7efb 100644 --- a/lib/liftoff/launchpad.rb +++ b/lib/liftoff/launchpad.rb @@ -23,10 +23,7 @@ def liftoff private def fetch_options - @config.project_name = ask('Project name? ') { |q| q.default = @config.project_name } - @config.company = ask('Company name? ') { |q| q.default = @config.company } - @config.author = ask('Author name? ') { |q| q.default = @config.author } - @config.prefix = ask('Prefix? ') { |q| q.default = @config.prefix }.upcase + OptionFetcher.new(@config).fetch_options end def perform_project_actions @@ -69,7 +66,7 @@ def enable_warnings def enable_static_analyzer xcode_helper.enable_static_analyzer(@config.enable_static_analyzer) end - + def open_project `open -a "Xcode" .` end diff --git a/lib/liftoff/option_fetcher.rb b/lib/liftoff/option_fetcher.rb new file mode 100644 index 0000000..103814d --- /dev/null +++ b/lib/liftoff/option_fetcher.rb @@ -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