Class: Liberator::Controller
- Inherits:
-
Object
- Object
- Liberator::Controller
- Defined in:
- lib/liberator/controller.rb
Instance Method Summary collapse
- #handle_key(key) ⇒ Object
-
#initialize(view) ⇒ Controller
constructor
A new instance of Controller.
- #listen ⇒ Object
- #render ⇒ Object
Constructor Details
#initialize(view) ⇒ Controller
Returns a new instance of Controller.
3 4 5 6 7 8 |
# File 'lib/liberator/controller.rb', line 3 def initialize(view) @view = view @view. "Analyzing #{Dir.pwd}..." @directory = Directory.new Dir.pwd render end |
Instance Method Details
#handle_key(key) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/liberator/controller.rb', line 16 def handle_key(key) case key when 'q' @view.close exit when 'j' @directory.select_next_entry render when 'k' @directory.select_previous_entry render when 10 if File.directory? @directory.selected_entry[:path] @view. "Analyzing #{@directory.selected_entry[:path]}..." begin @directory = Directory.new @directory.selected_entry[:path] rescue IOError @view. "Cannot change directories due to permissions" end render end when 'h' @view. "Analyzing #{File.(@directory.path + '/..')}..." @directory = @directory.parent render when 'x' @directory.delete_selected_entry if @view.confirm_delete @directory.refresh render end end |
#listen ⇒ Object
10 11 12 13 14 |
# File 'lib/liberator/controller.rb', line 10 def listen loop do handle_key @view.capture_keystroke end end |
#render ⇒ Object
48 49 50 |
# File 'lib/liberator/controller.rb', line 48 def render @view.refresh(@directory.path, @directory.entries, @directory.selected_index) end |