Module: Zillabyte::Helpers

Extended by:
Helpers
Included in:
Auth, CLI, Command, Command::Base, Helpers
Defined in:
lib/zillabyte/helpers.rb

Defined Under Namespace

Classes: DataSchemaBuilder

Instance Method Summary collapse

Instance Method Details

#ask ⇒ Object



35
36
37
# File 'lib/zillabyte/helpers.rb', line 35

def ask
  $stdin.gets.to_s.strip
end

#display(msg = "", new_line = true) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/zillabyte/helpers.rb', line 7

def display(msg="", new_line=true)
  if new_line
    puts(msg)
  else
    print(msg)
    $stdout.flush
  end
end

#error(message) ⇒ Object



17
18
19
20
# File 'lib/zillabyte/helpers.rb', line 17

def error(message)
  $stderr.puts(format_with_bang(message))
  exit(1)
end

#format_with_bang(message) ⇒ Object



22
23
24
25
# File 'lib/zillabyte/helpers.rb', line 22

def format_with_bang(message)
  return '' if message.to_s.strip == ""
  " !    " + message.split("\n").join("\n !    ")
end

#longest(items) ⇒ Object



27
28
29
# File 'lib/zillabyte/helpers.rb', line 27

def longest(items)
  items.map { |i| i.to_s.length }.sort.last
end

#read_multiline ⇒ Object



31
32
33
# File 'lib/zillabyte/helpers.rb', line 31

def read_multiline
  $stdin.gets
end

#with_tty(&block) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/zillabyte/helpers.rb', line 39

def with_tty(&block)
  return unless $stdin.isatty
  begin
    yield
  rescue
    # fails on windows
  end
end