Sha256: 3e43b2421b836798c5fb1687207cc3f4ee99a581edd73e8c75554176d6a9bc1e

Contents?: true

Size: 1.83 KB

Versions: 7

Compression:

Stored size: 1.83 KB

Contents

module Flydata
  module Helpers
    module_function
    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

    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

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

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

    # format text
    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

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

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

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
flydata-0.0.5.3 lib/flydata/helpers.rb
flydata-0.0.5.2 lib/flydata/helpers.rb
flydata-0.0.5.1 lib/flydata/helpers.rb
flydata-0.0.5.0 lib/flydata/helpers.rb
flydata-0.0.4.4 lib/flydata/helpers.rb
flydata-0.0.4.3 lib/flydata/helpers.rb
flydata-0.0.4.2 lib/flydata/helpers.rb