Module: Jax::Generators::Actions
- Included in:
- PluginGenerator, PluginManager
- Defined in:
- lib/generators/jax/base/actions.rb
Instance Method Summary collapse
- #menu(items, options = {}) ⇒ Object
- #menu_choice(*args) ⇒ Object
- #overwrite(path) ⇒ Object
- #prompt_yn(message, options = {}) ⇒ Object
- #say_option(which, caption) ⇒ Object
Instance Method Details
#menu(items, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/generators/jax/base/actions.rb', line 7 def (items, = {}) min = 1 if [:allow_all] say_option 0, "All candidates" min = 0 end items.each_with_index do |item, index| say_option index+1, item end which = (:min => min, :max => items.length) if which == -1 items.each_with_index { |item, index| yield item, index } else yield items[which], which end end |
#menu_choice(*args) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/generators/jax/base/actions.rb', line 26 def (*args) = args. , = *args = "Please select an option, or press ctrl+c to cancel >" unless which = ask("#{}#{}") sel = which.to_i # if sel.to_s != which then which is non-numeric if sel.to_s != which || [:min] && sel < [:min] || [:max] && sel > [:max] (, "Invalid choice. ") else sel - 1 end end |
#overwrite(path) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/generators/jax/base/actions.rb', line 45 def overwrite(path) path = path.to_s if File.exist? path prompt_yn "Path '#{path}' already exists! Delete it?" FileUtils.rm_rf path end end |
#prompt_yn(message, options = {}) ⇒ Object
2 3 4 5 |
# File 'lib/generators/jax/base/actions.rb', line 2 def prompt_yn(, = {}) yn = ask().downcase[0] throw :aborted, "Aborted by user." if yn != ?y end |
#say_option(which, caption) ⇒ Object
41 42 43 |
# File 'lib/generators/jax/base/actions.rb', line 41 def say_option(which, ) say "\t#{which}\t: #{}" end |