This gem aims at providing support for Shrine uploader in Hanami applications. It also tries to be as simple as possible, without polluting the world around.
Add this line to your application's Gemfile:
And then execute:
Setup Shrine with
hanami plugin enabled. Check Shrine's repository for more detailed description of the process.
class ImageAttachment < Shrine plugin :hanami end
Then, in your repository add (assuming your attachment is
And in your entity:
To use validations, enable them during setup of the plugin:
class ImageAttachment < Shrine plugin :hanami, validations: true end
And you can write some validation code. For example:
class ImageAttachment < Shrine plugin :validation_helpers plugin :determine_mime_type plugin :hanami, validations: true Attacher.validate do validate_max_size 180_000, message: "is too large (max is 2 MB)" validate_mime_type_inclusion ["image/jpg", "image/jpeg"] end end
Remember that you have to call
validate yourself. There is not as much magic in Hanami as it is in Rails :wink:
For inspiration look at the specs or example repo.
After checking out the repo, run
bin/setup to install dependencies. Then, run
rake spec to run the tests. You can also run
bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run
bundle exec rake install. To release a new version, update the version number in
version.rb, and then run
bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the
.gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/katafrakt/hanami-shrine.
The gem is available as open source under the terms of the MIT License.
Cat images (used in tests) are public domain taken from Wikimedia Commons.