module Mongoid::Paperclip::ClassMethods

Public Instance Methods

after_commit(*args, &block) click to toggle source

Adds after_commit

# File lib/mongoid_paperclip.rb, line 68
def after_commit(*args, &block)
  options = args.pop if args.last.is_a? Hash
  if options
    case options[:on]
    when :create
      after_create(*args, &block)
    when :update
      after_update(*args, &block)
    when :destroy
      after_destroy(*args, &block)
    else
      after_save(*args, &block)
    end
  else
    after_save(*args, &block)
  end
end
has_attached_file(field, options = {}) click to toggle source

This method is deprecated

# File lib/mongoid_paperclip.rb, line 116
def has_attached_file(field, options = {})
  raise "Mongoid::Paperclip#has_attached_file is deprecated, " +
        "Use 'has_mongoid_attached_file' instead"
end
has_mongoid_attached_file(field, options = {}) click to toggle source

Adds Mongoid::Paperclip's “#has_mongoid_attached_file” class method to the model which includes Paperclip and Paperclip::Glue in to the model. Additionally it'll also add the required fields for Paperclip since MongoDB is schemaless and doesn't have migrations.

# File lib/mongoid_paperclip.rb, line 91
def has_mongoid_attached_file(field, options = {})

  ##
  # Include Paperclip and Paperclip::Glue for compatibility
  unless self.ancestors.include?(::Paperclip)
    include ::Paperclip
    include ::Paperclip::Glue
  end

  ##
  # Invoke Paperclip's #has_attached_file method and passes in the
  # arguments specified by the user that invoked Mongoid::Paperclip#has_mongoid_attached_file
  has_attached_file(field, options)

  ##
  # Define the necessary collection fields in Mongoid for Paperclip
  field(:"#{field}_file_name",    :type => String)
  field(:"#{field}_content_type", :type => String)
  field(:"#{field}_file_size",    :type => Integer)
  field(:"#{field}_updated_at",   :type => DateTime)
  field(:"#{field}_fingerprint",  :type => String)
end