Class: Fog::Storage::GoogleXML::Directory

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

Instance Method Summary collapse

Instance Method Details

#acl=(new_acl) ⇒ Object


9
10
11
12
13
14
15
# File 'lib/fog/storage/google_xml/models/directory.rb', line 9

def acl=(new_acl)
  valid_acls = ["private", "public-read", "public-read-write", "authenticated-read"]
  unless valid_acls.include?(new_acl)
    raise ArgumentError.new("acl must be one of [#{valid_acls.join(', ')}]")
  end
  @acl = new_acl
end

#destroyObject


17
18
19
20
21
22
23
# File 'lib/fog/storage/google_xml/models/directory.rb', line 17

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

#filesObject


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

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

#public=(new_public) ⇒ Object


34
35
36
37
38
39
40
41
# File 'lib/fog/storage/google_xml/models/directory.rb', line 34

def public=(new_public)
  if new_public
    @acl = "public-read"
  else
    @acl = "private"
  end
  new_public
end

#public_urlObject


43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/storage/google_xml/models/directory.rb', line 43

def public_url
  requires :key
  if service.get_bucket_acl(key).body["AccessControlList"].detect { |entry| entry["Scope"]["type"] == "AllUsers" && entry["Permission"] == "READ" }
    if key.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/
      "https://#{key}.storage.googleapis.com"
    else
      "https://storage.googleapis.com/#{key}"
    end
  end
end

#saveObject


54
55
56
57
58
59
60
61
62
# File 'lib/fog/storage/google_xml/models/directory.rb', line 54

def save
  requires :key
  options = {}
  options["x-goog-acl"] = @acl if @acl
  options["LocationConstraint"] = @location if @location
  options["StorageClass"] = attributes[:storage_class] if attributes[:storage_class]
  service.put_bucket(key, options)
  true
end