Sha256: 3b9d300ca77cab66b8a917a11a320eb8359481a48f4d8195937283484ff59550

Contents?: true

Size: 1.19 KB

Versions: 75

Compression:

Stored size: 1.19 KB

Contents

module Technoweenie # :nodoc:
  module AttachmentFu # :nodoc:
    module Backends
      # Methods for DB backed attachments
      module DbFileBackend
        def self.included(base) #:nodoc:
          Object.const_set(:DbFile, Class.new(ActiveRecord::Base)) unless Object.const_defined?(:DbFile)
          base.belongs_to  :db_file, :class_name => '::DbFile', :foreign_key => 'db_file_id'
        end

        # Creates a temp file with the current db data.
        def create_temp_file
          write_to_temp_file current_data
        end
        
        # Gets the current data from the database
        def current_data
          db_file.data
        end
        
        protected
          # Destroys the file.  Called in the after_destroy callback
          def destroy_file
            db_file.destroy if db_file
          end
          
          # Saves the data to the DbFile model
          def save_to_storage
            if save_attachment?
              (db_file || build_db_file).data = temp_data
              db_file.save!
              self.class.update_all ['db_file_id = ?', self.db_file_id = db_file.id], ['id = ?', id]
            end
            true
          end
      end
    end
  end
end

Version data entries

75 entries across 75 versions & 18 rubygems

Version Path
artmotion-attachment_fu-0.0.1 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
artmotion-attachment_fu-0.0.2 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
atd-attachment_fu-1.0.20080507 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
atd-attachment_fu-1.0.20081202 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
futuresinc-attachment_fu-1.0.4 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
ioquatix-attachment_fu-1.0.1 lib/attachment_fu/backends/db_file_backend.rb
pager-attachment_fu-1.0.20080506 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
pager-attachment_fu-1.0.20080507 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
popel-attachment_fu-1.0.4 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
seamusabshere-attachment_fu-1.1 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
tdd-attachment_fu-0.9.6 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
tdd-attachment_fu-0.9.9 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
winton-attachment_fu-1.0.5 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
pothoven-attachment_fu-3.2.13 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
pothoven-attachment_fu-3.2.12 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
pothoven-attachment_fu-3.2.11 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
pothoven-attachment_fu-3.2.10 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
pothoven-attachment_fu-3.2.9 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
pothoven-attachment_fu-3.2.8 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
pothoven-attachment_fu-3.2.7 lib/technoweenie/attachment_fu/backends/db_file_backend.rb