Class: QingCloud::SDK::Config
- Inherits:
-
Hash
- Object
- Hash
- QingCloud::SDK::Config
- Defined in:
- lib/qingcloud/sdk/general/config.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(initial_config = {}) ⇒ Config
constructor
A new instance of Config.
- #install_default_user_config ⇒ Object
- #load_config_from_file(path) ⇒ Object
- #load_default_config ⇒ Object
- #load_user_config ⇒ Object
- #update(another_config = {}) ⇒ Object
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
#connection ⇒ Object
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
Instance Method Details
#install_default_user_config ⇒ Object
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_config ⇒ Object
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_config ⇒ Object
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 |