module Shrine::Plugins::Mongoid::AttachmentMethods
Public Instance Methods
included(model)
click to toggle source
Calls superclass method
# File lib/shrine/plugins/mongoid.rb, line 19 def included(model) super return unless model < ::Mongoid::Document name = @name if shrine_class.opts[:mongoid][:validations] # add validation plugin integration model.validate do send(:"#{name}_attacher").send(:mongoid_validate) end end if shrine_class.opts[:mongoid][:callbacks] model.before_save do send(:"#{name}_attacher").send(:mongoid_before_save) end model.after_save do send(:"#{name}_attacher").send(:mongoid_after_save) end model.after_destroy do send(:"#{name}_attacher").send(:mongoid_after_destroy) end end define_method :reload do |*args| result = super(*args) instance_variable_set(:"@#{name}_attacher", nil) result end end