Shrine

Shrine

  • Guides
  • Plugins
  • External
  • Discourse
  • GitHub
  • Wiki

›Other

Attachment

  • Active Record
  • Column
  • Entity
  • Model
  • Sequel

Flow

  • Backgrounding
  • Presign Endpoint
  • Upload Endpoint

Processing

  • Derivation Endpoint
  • Derivatives

Source

  • Data URI
  • Rack File
  • Remote URL

Validation

  • Remove Invalid
  • Validation
  • Validation Helpers

Metadata

  • Add Metadata
  • Determine MIME Type
  • Infer Extension
  • Metadata Attributes
  • Refresh Metadata
  • Restore Cached Data
  • Signature
  • Store Dimensions
  • Type Predicates

Downloading

  • Download Endpoint
  • Rack Response
  • Tempfile

Form

  • Cached Attachment Data
  • Form Assign
  • Remove Attachment

Settings

  • Default Storage
  • Default URL
  • Dynamic Storage
  • Multi Cache
  • Pretty Location
  • Upload Options
  • URL Options

Other

  • Atomic Helpers
  • Included
  • Instrumentation
  • Keep Files
  • Mirroring
Edit

Included

The included plugin allows you to hook up to the .included hook of the attachment module, and call additional methods on the model that includes it.

class ImageUploader < Shrine
  plugin :included do |name|
    # called when attachment module is included into a model 
 
    self #=> Photo (the model class) 
    name #=> :image 
  end
end
class Photo
  include ImageUploader::Attachment(:image) # triggers the included block 
end

For example, you can use it to define additional methods on the model:

class ImageUploader < Shrine
  plugin :included do |name|
    define_method(:"#{name}_width")  { send(name)&.width  }
    define_method(:"#{name}_height") { send(name)&.height }
  end
end
photo = Photo.new(image: file)
photo.image_width  #=> 1200 
photo.image_height #=> 800 
← Atomic HelpersInstrumentation →
Shrine
Docs
GuidesPluginsExternalContributing
Community
DiscourseStack Overflow
More
BlogGitHubStar
Follow @shrine_rb
Copyright © 2022 Janko Marohnić