Class: COS::ResourceOperator
- Inherits:
-
Struct::Base
- Object
- Struct::Base
- COS::ResourceOperator
- Defined in:
- lib/cos/resource.rb
Overview
COS资源,文件与目录的共有操作
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
资源类型.
Instance Method Summary collapse
-
#created_at ⇒ Time
创建时间Time类型.
-
#delete ⇒ Object
删除当前资源.
-
#delete! ⇒ Object
删除当前资源, 不会抛出异常而是返回布尔值.
-
#exist? ⇒ Boolean
(also: #exists?)
判断当前资源是否存在.
-
#initialize(attrs) ⇒ ResourceOperator
constructor
A new instance of ResourceOperator.
-
#stat ⇒ COSFile|COSDir
获取(刷新)当前资源的状态.
-
#to_hash ⇒ Hash
参数转化为Hash类型.
-
#update(biz_attr) ⇒ Object
更新当前资源的属性.
-
#updated_at ⇒ Time
更新时间Time类型.
Methods included from Struct::Base::AttrHelper
#optional_attrs, #required_attrs
Constructor Details
#initialize(attrs) ⇒ ResourceOperator
Returns a new instance of ResourceOperator.
94 95 96 |
# File 'lib/cos/resource.rb', line 94 def initialize(attrs) super(attrs) end |
Instance Attribute Details
#type ⇒ Object (readonly)
资源类型
89 90 91 |
# File 'lib/cos/resource.rb', line 89 def type @type end |
Instance Method Details
#created_at ⇒ Time
创建时间Time类型
101 102 103 |
# File 'lib/cos/resource.rb', line 101 def created_at Time.at(ctime.to_i) end |
#delete ⇒ Object
Note:
非空目录及根目录不可删除,会抛出异常
删除当前资源
185 186 187 188 |
# File 'lib/cos/resource.rb', line 185 def delete bucket.delete(path) self end |
#delete! ⇒ Object
Note:
非空目录及根目录不可删除, 返回false
删除当前资源, 不会抛出异常而是返回布尔值
196 197 198 |
# File 'lib/cos/resource.rb', line 196 def delete! bucket.delete!(path) end |
#exist? ⇒ Boolean Also known as: exists?
判断当前资源是否存在
140 141 142 |
# File 'lib/cos/resource.rb', line 140 def exist? bucket.exist?(path) end |
#stat ⇒ COSFile|COSDir
Note:
如查询根目录(‘/’, ”)可以获取到bucket信息, 返回COSDir
获取(刷新)当前资源的状态
156 157 158 |
# File 'lib/cos/resource.rb', line 156 def stat bucket.stat(path) end |
#to_hash ⇒ Hash
参数转化为Hash类型
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/cos/resource.rb', line 115 def to_hash hash = { type: type, bucket: bucket.bucket_name, path: path, name: name, ctime: ctime, mtime: mtime, } optional_attrs.each do |key| hash[key] = send(key.to_s) if respond_to?(key) and send(key.to_s) != nil end hash end |
#update(biz_attr) ⇒ Object
Note:
根目录(‘/’) 不可更新, 否则会抛出异常
更新当前资源的属性
170 171 172 173 174 175 |
# File 'lib/cos/resource.rb', line 170 def update(biz_attr) bucket.update(path, biz_attr) @mtime = Time.now.to_i.to_s @biz_attr = biz_attr self end |
#updated_at ⇒ Time
更新时间Time类型
108 109 110 |
# File 'lib/cos/resource.rb', line 108 def updated_at Time.at(mtime.to_i) end |