Sha256: 8d286271189fd4d6dd60f51050036139930df6d696a9ec1031754577e2568445

Contents?: true

Size: 1.21 KB

Versions: 13

Compression:

Stored size: 1.21 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.db_file_id = db_file.id
              self.class.where(:id => id).update_all(:db_file_id => db_file.id)
            end
            true
          end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
ss-attachment_fu-3.4.4 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
ss-attachment_fu-3.4.3 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
pothoven-attachment_fu-3.2.17 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
ss-attachment_fu-3.4.2 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
ss-attachment_fu-3.4.1 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
ss-attachment_fu-3.4.0 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
ss-attachment_fu-3.3.0 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
pothoven-attachment_fu-3.2.16 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
ss-attachment_fu-3.2.19 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
ss-attachment_fu-3.2.18 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
ss-attachment_fu-3.2.17 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
pothoven-attachment_fu-3.2.15 lib/technoweenie/attachment_fu/backends/db_file_backend.rb
pothoven-attachment_fu-3.2.14 lib/technoweenie/attachment_fu/backends/db_file_backend.rb