Module: Paperclip::Storage::Database
- Defined in:
- lib/paperclipdb/storage.rb
Class Method Summary collapse
Instance Method Summary collapse
- #exists?(style = default_style) ⇒ Boolean
- #flush_deletes ⇒ Object
- #flush_writes ⇒ Object
- #getAttachment(file_path) ⇒ Object
- #to_file(style = default_style) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
5 6 7 8 9 |
# File 'lib/paperclipdb/storage.rb', line 5 def self.extended(base) base.instance_eval do base end end |
Instance Method Details
#exists?(style = default_style) ⇒ Boolean
17 18 19 |
# File 'lib/paperclipdb/storage.rb', line 17 def exists?(style = default_style) return getAttachment(path(style)).nil? end |
#flush_deletes ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/paperclipdb/storage.rb', line 51 def flush_deletes @queued_for_delete.each do |path| = getAttachment(path) if (!.nil?) .destroy end end @queued_for_delete = [] end |
#flush_writes ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/paperclipdb/storage.rb', line 38 def flush_writes @queued_for_write.each do |style, file| = Paperclipdb::Attachment.new .base_name = File.basename(path(style)) .dir_name = File.dirname(path(style)) .content_type = self.instance_variable_get("@_#{self.name.to_s}_content_type") .file_size = file.size .file_data = file.read .save end @queued_for_write = {} end |
#getAttachment(file_path) ⇒ Object
21 22 23 |
# File 'lib/paperclipdb/storage.rb', line 21 def getAttachment(file_path) return Paperclipdb::Attachment.find(:first, :conditions => [ "base_name = ? AND dir_name = ?", File.basename(file_path), File.dirname(file_path) ]) end |
#to_file(style = default_style) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/paperclipdb/storage.rb', line 25 def to_file style = default_style if @queued_for_write[style] @queued_for_write[style] elsif exists?(style) = getAttachment(path(style)) tempfile = Tempfile.new .base_name tempfile.write .file_data tempfile else nil end end |