Class: MiniReadline::AutoFileSource
- Inherits:
-
Object
- Object
- MiniReadline::AutoFileSource
- Defined in:
- lib/mini_readline/read_line/edit/auto_complete/auto_file_source.rb
Overview
A flexible file source for shell emulation.
Constant Summary collapse
- EXTRACT =
The regex for extraction of the root and pivot.
/("[^"\s][^"]*"?$)|(\S+$)/
Instance Method Summary collapse
-
#backslash? ⇒ Boolean
Does this file name use backslashes?.
-
#dress_down(name) ⇒ Object
Prepare the file name for internal use.
-
#dress_up(name) ⇒ Object
Prepare the file name for external use.
-
#dress_up_quotes(name) ⇒ Object
Dress up in quotes if needed.
-
#dress_up_slashes(name) ⇒ Object
Dress up slashes and backslashes.
-
#extract_root_pivot(str) ⇒ Object
Parse the string into the two basic components.
-
#initialize(_options) ⇒ AutoFileSource
constructor
Create a new file/folder auto-data source.
-
#next ⇒ Object
Get the next string for auto-complete.
-
#rebuild(str) ⇒ Object
Construct a new data list for auto-complete.
Constructor Details
#initialize(_options) ⇒ AutoFileSource
Create a new file/folder auto-data source. NOP
10 11 12 |
# File 'lib/mini_readline/read_line/edit/auto_complete/auto_file_source.rb', line 10 def initialize() #Do nothing here! end |
Instance Method Details
#backslash? ⇒ Boolean
Does this file name use backslashes?
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/mini_readline/read_line/edit/auto_complete/auto_file_source.rb', line 63 def backslash? if @pivot.end_with?("\\") true elsif @pivot.end_with?("/") false elsif @pivot["\\"] true elsif @pivot["/"] false else MiniTerm.windows? end end |
#dress_down(name) ⇒ Object
Prepare the file name for internal use. Endemic Code Smells :reek:UtilityFunction
39 40 41 |
# File 'lib/mini_readline/read_line/edit/auto_complete/auto_file_source.rb', line 39 def dress_down(name) name.gsub("\\", "/").gsub('"', '') end |
#dress_up(name) ⇒ Object
Prepare the file name for external use. Endemic Code Smells :reek:UtilityFunction
46 47 48 |
# File 'lib/mini_readline/read_line/edit/auto_complete/auto_file_source.rb', line 46 def dress_up(name) dress_up_quotes(dress_up_slashes(name)) end |
#dress_up_quotes(name) ⇒ Object
Dress up in quotes if needed. Endemic Code Smells :reek:UtilityFunction
58 59 60 |
# File 'lib/mini_readline/read_line/edit/auto_complete/auto_file_source.rb', line 58 def dress_up_quotes(name) name[' '] ? "\"#{name}\"" : name end |
#dress_up_slashes(name) ⇒ Object
Dress up slashes and backslashes.
51 52 53 |
# File 'lib/mini_readline/read_line/edit/auto_complete/auto_file_source.rb', line 51 def dress_up_slashes(name) backslash? ? name.gsub("/", "\\") : name end |
#extract_root_pivot(str) ⇒ Object
Parse the string into the two basic components.
27 28 29 |
# File 'lib/mini_readline/read_line/edit/auto_complete/auto_file_source.rb', line 27 def extract_root_pivot(str) @root, @pivot = EXTRACT =~ str ? [$PREMATCH, $MATCH] : [str, ""] end |
#next ⇒ Object
Get the next string for auto-complete
32 33 34 |
# File 'lib/mini_readline/read_line/edit/auto_complete/auto_file_source.rb', line 32 def next @root + dress_up(@cycler.next) end |
#rebuild(str) ⇒ Object
Construct a new data list for auto-complete
15 16 17 18 19 20 21 |
# File 'lib/mini_readline/read_line/edit/auto_complete/auto_file_source.rb', line 15 def rebuild(str) extract_root_pivot(str) list = Dir.glob(dress_down(@pivot) + '*') @cycler = list.empty? ? nil : list.cycle end |