module Shrine::Plugins::ModuleInclude

  1. lib/shrine/plugins/module_include.rb

The module_include plugin allows you to extend Shrine's core classes for the given uploader with modules/methods.

plugin :module_include

To add a module to a core class, call the appropriate method:

attachment_module CustomAttachmentMethods
attacher_module CustomAttacherMethods
file_module CustomFileMethods

Alternatively you can pass in a block (which internally creates a module):

attachment_module do
  def included(model)
    super

    module_eval "      def #{@name}_size(version)
        if #{@name}.is_a?(Hash)
          #{@name}[version].size
        else
          #{@name}.size if #{@name}
        end
      end
", __FILE__, __LINE + 1
  end
end

The above defines an additional #<attachment>_size method on the attachment module, which is what is included in your model.