Class: Ctrl::InstanceSelector
- Inherits:
-
Object
- Object
- Ctrl::InstanceSelector
- Includes:
- Virtus::Model
- Defined in:
- lib/ctrl/instance_selector.rb
Instance Method Summary collapse
Instance Method Details
#display_options ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/ctrl/instance_selector.rb', line 7 def puts "Instances" instances.each_with_index do |instance, i| puts ("%2d %s" % [i + 1, instance.to_s]) end puts "\nPlease select an instance" end |
#perform ⇒ Object
28 29 30 |
# File 'lib/ctrl/instance_selector.rb', line 28 def perform instances.size == 1 ? instances.first : selection end |
#selection ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ctrl/instance_selector.rb', line 15 def selection return @selection if @selection loop do selected_index = Readline.readline(">> ") @selection = instances[selected_index.to_i - 1] break if selected_index.to_i > 0 && @selection end @selection end |