Module: Gill::Helper

Included in:
CLI, Git, Import, Remove, Settings::Config
Defined in:
lib/gill/helper.rb

Instance Method Summary collapse

Instance Method Details

#ask(msg, options = {}) ⇒ Object

Prompt the use for input

Parameters:

  • msg (String)

    Message to prompt for user input.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :default (Symbol, String)

    The default option for a return.



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, options={})
  default = options[: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

Parameters:

  • path (String)

    Path to extract the basename from

Returns:

  • (Object)

    Pathname Object



45
46
47
# File 'lib/gill/helper.rb', line 45

def basename(path)
  Pathname.new(path).basename
end

#blue(msg) ⇒ String

Blue

Parameters:

  • msg (String)

    Message to format.

Returns:

  • (String)

    Blue Colored String



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?

Parameters:

  • folder (String)

    Path to folder

Returns:

  • (true, false)

    Return true if the folder is empty.



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

Parameters:

  • msg (String)

    Message to format.

Returns:

  • (String)

    Green Colored String



12
13
14
# File 'lib/gill/helper.rb', line 12

def green(msg)
  "\e[32m#{msg}\e[0m"
end

#parent(path) ⇒ String

Parent Name

Parameters:

  • path (String)

    Path to extract the parent folder name from

Returns:

  • (String)

    Parent Folder Name



56
57
58
# File 'lib/gill/helper.rb', line 56

def parent(path)
  Pathname.new(path).parent
end

#red(msg) ⇒ String

Red

Parameters:

  • msg (String)

    Message to format.

Returns:

  • (String)

    Red Colored String



34
35
36
# File 'lib/gill/helper.rb', line 34

def red(msg)
  "\e[31m#{msg}\e[0m"
end