Class: QingCloud::SDK::Config

Inherits:
Hash
  • Object
show all
Defined in:
lib/qingcloud/sdk/general/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_config = {}) ⇒ Config

Returns a new instance of Config.



37
38
39
40
41
# File 'lib/qingcloud/sdk/general/config.rb', line 37

def initialize(initial_config = {})
  self.connection = Net::HTTP::Persistent.new
  load_default_config
  update initial_config
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



27
28
29
# File 'lib/qingcloud/sdk/general/config.rb', line 27

def connection
  @connection
end

Class Method Details

.init(access_key_id, secret_access_key) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/qingcloud/sdk/general/config.rb', line 29

def self.init(access_key_id, secret_access_key)
  initial_config = {
    qy_access_key_id:     access_key_id,
    qy_secret_access_key: secret_access_key,
  }
  Config.new(initial_config)
end

Instance Method Details

#install_default_user_configObject



63
64
65
66
67
# File 'lib/qingcloud/sdk/general/config.rb', line 63

def install_default_user_config
  Logger.warn "Installing default config file to #{Contract::USER_CONFIG_FILEPATH}"
  FileUtils.mkdir_p Contract::USER_SUPPORT_DIRECTORY
  FileUtils.copy Contract::DEFAULT_CONFIG_FILEPATH, Contract::USER_CONFIG_FILEPATH
end

#load_config_from_file(path) ⇒ Object



58
59
60
61
# File 'lib/qingcloud/sdk/general/config.rb', line 58

def load_config_from_file(path)
  path = path.sub '~', Dir.home if path.start_with? '~/'
  update YAML.load_file File.absolute_path path
end

#load_default_configObject



49
50
51
# File 'lib/qingcloud/sdk/general/config.rb', line 49

def load_default_config
  load_config_from_file Contract::DEFAULT_CONFIG_FILEPATH
end

#load_user_configObject



53
54
55
56
# File 'lib/qingcloud/sdk/general/config.rb', line 53

def load_user_config
  install_default_user_config unless File.exist? Contract::USER_CONFIG_FILEPATH
  load_config_from_file Contract::USER_CONFIG_FILEPATH
end

#update(another_config = {}) ⇒ Object



43
44
45
46
47
# File 'lib/qingcloud/sdk/general/config.rb', line 43

def update(another_config = {})
  deep_merge! another_config.deep_symbolize_keys!
  Logger.set_level self[:log_level]
  self
end