Module: Flydata::Helpers
- Included in:
- ApiClient, Cli, Command::Setup, Command::Sync, Credentials
- Defined in:
- lib/flydata/helpers.rb
Constant Summary collapse
- @@development_mode =
nil
Class Method Summary collapse
- .development? ⇒ Boolean
- .env_mode ⇒ Object
- .env_suffix ⇒ Object
- .flydata_api_host_file ⇒ Object
- .flydata_conf_file ⇒ Object
-
.format_menu_list(menu_list) ⇒ Object
format text.
- .parse_command(cmd) ⇒ Object
- .print_usage ⇒ Object
- .to_command_class(class_name) ⇒ Object
Class Method Details
.development? ⇒ Boolean
41 42 43 44 |
# File 'lib/flydata/helpers.rb', line 41 def development? return @@development_mode unless @@development_mode.nil? @@development_mode = !!(File.open(flydata_conf_file).first.strip.end_with?('dev')) end |
.env_mode ⇒ Object
46 47 48 |
# File 'lib/flydata/helpers.rb', line 46 def env_mode development? ? 'dev' : '' end |
.env_suffix ⇒ Object
50 51 52 |
# File 'lib/flydata/helpers.rb', line 50 def env_suffix development? ? '_dev' : '' end |
.flydata_api_host_file ⇒ Object
70 71 72 |
# File 'lib/flydata/helpers.rb', line 70 def flydata_api_host_file File.join(FLYDATA_HOME, 'flydata_api_host') end |
.flydata_conf_file ⇒ Object
74 75 76 |
# File 'lib/flydata/helpers.rb', line 74 def flydata_conf_file File.join(FLYDATA_HOME, 'flydata.conf') end |
.format_menu_list(menu_list) ⇒ Object
format text
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/flydata/helpers.rb', line 55 def () max_length_list = .inject(Array.new(.first.size, 0)) do |ml, | 0.upto(.size - 1) do |i| ml[i] = [i].length if ml[i] < [i].length end ml end = .collect do || 0.upto(.size - 1).inject("") do |str, i| str = "#{str}#{[i].ljust(max_length_list[i] + 1, ' ')}" end end end |
.parse_command(cmd) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/flydata/helpers.rb', line 5 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 |
.print_usage ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/flydata/helpers.rb', line 15 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 conf # show configuration sync # initial sync(only for mysql database) 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: #{File.join(FLYDATA_HOME, 'flydata.log')} EOM puts '-' * 64 end |
.to_command_class(class_name) ⇒ Object
37 38 39 |
# File 'lib/flydata/helpers.rb', line 37 def to_command_class(class_name) eval("Flydata::Command::#{class_name.camelcase}") end |