lib/app42/base/util.rb in app42-0.5.3 vs lib/app42/base/util.rb in app42-0.5.4
- old
+ new
@@ -17,15 +17,19 @@
# @param choices
# @param indexed
#
# @return +input string+
def input message, choices, indexed = true
- list = choices.compact unless choices.empty?
- ans = ask Paint["#{message}", :cyan],
+ if choices.empty?
+ ans = ask Paint["#{message}", :cyan]
+ else
+ list = choices.compact unless choices.empty?
+ ans = ask Paint["#{message}", :cyan],
:choices => list,
:default => list[0],
:indexed => indexed
+ end
print_new_line
return ans
end
#
@@ -123,12 +127,11 @@
#
#REVIEW, need to verify FAILED use case
def check_transaction_status transaction_id, previous_completed, what
begin
flag = false
- message "#{Message::LATEST_S_WAIT}", true, 'green'
- print 'Latest Status....'
+ message "#{Message::LATEST_S_WAIT}", false, 'green'
while flag == false do
response = status_call transaction_id
re_try ||= 1
if response["success"] == true && response["transactionStatus"] == "COMPLETED"
@@ -156,11 +159,11 @@
exit!
end
sleep 5
end
rescue Interrupt
- puts Paint[" Command cancelled.", :red]
+ message "#{Message::LATEST_S_INTERRUPT}", true, 'red'
exit!
end
end
# rest call for transaction status check
@@ -171,11 +174,11 @@
@same_status_retry ||= 1
response = get_request signature(query_params), resource_url('info', 'transaction'), query_params
return response
rescue Interrupt
- puts Paint[" Command cancelled.", :red]
+ message "#{Message::LATEST_S_INTERRUPT}", true, 'red'
exit!
end
end
# Escape white space and special character from path as per OS
@@ -243,25 +246,25 @@
# Check whether +app OR service+ name is valid OR not
# +app OR service+ name lenght should not be more than 30 character
# And should not contain any special character
def validate_app_and_service_name name, str
if str.match(App42::REGEX) || str.length > 30
- message "#{name} should not contain any special character or white space and it's length should be less than 30.", true, 'red'
+ message "#{name} should not contain any special character or white space and length should be less than 30.", true, 'red'
return false
else
return str
end
end
# Check whether +database name+ is valid OR not
# +database name+ lenght should not be more than 64 character
# And should not contain any special character
def validate_database_name name, str
- if str.match(App42::REGEX) || str.length > 64
- message "#{name} should not contain any special character and it's length should be less than 64.", true, 'red'
+ if str.match(App42::DBNAME_REGEX) || str.length > 64 || (numeric_including_zero? str)
+ message "Invalid database name. Should be less than 64 characters (Alphabets, alphanumeric and underscore(_) is allowed).", true, 'red'
return false
elsif App42::DATABASE_NAME_NOT_ALLOWED.include? str
- message "Your can't create database name with: #{str}.", true, 'red'
+ message "Database Name should not be '#{str}'.", true, 'red'
return false
else
return str
end
end
\ No newline at end of file