Sha256: 26199d297836623953d646e90affbf91cb8b96303ba96e5d07f93b0a926c7dee

Contents?: true

Size: 1.17 KB

Versions: 68

Compression:

Stored size: 1.17 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

68 entries across 68 versions & 2 rubygems

Version Path
refinerycms-0.9.7.15 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.7.14 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.7.13 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.7.11 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.7.10 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.7.9 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.7.8 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.7.7 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.7.6 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.7.5 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.7.4 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.7.3 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.7.2 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.7.1 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.7 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
jacobat-refinerycms-0.9.6.14 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.6.34 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.6.33 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.6.32 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb
refinerycms-0.9.6.31 vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb