Module: Flydata::Helpers

Included in:
ApiClient, Cli, Command::Setup, Credentials
Defined in:
lib/flydata/helpers.rb

Class Method Summary collapse

Class Method Details

.development?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/flydata/helpers.rb', line 38

def development?
  File.open(flydata_conf_file).first.strip.end_with?('dev')
end

.flydata_api_host_fileObject



67
68
69
# File 'lib/flydata/helpers.rb', line 67

def flydata_api_host_file
  File.join(flydata_home_directory, 'flydata_api_host')
end

.flydata_conf_fileObject



71
72
73
# File 'lib/flydata/helpers.rb', line 71

def flydata_conf_file
  File.join(flydata_home_directory, 'flydata.conf')
end

.flydata_home_directoryObject



63
64
65
# File 'lib/flydata/helpers.rb', line 63

def flydata_home_directory
  File.join(home_directory, '.flydata')
end

.format_menu_list(menu_list) ⇒ Object

format text



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/flydata/helpers.rb', line 43

def format_menu_list(menu_list)
  max_length_list = menu_list.inject(Array.new(menu_list.first.size, 0)) do |ml, menu|
    0.upto(menu.size - 1) do |i|
      ml[i] = menu[i].length if ml[i] < menu[i].length
    end
    ml
  end

  menu_list = menu_list.collect do |menu|
    0.upto(menu.size - 1).inject("") do |str, i|
      str = "#{str}#{menu[i].ljust(max_length_list[i] + 1, ' ')}"
    end
  end
end

.home_directoryObject

file paths



59
60
61
# File 'lib/flydata/helpers.rb', line 59

def home_directory
  ENV['HOME'] || Dir.pwd
end

.parse_command(cmd) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/flydata/helpers.rb', line 4

def parse_command(cmd)
  klass = Flydata::Command::Base
  method = cmd
  if cmd.include?(':')
    class_name, method = cmd.split(':')
    klass = to_command_class(class_name)
  end
  [klass, method]
end


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/flydata/helpers.rb', line 14

def print_usage
  puts '-' * 64
  puts <<-EOM
Usage: flydata COMMAND
  setup                    # setup initially
  start                    # start flydata process
  stop                     # stop flydata process
  restart                  # restart flydata process

If you encountered login or any other errors during setup,
please setup flydata again by following commands.
   source ~/.bashrc
   flydata setup

You can check the logs of sender(flydata) process.
   Log path: ~/.flydata/flydata.log
  EOM
  puts '-' * 64
end

.to_command_class(class_name) ⇒ Object



34
35
36
# File 'lib/flydata/helpers.rb', line 34

def to_command_class(class_name)
  eval("Flydata::Command::#{class_name.camelcase}")
end