Class: Fog::Storage::AWS::Directory

Inherits:
Model
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#aclObject

Returns the value of attribute acl.



11
12
13
# File 'lib/fog/aws/models/storage/directory.rb', line 11

def acl
  @acl
end

Instance Method Details

#destroyObject



26
27
28
29
30
31
32
# File 'lib/fog/aws/models/storage/directory.rb', line 26

def destroy
  requires :key
  service.delete_bucket(key)
  true
rescue Excon::Errors::NotFound
  false
end

#filesObject



43
44
45
# File 'lib/fog/aws/models/storage/directory.rb', line 43

def files
  @files ||= Fog::Storage::AWS::Files.new(:directory => self, :service => service)
end

#locationObject



34
35
36
# File 'lib/fog/aws/models/storage/directory.rb', line 34

def location
  @location ||= (bucket_location || self.service.region)
end

#location=(new_location) ⇒ Object

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



39
40
41
# File 'lib/fog/aws/models/storage/directory.rb', line 39

def location=(new_location)
  @location = new_location
end

#payerObject



47
48
49
50
51
# File 'lib/fog/aws/models/storage/directory.rb', line 47

def payer
  requires :key
  data = service.get_request_payment(key)
  data.body['Payer']
end

#payer=(new_payer) ⇒ Object



53
54
55
56
57
# File 'lib/fog/aws/models/storage/directory.rb', line 53

def payer=(new_payer)
  requires :key
  service.put_request_payment(key, new_payer)
  @payer = new_payer
end

#persisted?Boolean

Returns:

  • (Boolean)


109
110
111
112
113
# File 'lib/fog/aws/models/storage/directory.rb', line 109

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



74
75
76
77
# File 'lib/fog/aws/models/storage/directory.rb', line 74

def public=(new_public)
  self.acl = new_public ? 'public-read' : 'private'
  new_public
end

#public_urlObject



79
80
81
82
83
84
85
86
87
88
# File 'lib/fog/aws/models/storage/directory.rb', line 79

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

#saveObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/fog/aws/models/storage/directory.rb', line 90

def save
  requires :key

  options = {}

  options['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
    options['LocationConstraint'] = location
  end

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

  true
end

#versioning=(new_versioning) ⇒ Object



65
66
67
68
# File 'lib/fog/aws/models/storage/directory.rb', line 65

def versioning=(new_versioning)
  requires :key
  service.put_bucket_versioning(key, new_versioning ? 'Enabled' : 'Suspended')
end

#versioning?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
# File 'lib/fog/aws/models/storage/directory.rb', line 59

def versioning?
  requires :key
  data = service.get_bucket_versioning(key)
  data.body['VersioningConfiguration']['Status'] == 'Enabled'
end

#versionsObject



70
71
72
# File 'lib/fog/aws/models/storage/directory.rb', line 70

def versions
  @versions ||= Fog::Storage::AWS::Versions.new(:directory => self, :service => service)
end