file_hutch 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +4 -4
- data/lib/file_hutch/rails/attachable.rb +9 -3
- data/lib/file_hutch/rails/engine.rb +4 -0
- data/lib/file_hutch/rails.rb +5 -0
- data/lib/file_hutch/version.rb +1 -1
- data/lib/generators/file_hutch/attachment/attachment_generator.rb +2 -2
- data/lib/generators/file_hutch/install/install_generator.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 68acbe5c06713d98ad400877d375ccd63794b11ebe6e381aec9aea714061a0d6
|
|
4
|
+
data.tar.gz: a9d3896f4d665648edce1641453a92abb12168802a67feae0f8c6d015d1d5fb5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1ee3d96af2b6ab2b37d37036b466c4b6ed27ea40db2458c175e49723542464f595830786f228a02162cd65706c46dfac50429aa14213e080ceca1b3d2f78b0da
|
|
7
|
+
data.tar.gz: 670315688e96fc2170634e086ab5c21871cfe38e516d8aef6a3b1b5212cc64e88088e7bb9d4846f2bca77b4eb1d82a3106929c372335235c5a3489e572450b8f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -161,8 +161,8 @@ bin/rails generate file_hutch:attachment User avatar # adds users.avatar_file
|
|
|
161
161
|
|
|
162
162
|
```ruby
|
|
163
163
|
class User < ApplicationRecord
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
has_hutch :avatar, policy: "avatars"
|
|
165
|
+
has_hutch :contract, policy: "documents", dependent: false
|
|
166
166
|
end
|
|
167
167
|
|
|
168
168
|
user.avatar = params[:avatar] # uploaded IO → uploaded to storage on save
|
|
@@ -227,14 +227,14 @@ Submit buttons are disabled while uploading. The element dispatches `filehutch:s
|
|
|
227
227
|
`filehutch:progress`, `filehutch:complete`, and `filehutch:error`. `directUpload(file, { url,
|
|
228
228
|
policy, onProgress })` is exported for use without Stimulus.
|
|
229
229
|
|
|
230
|
-
On save, `
|
|
230
|
+
On save, `has_hutch` verifies the submitted id is a ready file under the declared policy,
|
|
231
231
|
so a client cannot attach someone else's upload to the wrong field.
|
|
232
232
|
|
|
233
233
|
### Coming from Active Storage
|
|
234
234
|
|
|
235
235
|
| Active Storage | file_hutch |
|
|
236
236
|
| --- | --- |
|
|
237
|
-
| `has_one_attached :avatar` | `
|
|
237
|
+
| `has_one_attached :avatar` | `has_hutch :avatar, policy: "avatars"` |
|
|
238
238
|
| `active_storage_blobs` + `attachments` tables | `users.avatar_file_id` |
|
|
239
239
|
| `url_for(user.avatar)` | `user.avatar_url` / `user.avatar_signed_url` |
|
|
240
240
|
| `user.avatar.variant(resize_to_fill: [200, 200])` | `user.avatar_transform_url("avatar")`, defined once in the dashboard |
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
require "active_support/concern"
|
|
4
4
|
|
|
5
5
|
module FileHutch
|
|
6
|
-
# `
|
|
6
|
+
# `has_hutch` for Active Record. The model stores one string column,
|
|
7
7
|
# `<name>_file_id`, holding an FileHutch file id. Nothing about storage leaks in.
|
|
8
8
|
#
|
|
9
9
|
# class User < ApplicationRecord
|
|
10
|
-
#
|
|
10
|
+
# has_hutch :avatar, policy: "avatars"
|
|
11
11
|
# end
|
|
12
12
|
#
|
|
13
13
|
# user.avatar = params[:avatar] # uploaded IO: uploaded to storage on save
|
|
@@ -25,7 +25,7 @@ module FileHutch
|
|
|
25
25
|
extend ActiveSupport::Concern
|
|
26
26
|
|
|
27
27
|
class_methods do
|
|
28
|
-
def
|
|
28
|
+
def has_hutch(name, policy:, column: "#{name}_file_id", dependent: :delete, verify: true)
|
|
29
29
|
include Attachable unless include?(Attachable)
|
|
30
30
|
name = name.to_sym
|
|
31
31
|
column = column.to_s
|
|
@@ -45,6 +45,12 @@ module FileHutch
|
|
|
45
45
|
define_method(:"purge_#{name}") { file_hutch_purge(name) }
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
# The 0.1.0 name. Kept for one release so upgrading doesn't break a model.
|
|
49
|
+
def has_file_hutch_file(name, **options)
|
|
50
|
+
FileHutch.deprecator.warn("has_file_hutch_file is deprecated and will be removed in file_hutch 0.3. Use has_hutch :#{name} with the same options.")
|
|
51
|
+
has_hutch(name, **options)
|
|
52
|
+
end
|
|
53
|
+
|
|
48
54
|
def file_hutch_files
|
|
49
55
|
@file_hutch_files ||= superclass.respond_to?(:file_hutch_files) ? superclass.file_hutch_files.dup : {}
|
|
50
56
|
end
|
|
@@ -13,6 +13,10 @@ module FileHutch
|
|
|
13
13
|
class Engine < ::Rails::Engine
|
|
14
14
|
isolate_namespace FileHutch
|
|
15
15
|
|
|
16
|
+
initializer "file_hutch.deprecator" do |app|
|
|
17
|
+
app.deprecators[:file_hutch] = FileHutch.deprecator if app.respond_to?(:deprecators)
|
|
18
|
+
end
|
|
19
|
+
|
|
16
20
|
initializer "file_hutch.active_record" do
|
|
17
21
|
ActiveSupport.on_load(:active_record) { extend FileHutch::Attachable::ClassMethods }
|
|
18
22
|
end
|
data/lib/file_hutch/rails.rb
CHANGED
data/lib/file_hutch/version.rb
CHANGED
|
@@ -6,7 +6,7 @@ require "rails/generators/active_record"
|
|
|
6
6
|
module FileHutch
|
|
7
7
|
module Generators
|
|
8
8
|
# bin/rails generate file_hutch:attachment User avatar
|
|
9
|
-
# Adds users.avatar_file_id (string). Pair with `
|
|
9
|
+
# Adds users.avatar_file_id (string). Pair with `has_hutch :avatar, policy: "…"`.
|
|
10
10
|
class AttachmentGenerator < ::Rails::Generators::NamedBase
|
|
11
11
|
include ::ActiveRecord::Generators::Migration
|
|
12
12
|
|
|
@@ -18,7 +18,7 @@ module FileHutch
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def show_macro
|
|
21
|
-
say %(Add to #{class_name}:
|
|
21
|
+
say %(Add to #{class_name}: has_hutch :#{attachment}, policy: "#{attachment.pluralize}"), :green
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
private
|
|
@@ -25,7 +25,7 @@ module FileHutch
|
|
|
25
25
|
say ""
|
|
26
26
|
say "FileHutch installed.", :green
|
|
27
27
|
say " 1. Set FILE_HUTCH_API_KEY (Dashboard → API keys) and, if not production, FILE_HUTCH_URL."
|
|
28
|
-
say " 2. Add a column and macro: bin/rails g file_hutch:attachment User avatar then
|
|
28
|
+
say " 2. Add a column and macro: bin/rails g file_hutch:attachment User avatar then has_hutch :avatar, policy: \"avatars\""
|
|
29
29
|
say " 3. For browser uploads, set FileHutch.config.authorize_direct_upload in the initializer and register the"
|
|
30
30
|
say " Stimulus controller: application.register(\"filehutch-direct-upload\", DirectUploadController)"
|
|
31
31
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: file_hutch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andy Leverenz
|
|
@@ -10,8 +10,8 @@ cert_chain: []
|
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: Talk to the FileHutch file control plane from Ruby. Server-side and browser-direct
|
|
13
|
-
uploads, signed URLs, and a
|
|
14
|
-
|
|
13
|
+
uploads, signed URLs, and a has_hutch macro for Active Record that stores only opaque
|
|
14
|
+
file ids.
|
|
15
15
|
email:
|
|
16
16
|
- andy@justalever.com
|
|
17
17
|
executables:
|