Class: QingStor::SDK::Config
- Inherits:
-
Hash
- Object
- Hash
- QingStor::SDK::Config
- Defined in:
- lib/qingstor/sdk/general/config.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
Class Method Summary collapse
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(initial_config = {}) ⇒ Config
constructor
A new instance of Config.
- #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/qingstor/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/qingstor/sdk/general/config.rb', line 27 def connection @connection end |
Class Method Details
Instance Method Details
#check ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/qingstor/sdk/general/config.rb', line 49 def check %i(access_key_id secret_access_key host port protocol).each do |x| if !self[x] || self[x].to_s.empty? raise ConfigurationError, "#{x.to_sym} not specified" end end if self[:additional_user_agent] && !self[:additional_user_agent].empty? self[:additional_user_agent].each_byte do |x| # Allow space(32) to ~(126) in ASCII Table, exclude "(34). if x < 32 || x > 126 || x == 32 || x == 34 raise ConfigurationError, 'additional User-Agent contains characters that not allowed' end end end self end |
#load_config_from_file(path) ⇒ Object
75 76 77 78 |
# File 'lib/qingstor/sdk/general/config.rb', line 75 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
66 67 68 |
# File 'lib/qingstor/sdk/general/config.rb', line 66 def load_default_config load_config_from_file Contract::DEFAULT_CONFIG_FILEPATH end |
#load_user_config ⇒ Object
70 71 72 73 |
# File 'lib/qingstor/sdk/general/config.rb', line 70 def load_user_config install_default_user_config unless File.exist? Contract::USER_CONFIG_FILEPATH load_config_from_file Contract::USER_CONFIG_FILEPATH end |