Class: COS::Config
- Inherits:
-
Struct::Base
- Object
- Struct::Base
- COS::Config
- Defined in:
- lib/cos/config.rb
Constant Summary collapse
- DEFAULT_HOST =
默认服务HOST
'web.file.myqcloud.com'
- DEFAULT_MULTIPLE_SIGN_EXPIRE =
默认多次签名过期时间(单位秒)
600
Instance Attribute Summary collapse
-
#api_base ⇒ Object
readonly
Returns the value of attribute api_base.
Instance Method Summary collapse
-
#get_bucket(custom_bucket) ⇒ String
获取指定的bucket或从config中获取默认bucket.
-
#initialize(options = {}) ⇒ COS::Config
constructor
初始化.
Methods included from Struct::Base::AttrHelper
#optional_attrs, #required_attrs
Constructor Details
#initialize(options = {}) ⇒ COS::Config
初始化
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cos/config.rb', line 48 def initialize( = {}) # 从配置文件加载配置 if [:config] config = load_config_file([:config]) .merge!(config) end super() # log_src: STDOUT | STDERR | 'path/filename.log' # log_level: Logger::DEBUG | Logger::INFO | Logger::ERROR | Logger::FATAL if [:log_src] Logging.set_logger( [:log_src], [:log_level] || Logger::INFO ) end @protocol ||= 'http' @host ||= DEFAULT_HOST @api_base = "#{@protocol}://#{@host}/files/v1" @multiple_sign_expire ||= DEFAULT_MULTIPLE_SIGN_EXPIRE end |
Instance Attribute Details
#api_base ⇒ Object (readonly)
Returns the value of attribute api_base.
22 23 24 |
# File 'lib/cos/config.rb', line 22 def api_base @api_base end |
Instance Method Details
#get_bucket(custom_bucket) ⇒ String
获取指定的bucket或从config中获取默认bucket
79 80 81 82 83 84 85 |
# File 'lib/cos/config.rb', line 79 def get_bucket(custom_bucket) b = custom_bucket || default_bucket if b == nil raise ClientError, 'Bucket name must be set' end b end |