Class: Fog::AWS::Storage::Directory
- Inherits:
-
Model
- Object
- Model
- Fog::AWS::Storage::Directory
- Defined in:
- lib/fog/aws/models/storage/directory.rb
Constant Summary collapse
- VALID_ACLS =
['private', 'public-read', 'public-read-write', 'authenticated-read']
Instance Attribute Summary collapse
-
#acl ⇒ Object
Returns the value of attribute acl.
Instance Method Summary collapse
- #destroy ⇒ Object
- #destroy!(options = {}) ⇒ Object
- #files ⇒ Object
- #location ⇒ Object
-
#location=(new_location) ⇒ Object
NOTE: you can’t change the region once the bucket is created.
- #payer ⇒ Object
- #payer=(new_payer) ⇒ Object
- #persisted? ⇒ Boolean
- #public=(new_public) ⇒ Object
- #public_url ⇒ Object
- #save ⇒ Object
- #versioning=(new_versioning) ⇒ Object
- #versioning? ⇒ Boolean
- #versions ⇒ Object
Instance Attribute Details
#acl ⇒ Object
Returns the value of attribute acl.
10 11 12 |
# File 'lib/fog/aws/models/storage/directory.rb', line 10 def acl @acl end |
Instance Method Details
#destroy ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/fog/aws/models/storage/directory.rb', line 24 def destroy requires :key service.delete_bucket(key) true rescue Excon::Errors::NotFound false end |
#destroy!(options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fog/aws/models/storage/directory.rb', line 38 def destroy!( = {}) requires :key = { timeout: Fog.timeout, interval: Fog.interval, }.merge() attempts = 0 begin clear! Fog.wait_for([:timeout], [:interval]) { objects_keys.size == 0 } service.delete_bucket(key) true rescue Excon::Errors::HTTPStatusError false end end |
#files ⇒ Object
65 66 67 |
# File 'lib/fog/aws/models/storage/directory.rb', line 65 def files @files ||= Fog::AWS::Storage::Files.new(:directory => self, :service => service) end |
#location ⇒ Object
56 57 58 |
# File 'lib/fog/aws/models/storage/directory.rb', line 56 def location @location ||= (bucket_location || Storage::DEFAULT_REGION) end |
#location=(new_location) ⇒ Object
NOTE: you can’t change the region once the bucket is created
61 62 63 |
# File 'lib/fog/aws/models/storage/directory.rb', line 61 def location=(new_location) @location = new_location end |
#payer ⇒ Object
69 70 71 72 73 |
# File 'lib/fog/aws/models/storage/directory.rb', line 69 def payer requires :key data = service.get_request_payment(key) data.body['Payer'] end |
#payer=(new_payer) ⇒ Object
75 76 77 78 79 |
# File 'lib/fog/aws/models/storage/directory.rb', line 75 def payer=(new_payer) requires :key service.put_request_payment(key, new_payer) @payer = new_payer end |
#persisted? ⇒ Boolean
131 132 133 134 135 |
# File 'lib/fog/aws/models/storage/directory.rb', line 131 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
96 97 98 99 |
# File 'lib/fog/aws/models/storage/directory.rb', line 96 def public=(new_public) self.acl = new_public ? 'public-read' : 'private' new_public end |
#public_url ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/fog/aws/models/storage/directory.rb', line 101 def public_url requires :key if service.get_bucket_acl(key).body['AccessControlList'].find {|grant| grant['Grantee']['URI'] == 'http://acs.amazonaws.com/groups/global/AllUsers' && grant['Permission'] == 'READ'} service.request_url( :bucket_name => key ) else nil end end |
#save ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/fog/aws/models/storage/directory.rb', line 112 def save requires :key = {} ['x-amz-acl'] = acl if acl # http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUT.html # Ignore the default region us-east-1 if !persisted? && location != DEFAULT_REGION ['LocationConstraint'] = location end service.put_bucket(key, ) attributes[:is_persisted] = true true end |
#versioning=(new_versioning) ⇒ Object
87 88 89 90 |
# File 'lib/fog/aws/models/storage/directory.rb', line 87 def versioning=(new_versioning) requires :key service.put_bucket_versioning(key, new_versioning ? 'Enabled' : 'Suspended') end |
#versioning? ⇒ Boolean
81 82 83 84 85 |
# File 'lib/fog/aws/models/storage/directory.rb', line 81 def versioning? requires :key data = service.get_bucket_versioning(key) data.body['VersioningConfiguration']['Status'] == 'Enabled' end |