Module: LabClient::ClientSetup

Included in:
Client
Defined in:
lib/labclient/client/setup.rb

Overview

Methods for Initialization

Instance Method Summary collapse

Instance Method Details

#fill_configurationObject

Load default profile



6
7
8
9
10
11
12
13
14
15
# File 'lib/labclient/client/setup.rb', line 6

def fill_configuration
  if File.exist? home_file
    Oj.load_file(home_file, { symbol_keys: true })
  else
    {
      url: ENV['LABCLIENT_URL'],
      token: ENV['LABCLIENT_TOKEN']
    }
  end
end

#prompt_for_tokenObject

Check for Token



25
26
27
28
29
# File 'lib/labclient/client/setup.rb', line 25

def prompt_for_token
  print 'Enter Personal Access Token: '

  @settings[:token] = ENV['LABCLIENT_TESTING'] ? 'testt' : $stdin.gets&.chomp
end

#prompt_for_urlObject

If nothing entered Prompt for Input



18
19
20
21
22
# File 'lib/labclient/client/setup.rb', line 18

def prompt_for_url
  print 'Enter GitLab URL (e.g. https://gitlab.com): '
  @settings[:url] = ENV['LABCLIENT_TESTING'] ? 'testu' : $stdin.gets&.chomp
  raise 'LabClient Error - Missing URL!' if @settings[:url].blank?
end

#setup_profileObject

Support for Named Profiles



43
44
45
46
47
48
49
50
51
# File 'lib/labclient/client/setup.rb', line 43

def setup_profile
  return false unless File.exist? home_file

  config = Oj.load_file(home_file, { symbol_keys: true })
  return false unless config.key? profile

  self.settings ||= {}
  settings.merge! config[profile]
end

#unspecified_defaultsObject

Fill Defaults



32
33
34
35
36
37
38
39
40
# File 'lib/labclient/client/setup.rb', line 32

def unspecified_defaults
  @settings[:paginate] = true if @settings[:paginate].nil?
  @settings[:ssl_verify] = true if @settings[:ssl_verify].nil?
  @settings[:quiet] = false if @settings[:quiet].nil?
  @settings[:debug] = false if @settings[:quiet].nil?
  @settings[:debug] = false if @settings[:debug].nil?
  @settings[:token_type] = 'Private-Token' if @settings[:token_type].nil?
  @settings[:retry] = { max: 5, delay_factor: 10, count: 0 } if @settings[:retry].nil?
end