Module: Mongoid::Paperclip::ClassMethods
- Defined in:
- lib/mongoid_paperclip.rb
Instance Method Summary collapse
-
#after_commit(*args, &block) ⇒ Object
Adds after_commit.
-
#has_attached_file(field, options = {}) ⇒ Object
This method is deprecated.
-
#has_mongoid_attached_file(field, options = {}) ⇒ Object
Adds Mongoid::Paperclip’s “#has_mongoid_attached_file” class method to the model which includes Paperclip and Paperclip::Glue in to the model.
Instance Method Details
#after_commit(*args, &block) ⇒ Object
Adds after_commit
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mongoid_paperclip.rb', line 68 def after_commit(*args, &block) = args.pop if args.last.is_a? Hash if case [: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 = {}) ⇒ Object
This method is deprecated
117 118 119 120 |
# File 'lib/mongoid_paperclip.rb', line 117 def has_attached_file(field, = {}) raise "Mongoid::Paperclip#has_attached_file is deprecated, " + "Use 'has_mongoid_attached_file' instead" end |
#has_mongoid_attached_file(field, options = {}) ⇒ Object
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.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/mongoid_paperclip.rb', line 91 def has_mongoid_attached_file(field, = {}) disable_fingerprint = .delete(:disable_fingerprint) ## # 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, ) ## # 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) unless disable_fingerprint end |