Class: Flydata::Command::Base
- Inherits:
-
Object
- Object
- Flydata::Command::Base
show all
- Defined in:
- lib/flydata/command/base.rb
Direct Known Subclasses
Conf, Crontab, Encrypt, Kill_all, Login, Restart, Routine, Sender, Setlogdel, Setup, Start, Status, Stop, Sync, Version
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
4
5
6
|
# File 'lib/flydata/command/base.rb', line 4
def initialize
@api_client = ApiClient.instance
end
|
Instance Method Details
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/flydata/command/base.rb', line 62
def ask_input_table_name
input = nil
loop do
say("Input a table name.")
say(">> ")
input = gets.strip
if input =~ /^[a-zA-Z0-9_]+$/
break
else
puts "Please enter a valid table name."
end
end
input
end
|
#ask_yes_no(message, default_yes = true) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/flydata/command/base.rb', line 34
def ask_yes_no(message, default_yes=true)
suffix = default_yes ? "(Y/n)" : "(y/n)"
loop do
ans = ask("#{message} #{suffix}: ")
return true if default_yes and ans == ''
if ans.size > 0
case ans[0].downcase
when 'y'; return true
when 'n'; return false
end
end
say(" ! Please answer y[es] or n[o]")
newline
end
end
|
#choose_one(message, prompt, menu_list, value_list = []) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/flydata/command/base.rb', line 49
def choose_one(message, prompt, , value_list=[])
choice = nil
value_list = unless .size == value_list.size
say(message) if message
choose do ||
.index = :number
.index_suffix = ") "
.select_by = :index
.prompt = prompt ? prompt : ">> "
.choices(*) {|item| choice = value_list[.index(item)]}
end
choice
end
|
#flydata ⇒ Object
7
|
# File 'lib/flydata/command/base.rb', line 7
def flydata; @api_client end
|
#newline ⇒ Object
30
|
# File 'lib/flydata/command/base.rb', line 30
def newline; puts end
|
#register_crontab ⇒ Object
22
23
24
25
26
27
|
# File 'lib/flydata/command/base.rb', line 22
def register_crontab
data_entries = retrieve_data_entries
if data_entries.any?{|e| e['log_deletion']}
Flydata::Command::Crontab.new.run
end
end
|
#retrieve_data_entries ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/flydata/command/base.rb', line 9
def retrieve_data_entries
data_entries = flydata.get('/data_entries')
unless flydata.response.code == 200 and data_entries
raise "Failed to retrieve data_entries"
end
data_entries.collect do |de|
if Flydata::Preference::DataEntryPreference.conf_exists?(de)
Flydata::Preference::DataEntryPreference.load_conf(de)
else
de
end
end
end
|
#separator(str = "=") ⇒ Object
31
32
33
|
# File 'lib/flydata/command/base.rb', line 31
def separator(str="=")
puts str * 64
end
|