Module: Paperclip::Storage::Swift
- Defined in:
- lib/paperclip/storage/swift.rb
Defined Under Namespace
Classes: FileExists
Class Method Summary collapse
Instance Method Summary collapse
- #copy_to_local_file(style, destination_path) ⇒ Object
- #exists?(style) ⇒ Boolean
- #flush_deletes ⇒ Object
- #flush_writes ⇒ Object
Class Method Details
.extended(base) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/paperclip/storage/swift.rb', line 8 def self.extended(base) base.instance_eval do @swift_credentials = parse_credentials(@options[:swift_credentials] || {}) @swift_options = @options[:swift_options] || {} environment = defined?(Rails) ? Rails.env : @swift_options[:environment].to_s @swift_credentials = (@swift_credentials[environment] || @swift_credentials).symbolize_keys swift_client end end |
Instance Method Details
#copy_to_local_file(style, destination_path) ⇒ Object
41 42 43 44 45 |
# File 'lib/paperclip/storage/swift.rb', line 41 def copy_to_local_file(style, destination_path) local_file = File.open(destination_path, 'wb') local_file.write(swift_client.object(path(style)).data) local_file.close end |
#exists?(style) ⇒ Boolean
18 19 20 |
# File 'lib/paperclip/storage/swift.rb', line 18 def exists?(style) swift_client.object_exists?(path(style)) end |
#flush_deletes ⇒ Object
34 35 36 37 38 39 |
# File 'lib/paperclip/storage/swift.rb', line 34 def flush_deletes @queued_for_delete.each do |path| swift_client.delete_object(path) end @queued_for_delete = [] end |
#flush_writes ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/paperclip/storage/swift.rb', line 22 def flush_writes @queued_for_write.each do |style, file| unless exists?(style) obj = swift_client.create_object(path(style), {:content_type => instance_read(:content_type)}, file) else raise FileExists, "file '#{style}' already exists in Swift" end end after_flush_writes @queued_for_write = {} end |