Class: Fog::Aliyun::Storage::Directory

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/aliyun/models/storage/directory.rb

Constant Summary collapse

VALID_ACLS =
['private', 'public-read', 'public-read-write']

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#aclObject

Returns the value of attribute acl.



12
13
14
# File 'lib/fog/aliyun/models/storage/directory.rb', line 12

def acl
  @acl
end

Instance Method Details

#destroyObject



25
26
27
28
29
30
31
32
33
34
35
# 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 = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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

#filesObject



66
67
68
69
70
71
72
73
# 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

#locationObject



54
55
56
57
58
# 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) ⇒ Object

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



61
62
63
64
# 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?Boolean

Returns:

  • (Boolean)


104
105
106
107
108
# 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) ⇒ Object

TODO



76
77
78
# File 'lib/fog/aliyun/models/storage/directory.rb', line 76

def public=(new_public)
  nil
end

#public_urlObject

TODO



81
82
83
# File 'lib/fog/aliyun/models/storage/directory.rb', line 81

def public_url
  nil
end

#saveObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# 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