Class: Idcf::Cli::Lib::Configure

Inherits:
Object
  • Object
show all
Defined in:
lib/idcf/cli/lib/configure.rb

Overview

configure

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.code_configObject (readonly)

Returns the value of attribute code_config.



11
12
13
# File 'lib/idcf/cli/lib/configure.rb', line 11

def code_config
  @code_config
end

.configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/idcf/cli/lib/configure.rb', line 11

def config
  @config
end

Class Method Details

.get_code_conf(path, o = {}) ⇒ Object

get code setting value

Parameters:

  • path (String)

    find path

  • o (Hash) (defaults to: {})

    options

Returns:

  • String or Hash

Raises:



39
40
41
42
43
44
45
46
47
48
# File 'lib/idcf/cli/lib/configure.rb', line 39

def get_code_conf(path, o = {})
  profile = get_profile(o)

  return get_user_conf(path, profile)
rescue StandardError => _e
  return code_config.find(path) if code_config
  f_path       = Idcf::Cli::Conf::Const::CODE_CONF_PATH
  @code_config = Idcf::Cli::Lib::Util::YmlConf.new(f_path)
  code_config.find(path)
end

.get_profile(o) ⇒ Object

get profile

Parameters:

  • o (Hash)

    options

Returns:

  • String



54
55
56
# File 'lib/idcf/cli/lib/configure.rb', line 54

def get_profile(o)
  o['profile'] || 'default'
end

.get_region(o, read_conf = false) ⇒ Object

get region

Parameters:

  • o (Hash)

    options

  • read_conf (Boolean) (defaults to: false)

Returns:

  • String



63
64
65
66
67
68
69
70
# File 'lib/idcf/cli/lib/configure.rb', line 63

def get_region(o, read_conf = false)
  return o['region'] if o['region']
  region = ''
  region = get_user_conf('region', get_profile(o)) if read_conf
  region.empty? ? 'default' : region
rescue StandardError => _e
  'default'
end

.get_user_conf(name, profile = 'default') ⇒ Object

get user config value

Parameters:

  • name (String)
  • profile (String) (defaults to: 'default')

Returns:

  • String or Hash

Raises:



24
25
26
27
28
29
30
31
# File 'lib/idcf/cli/lib/configure.rb', line 24

def get_user_conf(name, profile = 'default')
  return config.find(name, profile) if config
  @config = load_user_conf
  msg     = 'Run the command `configure`'
  raise Idcf::Cli::Error::CliError, msg unless config

  config.find(name, profile)
end

.reloadObject



13
14
15
16
# File 'lib/idcf/cli/lib/configure.rb', line 13

def reload
  @config      = nil
  @code_config = nil
end