Class: Fog::Backblaze::Storage::Directory

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

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Directory

Returns a new instance of Directory.


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

def initialize(attrs)
  attrs = attrs.dup
  attrs['bucket_id']       = attrs['bucketId']
  attrs['bucket_info']     = attrs['bucketInfo']
  attrs['bucket_type']     = attrs['bucketType']
  attrs['cors_rules']      = attrs['corsRules']
  attrs['lifecycle_rules'] = attrs['lifecycleRules']

  super(attrs)
end

Instance Method Details

#destroyObject


24
25
26
27
28
29
30
# File 'lib/fog/backblaze/storage/models/directory.rb', line 24

def destroy
  requires :key
  response = service.delete_bucket(key)
  return response.status < 400
#rescue Fog::Errors::NotFound
#  false
end

#destroy_recursiveObject


32
33
34
35
# File 'lib/fog/backblaze/storage/models/directory.rb', line 32

def destroy_recursive
  files.each(&:destroy)
  destroy
end

#filesObject


63
64
65
# File 'lib/fog/backblaze/storage/models/directory.rb', line 63

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

#public=(value) ⇒ Object


73
74
75
# File 'lib/fog/backblaze/storage/models/directory.rb', line 73

def public=(value)
  self.bucket_type = value ? 'allPublic' : 'allPrivate'
end

#public?Boolean Also known as: public

Returns:

  • (Boolean)

67
68
69
# File 'lib/fog/backblaze/storage/models/directory.rb', line 67

def public?
  attributes[:bucket_type] == "allPublic"
end

#saveObject


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fog/backblaze/storage/models/directory.rb', line 37

def save
  requires :key
  options = {}

  options[:bucketInfo]     = bucket_info     if bucket_info
  options[:bucketType]     = bucket_type     if bucket_type
  options[:lifecycleRules] = lifecycle_rules if lifecycle_rules
  options[:corsRules]      = cors_rules      if cors_rules

  if attributes[:bucket_id]
    options[:bucketId] = attributes[:bucket_id]
    response = service.update_bucket(key, options)
  else
    response = service.put_bucket(key, options)
  end

  attributes[:bucket_id] = response.json['bucketId']
  attributes[:bucket_type] = response.json['bucketType']
  attributes[:bucket_info] = response.json['bucketInfo']
  attributes[:revision] = response.json['revision']
  attributes[:lifecycle_rules] = response.json['lifecycleRules']
  attributes[:cors_rules] = response.json['corsRules']

  true
end