<commit_before>Tori
===

"(\\( ⁰⊖⁰)/)"

Tori is a very very simple file uploader.

Tori dose nothing.

Only file upload to backend store.

You can upload file without alter database.

# Quick start on Rails

Gemfile

```
gem 'tori', require: 'tori/rails'
```

app/models/photo.rb

```ruby
class Photo < ActiveRecord::Base
  tori :image
end
```

app/controllers/photos_controller.rb

```ruby
class PhotosController < ApplicationController
  def new
    @photo = Photo.new
  end

  def create
    Photo.create(photo_params)
    redirect_to root_path
  end

  private

    def photo_params
      params.require(:photo).permit(:image)
    end
end
```

app/views/photos/new.html.slim

```ruby
= form_for @photo, multipart: true |f|
  = f.file_field 'image'
  = f.button 'Upload'
```

You can read file.

```ruby
photo.image.read #=> image bin
photo.image.exist? #=> exist check
photo.image.to_s #=> filename
```

# Custom configure example

```ruby
# Save to S3 bucket.
require 'tori/backend/s3'
Tori.config.backend = Tori::Backend::S3.new(bucket: 'tori_bucket')

# Filename decided by model.class.name,id and hidden words.
Tori.config.filename_callback do |model|
  "#{model.class.name}/#{Digest::SHA1.hexdigest "#{ENV["TORI_MAGICKWORD"]}/#{model.id}"}"
end<commit_msg>Should be use `name` instead of `to_s`<commit_after>Tori
===

"(\\( ⁰⊖⁰)/)"

Tori is a very very simple file uploader.

Tori dose nothing.

Only file upload to backend store.

You can upload file without alter database.

# Quick start on Rails

Gemfile

```
gem 'tori', require: 'tori/rails'
```

app/models/photo.rb

```ruby
class Photo < ActiveRecord::Base
  tori :image
end
```

app/controllers/photos_controller.rb

```ruby
class PhotosController < ApplicationController
  def new
    @photo = Photo.new
  end

  def create
    Photo.create(photo_params)
    redirect_to root_path
  end

  private

    def photo_params
      params.require(:photo).permit(:image)
    end
end
```

app/views/photos/new.html.slim

```ruby
= form_for @photo, multipart: true |f|
  = f.file_field 'image'
  = f.button 'Upload'
```

You can read file.

```ruby
photo.image.read #=> image bin
photo.image.exist? #=> exist check
photo.image.name #=> filename
```

# Custom configure example

```ruby
# Save to S3 bucket.
require 'tori/backend/s3'
Tori.config.backend = Tori::Backend::S3.new(bucket: 'tori_bucket')

# Filename decided by model.class.name,id and hidden words.
Tori.config.filename_callback do |model|
  "#{model.class.name}/#{Digest::SHA1.hexdigest "#{ENV["TORI_MAGICKWORD"]}/#{model.id}"}"
end
{'fraction_non_alphanumeric': 0.1416829745596869, 'fraction_numerical': 0.0031311154598825833, 'mean_word_length': 4.0216110019646365, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '154137', 'n_tokens_mistral': 959, 'n_tokens_neox': 908, 'n_words': 235}