Class: GemWizard

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_wizard.rb

Class Method Summary collapse

Class Method Details

.ask_sub_prompts(sub_prompts) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/gem_wizard.rb', line 30

def self.ask_sub_prompts(sub_prompts)
  sub_prompts.each do |prompt|
    puts prompt['message']

    if boolean(gets.chomp)
      @pre_install_commands << prompt['pre_install_commands'] unless prompt['pre_install_commands'].nil?
      @post_install_commands << prompt['post_install_commands'] unless prompt['post_install_commands'].nil?
    end
  end
end

.boolean(string) ⇒ Object

—– helper methods —–#



49
50
51
52
53
# File 'lib/gem_wizard.rb', line 49

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 —–#



42
43
44
45
46
# File 'lib/gem_wizard.rb', line 42

def self.gemify!
  system(@pre_install_commands.flatten.join(' '))
  system('bundle install')
  system(@post_install_commands.flatten.join(' '))
end

.startObject

—– asking the right questions —–#



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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)

  @pre_install_commands = []
  @post_install_commands = []

  gems.each do |gem|
    puts gem['prompt']

    if boolean(gets.chomp)
      gem_groups = gem['gem_groups'].join(' ') unless gem['gem_groups'].nil?
      command = "bundle add #{gem['name']} #{!gem_groups.nil? ? "--group #{gem_groups}" : nil}"

      @pre_install_commands << command

      ask_sub_prompts(gem['sub_prompts'])
    end
  end

  gemify!
end