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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2b2054f9f101d16f7ea61d375dfcbb9715838b5988c517bd547da595759f454
4
- data.tar.gz: b81dc343e6ee21e17d396502b0700ff7e9ed253e5729f928eca28673248c2801
3
+ metadata.gz: 68acbe5c06713d98ad400877d375ccd63794b11ebe6e381aec9aea714061a0d6
4
+ data.tar.gz: a9d3896f4d665648edce1641453a92abb12168802a67feae0f8c6d015d1d5fb5
5
5
  SHA512:
6
- metadata.gz: 48a44a32ed534d38c731ab9cb9be31c856b635a642035ae5942cdcfffca73743c973f8fe11cb7a2dcccf7206e503b650d1997dd98c17f85dbcee705aebb20adc
7
- data.tar.gz: 13cfab0ce82a0afa0594818e1508b994ee066790319fb621a18c7bc3033bc787a2a1afa22699c29a92bc1e783b101a1bb9e7bb9ae0e6e08465c813286d18a98a
6
+ metadata.gz: 1ee3d96af2b6ab2b37d37036b466c4b6ed27ea40db2458c175e49723542464f595830786f228a02162cd65706c46dfac50429aa14213e080ceca1b3d2f78b0da
7
+ data.tar.gz: 670315688e96fc2170634e086ab5c21871cfe38e516d8aef6a3b1b5212cc64e88088e7bb9d4846f2bca77b4eb1d82a3106929c372335235c5a3489e572450b8f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0 — 2026-09-16
4
+
5
+ ### Rails
6
+
7
+ - `has_file_hutch_file` is now `has_hutch`, with the same options. The old name still works and
8
+ logs a deprecation warning; it will be removed in 0.3.
9
+
3
10
  ## 0.1.0 — 2026-09-15
4
11
 
5
12
  First release.
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
- has_file_hutch_file :avatar, policy: "avatars"
165
- has_file_hutch_file :contract, policy: "documents", dependent: false
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, `has_file_hutch_file` verifies the submitted id is a ready file under the declared policy,
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` | `has_file_hutch_file :avatar, policy: "avatars"` |
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
- # `has_file_hutch_file` for Active Record. The model stores one string column,
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
- # has_file_hutch_file :avatar, policy: "avatars"
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 has_file_hutch_file(name, policy:, column: "#{name}_file_id", dependent: :delete, verify: true)
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
@@ -2,4 +2,9 @@
2
2
 
3
3
  require "rails"
4
4
  require_relative "rails/attachable"
5
+
6
+ module FileHutch
7
+ def self.deprecator = @deprecator ||= ActiveSupport::Deprecation.new("0.3", "file_hutch")
8
+ end
9
+
5
10
  require_relative "rails/engine"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FileHutch
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -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 `has_file_hutch_file :avatar, policy: "…"`.
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}: has_file_hutch_file :#{attachment}, policy: "#{attachment.pluralize}"), :green
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 has_file_hutch_file :avatar, policy: \"avatars\""
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.1.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 has_file_hutch_file macro for Active Record that stores
14
- only opaque file ids.
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: