class COS::ResourceOperator
COS资源,文件与目录的共有操作
Attributes
type[R]
资源类型
Public Class Methods
new(attrs)
click to toggle source
Calls superclass method
# File lib/cos/resource.rb, line 94 def initialize(attrs) super(attrs) end
Public Instance Methods
created_at()
click to toggle source
创建时间Time类型
@return [Time]
# File lib/cos/resource.rb, line 101 def created_at Time.at(ctime.to_i) end
delete()
click to toggle source
删除当前资源
@note 非空目录及根目录不可删除,会抛出异常
@raise [ServerError] 服务端异常返回
@example
resource.delete
# File lib/cos/resource.rb, line 185 def delete bucket.delete(path) self end
delete!()
click to toggle source
删除当前资源, 不会抛出异常而是返回布尔值
@note 非空目录及根目录不可删除, 返回false
@example
puts resource.delete!
# File lib/cos/resource.rb, line 196 def delete! bucket.delete!(path) end
exist?()
click to toggle source
判断当前资源是否存在
@raise [ServerError] 服务端异常返回
@return [Boolean] 是否存在
@example
puts resource.exist?
# File lib/cos/resource.rb, line 140 def exist? bucket.exist?(path) end
Also aliased as: exists?
stat()
click to toggle source
获取(刷新)当前资源的状态
@note 如查询根目录(‘/’, ”)可以获取到bucket信息, 返回COSDir
@raise [ServerError] 服务端异常返回
@return [COSFile|COSDir] 如果是目录则返回COSDir资源对象,是文件则返回COSFile资源对象
@example
puts resource.stat.name
# File lib/cos/resource.rb, line 156 def stat bucket.stat(path) end
to_hash()
click to toggle source
参数转化为Hash类型
@return [Hash]
# 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)
click to toggle source
更新当前资源的属性
@note 根目录(‘/’) 不可更新, 否则会抛出异常
@param biz_attr [String] 目录/文件属性,业务端维护
@raise [ServerError] 服务端异常返回
@example
resource.update('i am the attr')
# 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()
click to toggle source
更新时间Time类型
@return [Time]
# File lib/cos/resource.rb, line 108 def updated_at Time.at(mtime.to_i) end