module Shrine::Plugins::Sequel::AttachmentMethods

  1. lib/shrine/plugins/sequel.rb

Methods

Public Instance

  1. included

Public Instance methods

included (model)
[show source]
# File lib/shrine/plugins/sequel.rb, line 66
        def included(model)
          super

          return unless model < ::Sequel::Model

          opts = shrine_class.opts

          module_eval "            def validate
              super
              #{@name}_attacher.errors.each do |message|
                errors.add(:#{@name}, *message)
              end
            end
", __FILE__, __LINE__ + 1 if opts[:sequel_validations]

          module_eval "            def before_save
              super
              #{@name}_attacher.save if #{@name}_attacher.changed?
            end

            def after_save
              super
              db.after_commit{#{@name}_attacher.finalize} if #{@name}_attacher.changed?
            end

            def after_destroy
              super
              db.after_commit{#{@name}_attacher.destroy} if #{@name}_attacher.read
            end
", __FILE__, __LINE__ + 1 if opts[:sequel_callbacks]
        end