Class: S3BackupManager::Bucket
- Inherits:
-
Object
- Object
- S3BackupManager::Bucket
- Defined in:
- lib/models/bucket.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#s3_bucket ⇒ Object
Returns the value of attribute s3_bucket.
Class Method Summary collapse
Instance Method Summary collapse
- #files ⇒ Object
-
#initialize(name) ⇒ Bucket
constructor
A new instance of Bucket.
- #retrieve(filename) ⇒ Object
- #store(filename, data) ⇒ Object
Constructor Details
#initialize(name) ⇒ Bucket
Returns a new instance of Bucket.
12 13 14 |
# File 'lib/models/bucket.rb', line 12 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/models/bucket.rb', line 9 def name @name end |
#s3_bucket ⇒ Object
Returns the value of attribute s3_bucket.
10 11 12 |
# File 'lib/models/bucket.rb', line 10 def s3_bucket @s3_bucket end |
Class Method Details
.create!(name) ⇒ Object
31 32 33 34 35 |
# File 'lib/models/bucket.rb', line 31 def self.create!(name) raise BucketError::NoNameError.new if name.nil? || name.strip == "" connect! AWS::S3::Bucket.create("#{config["collection_prefix"]}_#{name}") end |
.find(id) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/models/bucket.rb', line 21 def self.find(id) connect! bucket = AWS::S3::Bucket.find((id)) initialize_with_bucket(id, bucket) rescue AWS::S3::CurrentBucketNotSpecified raise BucketError::NoNameError rescue AWS::S3::NoSuchBucket raise BucketError::NoBucketFoundError end |
.find_all ⇒ Object
16 17 18 19 |
# File 'lib/models/bucket.rb', line 16 def self.find_all connect! AWS::S3::Service.buckets.select{|b| b.name =~ %r{^#{config["collection_prefix"]}_}}.map{|b| b.name.sub(%r{^#{config["collection_prefix"]}_},"")} end |
Instance Method Details
#files ⇒ Object
45 46 47 |
# File 'lib/models/bucket.rb', line 45 def files @s3_bucket.objects end |
#retrieve(filename) ⇒ Object
41 42 43 |
# File 'lib/models/bucket.rb', line 41 def retrieve(filename) AWS::S3::S3Object.value(filename, bucket_name) end |
#store(filename, data) ⇒ Object
37 38 39 |
# File 'lib/models/bucket.rb', line 37 def store(filename, data) AWS::S3::S3Object.store(filename, data, bucket_name) end |