Class: ConfigFile
- Inherits:
-
Object
- Object
- ConfigFile
- Defined in:
- lib/trail_marker/config_file.rb
Overview
History:
2/19/2018 Created [email protected]
Direct Known Subclasses
Instance Attribute Summary collapse
-
#default_comment ⇒ Object
Returns the value of attribute default_comment.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#testrail_url ⇒ Object
Returns the value of attribute testrail_url.
-
#token ⇒ Object
Returns the value of attribute token.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #check_create_configfile ⇒ Object
- #config_project ⇒ Object
- #create_configfile ⇒ Object
-
#initialize(cfile) ⇒ ConfigFile
constructor
A new instance of ConfigFile.
- #prompt_user(user_msg, default_val) ⇒ Object
- #read_config_file ⇒ Object
- #save ⇒ Object
- #update(varname, varvalue) ⇒ Object
- #user_continue?(user_msg, default_val = false) ⇒ Boolean
Constructor Details
#initialize(cfile) ⇒ ConfigFile
Returns a new instance of ConfigFile.
11 12 13 14 |
# File 'lib/trail_marker/config_file.rb', line 11 def initialize(cfile) @filename = cfile read_config_file end |
Instance Attribute Details
#default_comment ⇒ Object
Returns the value of attribute default_comment.
9 10 11 |
# File 'lib/trail_marker/config_file.rb', line 9 def default_comment @default_comment end |
#filename ⇒ Object
Returns the value of attribute filename.
9 10 11 |
# File 'lib/trail_marker/config_file.rb', line 9 def filename @filename end |
#testrail_url ⇒ Object
Returns the value of attribute testrail_url.
9 10 11 |
# File 'lib/trail_marker/config_file.rb', line 9 def testrail_url @testrail_url end |
#token ⇒ Object
Returns the value of attribute token.
9 10 11 |
# File 'lib/trail_marker/config_file.rb', line 9 def token @token end |
#username ⇒ Object
Returns the value of attribute username.
9 10 11 |
# File 'lib/trail_marker/config_file.rb', line 9 def username @username end |
Instance Method Details
#check_create_configfile ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/trail_marker/config_file.rb', line 59 def check_create_configfile if ! File.exist?(@filename) puts "\nWARNING: Configuration File does not exist." if user_continue?("Create a new config file (Y/N)? : ", 'N') create_configfile end end end |
#config_project ⇒ Object
88 89 90 91 92 |
# File 'lib/trail_marker/config_file.rb', line 88 def config_project @project_name = prompt_user("Enter testrail project name: ") @testrun = prompt_user("Enter name of test run: ", "NA") @testplan = prompt_user("Enter name of test plan: ", "NA") end |
#create_configfile ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/trail_marker/config_file.rb', line 68 def create_configfile @username = prompt_user("Enter testrail email (#{@username}): ", @username) @token = prompt_user("Enter testrail token (#{@token}): ", @token) @testrail_url = prompt_user("TestRail URL (#{@testrail_url}): ", @testrail_url) @default_comment = prompt_user("Test comment (Default - Marked by Automation): ", "Marked by Automation") @trail_info = Hash.new @trail_info["username"] = @username @trail_info["token"] = @token @trail_info["testrail_url"] = @testrail_url @trail_info["default_comment"] = @default_comment save # Comment out until overwrite is finished. #if user_continue?("Do you want to save the testrail project info (Y/N)?") # config_project # thash["project_name"] = @project_name # thash["testrun"] = @testrun # thash["testplan"] = @testplan #end end |
#prompt_user(user_msg, default_val) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/trail_marker/config_file.rb', line 16 def prompt_user(user_msg, default_val) retval = default_val newval = '' atmps = 0 while newval.strip == '' && atmps < 3 atmps += 1 print "#{user_msg}" newval = STDIN.gets retval = newval.strip == '' ? default_val : newval.strip newval = retval end if atmps >= 3 puts "\nERROR: Value cannot be empty... exiting." exit(0) end return retval end |
#read_config_file ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/trail_marker/config_file.rb', line 43 def read_config_file if File.exist?(@filename) @trail_info = YAML.load_file(@filename) @username = @trail_info["username"] @token = @trail_info["token"] @testrail_url = @trail_info["testrail_url"] @default_comment = @trail_info['default_comment'] else @trail_info = Hash.new @username = '' @token = '' @testrail_url = '' @default_comment = 'Marked by Automation' end end |
#save ⇒ Object
100 101 102 103 104 105 |
# File 'lib/trail_marker/config_file.rb', line 100 def save File.open(@filename, 'w') { |f| f.write @trail_info.to_yaml puts "Successfully saved config file: #{@filename}" } end |
#update(varname, varvalue) ⇒ Object
94 95 96 97 98 |
# File 'lib/trail_marker/config_file.rb', line 94 def update(varname, varvalue) if defined? @trail_info @trail_info[varname] = varvalue end end |
#user_continue?(user_msg, default_val = false) ⇒ Boolean
34 35 36 37 38 39 40 41 |
# File 'lib/trail_marker/config_file.rb', line 34 def user_continue?(user_msg, default_val=false) retval = default_val reply = prompt_user(user_msg, 'N') if reply.upcase == "Y" retval = true end return retval end |