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.
93 94 95 |
# File 'lib/cos/resource.rb', line 93 def initialize(attrs) super(attrs) end |
Instance Attribute Details
#type ⇒ Object (readonly)
资源类型
88 89 90 |
# File 'lib/cos/resource.rb', line 88 def type @type end |
Instance Method Details
#created_at ⇒ Time
创建时间Time类型
100 101 102 |
# File 'lib/cos/resource.rb', line 100 def created_at Time.at(ctime.to_i) end |
#delete ⇒ Object
Note:
非空目录及根目录不可删除,会抛出异常
删除当前资源
184 185 186 187 |
# File 'lib/cos/resource.rb', line 184 def delete bucket.delete(path) self end |
#delete! ⇒ Object
Note:
非空目录及根目录不可删除, 返回false
删除当前资源, 不会抛出异常而是返回布尔值
195 196 197 |
# File 'lib/cos/resource.rb', line 195 def delete! bucket.delete!(path) end |
#exist? ⇒ Boolean Also known as: exists?
判断当前资源是否存在
139 140 141 |
# File 'lib/cos/resource.rb', line 139 def exist? bucket.exist?(path) end |
#stat ⇒ COSFile|COSDir
Note:
如查询根目录(‘/’, ”)可以获取到bucket信息, 返回COSDir
获取(刷新)当前资源的状态
155 156 157 |
# File 'lib/cos/resource.rb', line 155 def stat bucket.stat(path) end |
#to_hash ⇒ Hash
参数转化为Hash类型
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/cos/resource.rb', line 114 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:
根目录(‘/’) 不可更新, 否则会抛出异常
更新当前资源的属性
169 170 171 172 173 174 |
# File 'lib/cos/resource.rb', line 169 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类型
107 108 109 |
# File 'lib/cos/resource.rb', line 107 def updated_at Time.at(mtime.to_i) end |