Class: Fog::Storage::Google::Directory

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

Instance Attribute Summary

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Model

#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#acl=(new_acl) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/fog/google/models/storage/directory.rb', line 14

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



22
23
24
25
26
27
28
# File 'lib/fog/google/models/storage/directory.rb', line 22

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

#filesObject



30
31
32
33
34
35
36
37
# File 'lib/fog/google/models/storage/directory.rb', line 30

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

#public=(new_public) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/fog/google/models/storage/directory.rb', line 39

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

#public_urlObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fog/google/models/storage/directory.rb', line 48

def public_url
  requires :key
  if connection.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}.commondatastorage.googleapis.com"
    else
      "https://commondatastorage.googleapis.com/#{key}"
    end
  else
    nil
  end
end

#saveObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fog/google/models/storage/directory.rb', line 61

def save
  requires :key
  options = {}
  if @acl
    options['x-goog-acl'] = @acl
  end
  if @location
    options['LocationConstraint'] = @location
  end
  connection.put_bucket(key, options)
  true
end