Giter VIP home page Giter VIP logo

hanami-shrine's Introduction

Hanami::Shrine

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.

Build Status Gem Version Code Climate

Current compatibility status

0.1.x

  • works with Hanami 0.7.x
  • works with Hanami 0.8.x without validations (which have been extracted to separate gem)

0.2.x

  • works with Hanami 0.9.x and 1.0.

Future compatibility will only be provided with Hanami 1.0 and later (which will propably be compatible with 0.9 too).

Installation

Add this line to your application's Gemfile:

gem 'hanami-shrine'

And then execute:

$ bundle

Usage

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 avatar):

prepend ImageAttachment.repository(:avatar)

And in your entity:

include ImageAttachment[:avatar]

For inspiration read a blog post, look at the specs or example repo.

Important changes since 0.1 version

As Hanami has been upgraded to 0.9, it started to use new engine for the entities in hanami-model. It required heavy changes in hanami-shrine to accomodate to new paradigm. Unfortunately, some of them are breaking. Here's a summary list:

  • Validations are gone (for now, hopefully)
  • You need to use prepend instead of extend in your repository
  • Entities are now read-only. You need to initialize them with the attachment, not add it later: MyEntity.new(avatar: File.open('my_avatar.png'). This is a Hanami change, but it's worth mentioning here as well.

Development

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.

Testing

Testing is done against 3 major database engines: PostgreSQL, MySQL and sqlite3. It is steered by environment variable DB. To run locally, forst cp .env.travis .env, then put values matching your local configuration there. After that, you can test all three versions:

DB=sqlite bundle exec rake
DB=postgres bundle exec rake
DB=mysql bundle exec rake

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/katafrakt/hanami-shrine.

License

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.

hanami-shrine's People

Contributors

famano avatar janko avatar katafrakt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.