Class: CodeKindly::Utils::File
- Inherits:
-
Object
- Object
- CodeKindly::Utils::File
show all
- Includes:
- Presence
- Defined in:
- lib/code_kindly/utils/file.rb
Class Method Summary
collapse
Methods included from Presence
blank?, #blank?, present?, #present?
Class Method Details
.choose_from_options(dir_path, h_l = nil) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/code_kindly/utils/file.rb', line 13
def choose_from_options(dir_path, h_l = nil)
require 'highline'
h_l ||= HighLine.new
file_opts = file_options(dir_path)
return nil if blank? file_opts
msg = file_opts.inject('') { |(k, v), m| m + "\n #{k}: #{v}" }
option = h_l.ask("Select a file:#{msg}\n 0: None", Integer)
file_path = file_opts.fetch(option, nil)
return if file_path.nil?
::File.join(dir_path, file_path)
end
|
.file_options(path) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/code_kindly/utils/file.rb', line 25
def file_options(path)
require 'map'
options = Map.new
key = 0
find(path).each do |file|
options[key += 1] = file
end
options
end
|
.find(path) ⇒ Object
35
36
37
38
|
# File 'lib/code_kindly/utils/file.rb', line 35
def find(path)
require 'fileutils'
all(path).select { |entry| ::File.file?("#{path}/#{entry}") }
end
|
.trash!(file_string) ⇒ Object
42
43
44
|
# File 'lib/code_kindly/utils/file.rb', line 42
def trash!(file_string)
Kernel.system(command_to_trash_files(file_string))
end
|