Sha256: 38f86027edec0227541fa79bea3e22187fb477d3530bc938fe0bae2074f27298

Contents?: true

Size: 906 Bytes

Versions: 6

Compression:

Stored size: 906 Bytes

Contents

# encoding: utf-8
require 'mongomapper'

module CarrierWave
  module MongoMapper
    include CarrierWave::Mount
    ##
    # See +CarrierWave::Mount#mount_uploader+ for documentation
    #
    def mount_uploader(column, uploader, options={}, &block)
      # We need to set the mount_on column (or key in MongoMapper's case)
      # since MongoMapper will attempt to set the filename on 
      # the uploader instead of the file on a Document's initialization.
      options[:mount_on] ||= "#{column}_filename"
      key options[:mount_on]
      
      super
      alias_method :read_uploader, :[]
      alias_method :write_uploader, :[]=
      after_save "store_#{column}!".to_sym
      before_save "write_#{column}_identifier".to_sym
      after_destroy "remove_#{column}!".to_sym
    end
  end # MongoMapper
end # CarrierWave

MongoMapper::Document::ClassMethods.send(:include, CarrierWave::MongoMapper)

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
durran-carrierwave-0.3.2.3 lib/carrierwave/orm/mongomapper.rb
jnicklas-carrierwave-0.3.3 lib/carrierwave/orm/mongomapper.rb
carrierwave-0.3.5.1 lib/carrierwave/orm/mongomapper.rb
carrierwave-0.3.5 lib/carrierwave/orm/mongomapper.rb
carrierwave-0.3.4 lib/carrierwave/orm/mongomapper.rb
carrierwave-0.3.3 lib/carrierwave/orm/mongomapper.rb