Module: Gill::Helper
- Included in:
- CLI, Git, Import, Remove, Settings::Config
- Defined in:
- lib/gill/helper.rb
Instance Method Summary collapse
-
#ask(msg, options = {}) ⇒ Object
Prompt the use for input.
-
#basename(path) ⇒ Object
Basename.
-
#blue(msg) ⇒ String
Blue.
-
#folder_empty?(folder) ⇒ true, false
Empty Folder?.
-
#green(msg) ⇒ String
Green.
-
#parent(path) ⇒ String
Parent Name.
-
#red(msg) ⇒ String
Red.
Instance Method Details
#ask(msg, options = {}) ⇒ Object
Prompt the use for input
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/gill/helper.rb', line 86 def ask(msg, ={}) default = [:default] || false if default STDOUT.print "#{green("INFO")} #{msg} [Y/n] " else STDOUT.print "#{green("INFO")} #{msg} [y/N] " end input = STDIN.gets.chomp STDOUT.flush if block_given? if input[/([Yy]|[Yy]es)$/i] yield elsif input[/([Nn]|[Nn]o)$/i] return else yield if default end end end |
#basename(path) ⇒ Object
Basename
45 46 47 |
# File 'lib/gill/helper.rb', line 45 def basename(path) Pathname.new(path).basename end |
#blue(msg) ⇒ String
Blue
23 24 25 |
# File 'lib/gill/helper.rb', line 23 def blue(msg) "\e[34m#{msg}\e[0m" end |
#folder_empty?(folder) ⇒ true, false
Empty Folder?
67 68 69 70 71 72 73 74 |
# File 'lib/gill/helper.rb', line 67 def folder_empty?(folder) if File.exists?(folder) return true unless Dir.enum_for(:foreach, folder).any? {|n| /\A\.\.?\z/ !~ n} return false else return false end end |
#green(msg) ⇒ String
Green
12 13 14 |
# File 'lib/gill/helper.rb', line 12 def green(msg) "\e[32m#{msg}\e[0m" end |
#parent(path) ⇒ String
Parent Name
56 57 58 |
# File 'lib/gill/helper.rb', line 56 def parent(path) Pathname.new(path).parent end |
#red(msg) ⇒ String
Red
34 35 36 |
# File 'lib/gill/helper.rb', line 34 def red(msg) "\e[31m#{msg}\e[0m" end |