class Fog::Aliyun::Storage::Directory

Constants

VALID_ACLS

Attributes

acl[R]

Public Instance Methods

acl=(new_acl) click to toggle source
# File lib/fog/aliyun/models/storage/directory.rb, line 17
def acl=(new_acl)
  unless VALID_ACLS.include?(new_acl)
    raise ArgumentError.new("acl must be one of [#{VALID_ACLS.join(', ')}]")
  else
    @acl = new_acl
  end
end
destroy() click to toggle source
# File lib/fog/aliyun/models/storage/directory.rb, line 25
def destroy
  requires :key
  service.delete_bucket(key)
  true
rescue AliyunOssSdk::ServerError => error
  if error.error_code == "NoSuchBucket"
    false
  else
    raise(error)
  end
end
destroy!(options = {}) click to toggle source
# File lib/fog/aliyun/models/storage/directory.rb, line 37
def destroy!(options = {})
  requires :key
  options = {
      timeout: Fog.timeout,
      interval: Fog.interval,
  }.merge(options)

  begin
    clear!
    Fog.wait_for(options[:timeout], options[:interval]) { objects_keys.size == 0 }
    service.delete_bucket(key)
    true
  rescue AliyunOssSdk::ServerError
    false
  end
end
files() click to toggle source
# File lib/fog/aliyun/models/storage/directory.rb, line 66
def files
  @files ||= begin
    Fog::Aliyun::Storage::Files.new(
      directory: self,
      service: service
    )
  end
end
location() click to toggle source
# File lib/fog/aliyun/models/storage/directory.rb, line 54
def location
  region = @aliyun_region_id
  region ||= Storage::DEFAULT_REGION
  @location = (bucket_location || 'oss-' + region)
end
location=(new_location) click to toggle source

NOTE: you can’t change the region once the bucket is created

# File lib/fog/aliyun/models/storage/directory.rb, line 61
def location=(new_location)
  new_location = 'oss-' + new_location unless new_location.start_with?('oss-')
  @location = new_location
end
persisted?() click to toggle source
# File lib/fog/aliyun/models/storage/directory.rb, line 104
def persisted?
  # is_persisted is true in case of directories.get or after #save
  # creation_date is set in case of directories.all
  attributes[:is_persisted] || !!attributes[:creation_date]
end
public=(new_public) click to toggle source

TODO

# File lib/fog/aliyun/models/storage/directory.rb, line 76
def public=(new_public)
  nil
end
public_url() click to toggle source

TODO

# File lib/fog/aliyun/models/storage/directory.rb, line 81
def public_url
  nil
end
save() click to toggle source
# File lib/fog/aliyun/models/storage/directory.rb, line 85
def save
  requires :key

  options = {}

  options['x-oss-acl'] = acl if acl

  # https://help.aliyun.com/document_detail/31959.html
  # if !persisted?
  #   # There is a sdk bug that location can not be set
  #   options[:location] = location
  # end

  service.put_bucket(key, options)
  attributes[:is_persisted] = true

  true
end

Private Instance Methods

bucket_location() click to toggle source
# File lib/fog/aliyun/models/storage/directory.rb, line 112
def bucket_location
  requires :key
  return nil unless persisted?
  service.get_bucket_location(key)
end
clear!() click to toggle source
# File lib/fog/aliyun/models/storage/directory.rb, line 131
def clear!
  requires :key
  service.delete_multiple_objects(key, objects_keys) if objects_keys.size > 0
end
objects_keys() click to toggle source
# File lib/fog/aliyun/models/storage/directory.rb, line 118
def objects_keys
  requires :key
  bucket_query = service.get_bucket(key)

  object_keys = []
  i = 0
  bucket_query[0].each do |o|
    object_keys[i] = o.key
    i += 1
  end
  object_keys
end