Module: CarrierWaveDirect::Mongoid

Includes:
Mount
Defined in:
lib/carrierwave_direct/mongoid.rb

Instance Method Summary collapse

Instance Method Details

#mount_uploader(column, uploader = nil, options = {}, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/carrierwave_direct/mongoid.rb', line 14

def mount_uploader(column, uploader=nil, options={}, &block)
  super

  uploader.instance_eval "    include ActiveModel::Conversion\n    extend ActiveModel::Naming\n  RUBY\n\n  include CarrierWaveDirect::Validations::ActiveModel\n\n  validates_is_attached column if uploader_option(column.to_sym, :validate_is_attached)\n  validates_is_uploaded column if uploader_option(column.to_sym, :validate_is_uploaded)\n  validates_filename_uniqueness_of column if uploader_option(column.to_sym, :validate_unique_filename)\n  validates_filename_format_of column if uploader_option(column.to_sym, :validate_filename_format)\n  validates_remote_net_url_format_of column if uploader_option(column.to_sym, :validate_remote_net_url_format)\n\n  self.instance_eval <<-RUBY, __FILE__, __LINE__+1\n    attr_accessor   :skip_is_attached_validations\n    attr_accessible :key, :remote_\#{column}_net_url\n  RUBY\n\n  mod = Module.new\n  include mod\n  mod.class_eval <<-RUBY, __FILE__, __LINE__+1\n    def filename_valid?\n      if has_\#{column}_upload?\n        self.skip_is_attached_validations = true\n        valid?\n        self.skip_is_attached_validations = false\n        column_errors = errors[:\#{column}]\n        errors.clear\n        column_errors.each do |column_error|\n          errors.add(:\#{column}, column_error)\n        end\n        errors.empty?\n      else\n        true\n      end\n    end\n  RUBY\nend\n", __FILE__, __LINE__+1