Class: Backup::Storage::Qiniu
- Inherits:
-
Base
- Object
- Base
- Backup::Storage::Qiniu
- Defined in:
- lib/backup/storage/qiniu.rb
Instance Attribute Summary collapse
-
#access_key ⇒ Object
Returns the value of attribute access_key.
-
#access_secret ⇒ Object
Returns the value of attribute access_secret.
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#path ⇒ Object
Returns the value of attribute path.
-
#upload_token ⇒ Object
Returns the value of attribute upload_token.
Instance Method Summary collapse
-
#initialize(model, storage_id = nil, &block) ⇒ Qiniu
constructor
A new instance of Qiniu.
- #remove!(pkg) ⇒ Object
- #transfer! ⇒ Object
Constructor Details
#initialize(model, storage_id = nil, &block) ⇒ Qiniu
Returns a new instance of Qiniu.
15 16 17 18 19 20 21 |
# File 'lib/backup/storage/qiniu.rb', line 15 def initialize(model, storage_id = nil, &block) super(model, storage_id) @bucket ||= 'backups' instance_eval(&block) if block_given? end |
Instance Attribute Details
#access_key ⇒ Object
Returns the value of attribute access_key.
10 11 12 |
# File 'lib/backup/storage/qiniu.rb', line 10 def access_key @access_key end |
#access_secret ⇒ Object
Returns the value of attribute access_secret.
10 11 12 |
# File 'lib/backup/storage/qiniu.rb', line 10 def access_secret @access_secret end |
#bucket ⇒ Object
Returns the value of attribute bucket.
12 13 14 |
# File 'lib/backup/storage/qiniu.rb', line 12 def bucket @bucket end |
#path ⇒ Object
Returns the value of attribute path.
13 14 15 |
# File 'lib/backup/storage/qiniu.rb', line 13 def path @path end |
#upload_token ⇒ Object
Returns the value of attribute upload_token.
11 12 13 |
# File 'lib/backup/storage/qiniu.rb', line 11 def upload_token @upload_token end |
Instance Method Details
#remove!(pkg) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/backup/storage/qiniu.rb', line 23 def remove!(pkg) remote_path = remote_path_for(pkg) establish_connection! transferred_files_for(pkg) do |local_file, remote_file| Logger.info "#{storage_name} started removing " + "'#{ local_file }' from bucket '#{ bucket }'." key = File.join(remote_path, remote_file) unless ::Qiniu::RS.delete(bucket, key) raise "delete '#{key}' failed" end end end |
#transfer! ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/backup/storage/qiniu.rb', line 36 def transfer! if access_key and access_secret transfer_by_secret! else transfer_by_upload_token! end end |