Sha256: 0c47cac3150c1f5b4ae75dce3866354cfa2b3169855f57768e4388d61498e6b2

Contents?: true

Size: 1.25 KB

Versions: 10

Compression:

Stored size: 1.25 KB

Contents

# encoding: utf-8

require 'active_record'
require 'carrierwave/validations/active_model'

module CarrierWave
  module ActiveRecord

    include CarrierWave::Mount

    ##
    # See +CarrierWave::Mount#mount_uploader+ for documentation
    #
    def mount_uploader(column, uploader=nil, options={}, &block)
      super

      alias_method :read_uploader, :read_attribute
      alias_method :write_uploader, :write_attribute
      public :read_uploader
      public :write_uploader

      include CarrierWave::Validations::ActiveModel

      validates_integrity_of column if uploader_option(column.to_sym, :validate_integrity)
      validates_processing_of column if uploader_option(column.to_sym, :validate_processing)

      after_save :"store_#{column}!"
      before_save :"write_#{column}_identifier"
      after_destroy :"remove_#{column}!"
      before_update :"store_previous_model_for_#{column}"
      after_save :"remove_previously_stored_#{column}"

      class_eval <<-RUBY, __FILE__, __LINE__+1
        def #{column}=(new_file)
          column = _mounter(:#{column}).serialization_column
          send(:"\#{column}_will_change!")
          super
        end
      RUBY

    end

  end # ActiveRecord
end # CarrierWave

ActiveRecord::Base.extend CarrierWave::ActiveRecord

Version data entries

10 entries across 10 versions & 4 rubygems

Version Path
carrierwave-pressplane-0.5.8.3 lib/carrierwave/orm/activerecord.rb
carrierwave-0.5.8 lib/carrierwave/orm/activerecord.rb
carrierwave-0.5.7 lib/carrierwave/orm/activerecord.rb
potatosalad-carrierwave-0.5.7.1 lib/carrierwave/orm/activerecord.rb
potatosalad-carrierwave-0.5.7 lib/carrierwave/orm/activerecord.rb
carrierwave-0.5.6 lib/carrierwave/orm/activerecord.rb
carrierwave-0.5.5 lib/carrierwave/orm/activerecord.rb
locomotive_carrierwave-0.5.4.beta3 lib/carrierwave/orm/activerecord.rb
locomotive_carrierwave-0.5.4.beta2 lib/carrierwave/orm/activerecord.rb
locomotive_carrierwave-0.5.4.beta1 lib/carrierwave/orm/activerecord.rb