Class: Fog::Backblaze::Storage::Directory
- Inherits:
-
Model
- Object
- Model
- Fog::Backblaze::Storage::Directory
- Defined in:
- lib/fog/backblaze/storage/models/directory.rb
Instance Method Summary collapse
- #destroy ⇒ Object
- #files ⇒ Object
-
#initialize(attrs) ⇒ Directory
constructor
A new instance of Directory.
- #public=(value) ⇒ Object
- #public? ⇒ Boolean (also: #public)
- #save ⇒ Object
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
#destroy ⇒ Object
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 |
#files ⇒ Object
58 59 60 |
# File 'lib/fog/backblaze/storage/models/directory.rb', line 58 def files @files ||= Fog::Backblaze::Storage::Files.new(directory: self, service: service) end |
#public=(value) ⇒ Object
68 69 70 |
# File 'lib/fog/backblaze/storage/models/directory.rb', line 68 def public=(value) self.bucket_type = value ? 'allPublic' : 'allPrivate' end |
#public? ⇒ Boolean Also known as: public
62 63 64 |
# File 'lib/fog/backblaze/storage/models/directory.rb', line 62 def public? attributes[:bucket_type] == "allPublic" end |
#save ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fog/backblaze/storage/models/directory.rb', line 32 def save requires :key = {} [:bucketInfo] = bucket_info if bucket_info [:bucketType] = bucket_type if bucket_type [:lifecycleRules] = lifecycle_rules if lifecycle_rules [:corsRules] = cors_rules if cors_rules if attributes[:bucket_id] [:bucketId] = attributes[:bucket_id] response = service.update_bucket(key, ) else response = service.put_bucket(key, ) 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 |