Module: Eastrails::ThorExt

Included in:
Components::Haml, Components::Jasmine
Defined in:
lib/eastrails/thor_ext.rb

Instance Method Summary collapse

Instance Method Details

#ask_wizard(question) ⇒ Object



7
8
9
# File 'lib/eastrails/thor_ext.rb', line 7

def ask_wizard(question)
  ask "\033[1m\033[30m\033[46m" + (@current_recipe || "prompt").rjust(10) + "\033[1m\033[36m" + "  #{question}\033[0m"
end

#multiple_choice(question, choices) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/eastrails/thor_ext.rb', line 25

def multiple_choice(question, choices)
  say_custom('question', question)
  values = {}
  choices.each_with_index do |choice,i|
    values[(i + 1).to_s] = choice[1]
    say_custom( (i + 1).to_s + ')', choice[0] )
  end
  answer = ask_wizard("Enter your selection:") while !values.keys.include?(answer)
  values[answer]
end

#no_wizard?(question) ⇒ Boolean

Returns:

  • (Boolean)


23
# File 'lib/eastrails/thor_ext.rb', line 23

def no_wizard?(question); !yes_wizard?(question) end

#say_custom(tag, text) ⇒ Object



3
# File 'lib/eastrails/thor_ext.rb', line 3

def say_custom(tag, text); say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + "  #{text}" end

#say_recipe(name) ⇒ Object



4
# File 'lib/eastrails/thor_ext.rb', line 4

def say_recipe(name); say "\033[1m\033[36m" + "recipe".rjust(10) + "\033[0m" + "  Running #{name} recipe..." end

#say_wizard(text) ⇒ Object



5
# File 'lib/eastrails/thor_ext.rb', line 5

def say_wizard(text); say_custom(@current_recipe || 'eastrails', text) end

#yes_wizard?(question) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/eastrails/thor_ext.rb', line 11

def yes_wizard?(question)
  answer = ask_wizard(question + " \033[33m(y/n)\033[0m")
  case answer.downcase
  when "yes", "y"
    true
  when "no", "n"
    false
  else
    yes_wizard?(question)
  end
end