Class: GemWizard
- Inherits:
-
Object
- Object
- GemWizard
- Defined in:
- lib/gem_wizard.rb
Class Method Summary collapse
- .ask_sub_prompts(sub_prompts) ⇒ Object
-
.boolean(string) ⇒ Object
—– helper methods —–#.
-
.gemify! ⇒ Object
—– where the magic happens —–#.
-
.start ⇒ Object
—– asking the right questions —–#.
Class Method Details
.ask_sub_prompts(sub_prompts) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/gem_wizard.rb', line 24 def self.ask_sub_prompts(sub_prompts) sub_prompts.each do |prompt| puts prompt['message'] @post_install_commands << prompt['commands_if_accepted'] if boolean(gets.chomp) end end |
.boolean(string) ⇒ Object
—– helper methods —–#
39 40 41 42 43 |
# File 'lib/gem_wizard.rb', line 39 def self.boolean(string) return true if 'y'.casecmp(string).zero? || 'yes'.casecmp(string).zero? || 'true'.casecmp(string).zero? false end |
.gemify! ⇒ Object
—– where the magic happens —–#
33 34 35 36 |
# File 'lib/gem_wizard.rb', line 33 def self.gemify! system('bundle install') system(@post_install_commands.flatten.join(' ')) end |
.start ⇒ Object
—– asking the right questions —–#
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gem_wizard.rb', line 6 def self.start file_path = File.join( File.dirname(__FILE__), 'gems.json') file = File.read(file_path) gems = JSON.parse(file) @post_install_commands = [] gems.each do |gem| puts gem['prompt'] system("bundle add #{gem['name']}") if boolean(gets.chomp) ask_sub_prompts(gem['sub_prompts']) end gemify! end |