Mongoid integration for Shrine
Ruby
Clone or download
janko-m Update links to Shrine gems
Shrine gems have been moved to the "shrinerb" organization.
Latest commit 3791402 Mar 11, 2018
Permalink
Failed to load latest commit information.
lib/shrine/plugins
test
.gitignore
CODE_OF_CONDUCT.md
Gemfile
LICENSE.txt
README.md
Rakefile
shrine-mongoid.gemspec

README.md

Shrine::Plugins::Mongoid

Provides Mongoid integration for Shrine.

Installation

gem "shrine-mongoid"

Usage

Shrine.plugin :mongoid
class Post
  include Mongoid::Document
  include ImageUploader::Attachment.new(:image)

  field :image_data, type: String # or `type: Hash`
end

This plugin will add validations and callbacks:

post = Post.new
post.image = file
post.image.storage_key #=> "cache"
post.save
post.image.storage_key #=> "store"
post.destroy
post.image.exists?     #=> false

If for some reason you don't want callbacks and/or validations, you can turn them off:

plugin :mongoid, callbacks: false, validations: false

Contributing

You can run the tests with the Rake task:

$ bundle exec rake test

License

MIT