resizing 1.2.1 → 1.3.1

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +73 -0
  3. data/.devcontainer/compose.yaml +58 -0
  4. data/.devcontainer/devcontainer-lock.json +9 -0
  5. data/.devcontainer/devcontainer.json +32 -0
  6. data/.devcontainer/post-create.sh +41 -0
  7. data/.github/copilot-instructions.md +1 -0
  8. data/.github/labeler.yml +28 -0
  9. data/.github/release.yml +35 -0
  10. data/.github/workflows/labeler.yml +20 -0
  11. data/.github/workflows/lint.yml +37 -0
  12. data/.github/workflows/test.yml +16 -9
  13. data/.gitignore +6 -0
  14. data/AGENTS.md +1 -0
  15. data/CHANGELOG.md +3 -0
  16. data/CLAUDE.md +68 -0
  17. data/Gemfile +9 -3
  18. data/README.md +114 -2
  19. data/Rakefile +5 -7
  20. data/bin/setup +3 -0
  21. data/git-hooks/pre-push +6 -0
  22. data/git-hooks/pre-push-ruby.sh +48 -0
  23. data/lib/resizing/carrier_wave/callback_file.rb +88 -0
  24. data/lib/resizing/carrier_wave/storage/file.rb +120 -47
  25. data/lib/resizing/carrier_wave/storage/remote.rb +7 -3
  26. data/lib/resizing/carrier_wave.rb +51 -7
  27. data/lib/resizing/client.rb +0 -1
  28. data/lib/resizing/configurable.rb +1 -1
  29. data/lib/resizing/configuration.rb +40 -10
  30. data/lib/resizing/mock_client.rb +23 -7
  31. data/lib/resizing/public_id.rb +3 -2
  32. data/lib/resizing/version.rb +1 -1
  33. data/lib/resizing.rb +0 -1
  34. data/resizing.gemspec +3 -3
  35. data/test/resizing/carrier_wave/storage/file_test.rb +455 -9
  36. data/test/resizing/carrier_wave/storage/remote_test.rb +91 -9
  37. data/test/resizing/carrier_wave_cache_callbacks_test.rb +224 -0
  38. data/test/resizing/carrier_wave_callback_file_test.rb +77 -0
  39. data/test/resizing/carrier_wave_test.rb +477 -23
  40. data/test/resizing/carrier_wave_uploader_test.rb +211 -0
  41. data/test/resizing/client_test.rb +324 -25
  42. data/test/resizing/configuration_test.rb +235 -10
  43. data/test/resizing/http_clientable_test.rb +27 -0
  44. data/test/resizing/mock_client_test.rb +111 -1
  45. data/test/resizing/public_id_test.rb +96 -0
  46. data/test/resizing_module_test.rb +110 -0
  47. data/test/resizing_test.rb +8 -0
  48. data/test/test_helper.rb +358 -11
  49. data/test/vcr/carrier_wave_test/update_image.yml +63 -0
  50. metadata +35 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c35a202fce460c80d3b476d4d9307f6345d9d13ed95c385a0e41108f35e46e61
4
- data.tar.gz: 14f7f3a20d83859f121b9138931164d5eb27a5a9764cd6ff2dee2dfc71aa72cd
3
+ metadata.gz: 0ff23b326ca457e2ba530fa2b299b7cb88c814fe08dc6469c3355506cdbb8f65
4
+ data.tar.gz: d0425ae8a78d155163a813a164b6f7b1e98f2a9b10032832d50c917878fcfbce
5
5
  SHA512:
6
- metadata.gz: 25a5f49e162e691ed72d147132d4a7aea069a6d148af8a1d22b0b3b3cedecc0b8bd46b674c177fdbef88179684342a230ffc23edb56340db42540beadc5f6947
7
- data.tar.gz: 03b8a3544e711973f79ef66dec2400ad09fba7d571a4518f0424ede8eb3da8420fb0c8fd299bc1a7c0ad734894bcbb59fa566857790277c0c8d4f0aa67537700
6
+ metadata.gz: 3e8a8b33fda6f8b6209c7b85fb7b2e89346b5059443b5de19f2334fb70019b1df4b92b0bf815e7f091e930a3e726e30f601d344e1330e2bb2ce83d6adbad3c9a
7
+ data.tar.gz: ab6ea786bce933942de4e10b8826beb243a2285789ec48c9a33644aae954bfc7fa26817ab73c95516844661d60d5e6f2b5d36da2c6b0509eb6b4126602ca6874
@@ -0,0 +1,73 @@
1
+ # Debian variant of the base image (bookworm / bullseye)
2
+ ARG VARIANT=bookworm
3
+ FROM mcr.microsoft.com/devcontainers/base:${VARIANT}
4
+
5
+ # Ruby installed and set as the rbenv global version. Matches .ruby-version.
6
+ # Other versions can be installed from inside the container with `rbenv install`.
7
+ ARG RUBY_VERSION=3.1.7
8
+
9
+ # Build dependencies for ruby-build, plus what the mysql2 gem needs.
10
+ # The MySQL packages match .github/workflows/test.yml.
11
+ RUN apt-get update \
12
+ && export DEBIAN_FRONTEND=noninteractive \
13
+ && apt-get install -y --no-install-recommends \
14
+ autoconf \
15
+ bison \
16
+ build-essential \
17
+ libffi-dev \
18
+ libgdbm-dev \
19
+ libncurses-dev \
20
+ libreadline-dev \
21
+ libssl-dev \
22
+ libyaml-dev \
23
+ uuid-dev \
24
+ zlib1g-dev \
25
+ default-libmysqlclient-dev \
26
+ default-mysql-client \
27
+ pkg-config \
28
+ && apt-get clean \
29
+ && rm -rf /var/lib/apt/lists/*
30
+
31
+ ENV RBENV_ROOT=/usr/local/rbenv
32
+ ENV PATH=${RBENV_ROOT}/shims:${RBENV_ROOT}/bin:${PATH}
33
+
34
+ # rbenv and ruby-build. RBENV_ROOT is owned by vscode so that `rbenv install`
35
+ # works from inside the container without sudo.
36
+ RUN git clone --depth 1 https://github.com/rbenv/rbenv.git "${RBENV_ROOT}" \
37
+ && git clone --depth 1 https://github.com/rbenv/ruby-build.git "${RBENV_ROOT}/plugins/ruby-build" \
38
+ && printf '%s\n' \
39
+ 'export RBENV_ROOT=/usr/local/rbenv' \
40
+ 'export PATH="$RBENV_ROOT/shims:$RBENV_ROOT/bin:$PATH"' \
41
+ 'eval "$(rbenv init -)"' \
42
+ > /etc/profile.d/rbenv.sh
43
+
44
+ RUN rbenv install "${RUBY_VERSION}" \
45
+ && rbenv global "${RUBY_VERSION}" \
46
+ && gem install bundler \
47
+ && rbenv rehash \
48
+ && chown -R vscode:vscode "${RBENV_ROOT}"
49
+
50
+ # Install gems into a named volume, so nothing is written to the bind-mounted
51
+ # workspace and a rebuild does not have to fetch them again.
52
+ ENV BUNDLE_PATH=/usr/local/bundle
53
+
54
+ RUN mkdir -p "${BUNDLE_PATH}" && chown -R vscode:vscode "${BUNDLE_PATH}"
55
+
56
+ # Ruby artifacts generated on the host must not leak in through the bind mount:
57
+ # vendor/ holds gems with native extensions built against the host's glibc,
58
+ # .bundle/config points BUNDLE_PATH at it, and .ruby-lsp/ records which gems the
59
+ # Ruby LSP extension has installed. compose.yaml keeps all three on their own
60
+ # volumes; creating the directories here gives those volumes the right owner.
61
+ RUN mkdir -p /workspaces/resizing-gem/vendor \
62
+ /workspaces/resizing-gem/.bundle \
63
+ /workspaces/resizing-gem/.ruby-lsp \
64
+ && chown -R vscode:vscode /workspaces
65
+
66
+ # Bundler's global config, so that BUNDLE_PATH also applies to tools that
67
+ # compose their own bundle with a clean environment. The Ruby LSP extension
68
+ # builds one under .ruby-lsp/, which makes that directory bundler's app root,
69
+ # so a config in the workspace root would not be read for it.
70
+ RUN mkdir -p /home/vscode/.bundle \
71
+ && printf '%s\n' '---' 'BUNDLE_PATH: "/usr/local/bundle"' \
72
+ > /home/vscode/.bundle/config \
73
+ && chown -R vscode:vscode /home/vscode/.bundle
@@ -0,0 +1,58 @@
1
+ # A distinct project name and service name so this does not collide with the
2
+ # docker-compose.yml in the repository root (project resizing-gem, service mysql)
3
+ name: resizing-gem-devcontainer
4
+
5
+ services:
6
+ app:
7
+ build:
8
+ context: ..
9
+ dockerfile: .devcontainer/Dockerfile
10
+ args:
11
+ # Default Ruby version. Other versions can be installed from inside the
12
+ # container with `rbenv install`, so this rarely needs changing.
13
+ RUBY_VERSION: 3.1.7
14
+ command: sleep infinity
15
+ environment:
16
+ # test/test_helper.rb reads these to build the ActiveRecord connection.
17
+ # MYSQL_DATABASE is left unset on purpose: the tests then create a database
18
+ # per process and drop it afterwards, which keeps concurrent runs isolated.
19
+ MYSQL_HOST: db
20
+ MYSQL_PORT: '3306'
21
+ MYSQL_USER: root
22
+ MYSQL_PASSWORD: secret
23
+ # RAILS_VERSION is left unset on purpose: the Gemfile then picks the newest
24
+ # Rails that runs on the container's Ruby. Set it here to pin another version.
25
+ volumes:
26
+ - ..:/workspaces/resizing-gem:cached
27
+ - bundle:/usr/local/bundle
28
+ # Not shared with the host: see the Dockerfile
29
+ - vendor:/workspaces/resizing-gem/vendor
30
+ - bundle-config:/workspaces/resizing-gem/.bundle
31
+ - ruby-lsp:/workspaces/resizing-gem/.ruby-lsp
32
+ depends_on:
33
+ db:
34
+ condition: service_healthy
35
+
36
+ db:
37
+ image: mysql:5.7.29
38
+ # mysql:5.7 is published for amd64 only, so run it emulated on Apple Silicon
39
+ platform: linux/amd64
40
+ command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_bin
41
+ environment:
42
+ MYSQL_ROOT_PASSWORD: secret
43
+ MYSQL_DATABASE: resizing_gem_test
44
+ volumes:
45
+ - db-data:/var/lib/mysql
46
+ healthcheck:
47
+ test: ['CMD', 'mysqladmin', 'ping', '-h', '127.0.0.1', '-uroot', '-psecret']
48
+ interval: 5s
49
+ timeout: 5s
50
+ retries: 30
51
+ start_period: 30s
52
+
53
+ volumes:
54
+ bundle:
55
+ vendor:
56
+ bundle-config:
57
+ ruby-lsp:
58
+ db-data:
@@ -0,0 +1,9 @@
1
+ {
2
+ "features": {
3
+ "ghcr.io/devcontainers/features/github-cli:1": {
4
+ "version": "1.1.2",
5
+ "resolved": "ghcr.io/devcontainers/features/github-cli@sha256:7c409bf6316ffd85f04fd92fba85a744282639e603417dd4796409866bdb6805",
6
+ "integrity": "sha256:7c409bf6316ffd85f04fd92fba85a744282639e603417dd4796409866bdb6805"
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "resizing-gem",
3
+ "dockerComposeFile": "compose.yaml",
4
+ "service": "app",
5
+ "workspaceFolder": "/workspaces/resizing-gem",
6
+ "remoteUser": "vscode",
7
+ "features": {
8
+ "ghcr.io/devcontainers/features/github-cli:1": {}
9
+ },
10
+ "postCreateCommand": ".devcontainer/post-create.sh",
11
+ "customizations": {
12
+ "vscode": {
13
+ "extensions": [
14
+ "Shopify.ruby-lsp",
15
+ "eamodio.gitlens"
16
+ ],
17
+ "settings": {
18
+ "[ruby]": {
19
+ "editor.defaultFormatter": "Shopify.ruby-lsp",
20
+ "editor.tabSize": 2,
21
+ "editor.insertSpaces": true
22
+ },
23
+ "rubyLsp.formatter": "rubocop",
24
+ "rubyLsp.rubyVersionManager": {
25
+ "identifier": "rbenv"
26
+ },
27
+ "files.trimTrailingWhitespace": true,
28
+ "files.insertFinalNewline": true
29
+ }
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env bash
2
+ # Runs once after the dev container is created.
3
+ set -euo pipefail
4
+
5
+ # Honour a .ruby-version that asks for a Ruby the image does not carry.
6
+ # (.ruby-version is gitignored, so it differs from machine to machine.)
7
+ if [ -f .ruby-version ]; then
8
+ required="$(cat .ruby-version)"
9
+ if ! rbenv versions --bare | grep -qx "${required}"; then
10
+ echo "==> installing Ruby ${required} (from .ruby-version)"
11
+ rbenv install "${required}"
12
+ rbenv rehash
13
+ fi
14
+ fi
15
+
16
+ echo "==> ruby $(ruby -e 'print RUBY_VERSION')"
17
+
18
+ echo "==> bundle install"
19
+ bundle install
20
+
21
+ echo "==> waiting for MySQL (${MYSQL_HOST}:${MYSQL_PORT})"
22
+ for _ in $(seq 1 60); do
23
+ if mysqladmin ping \
24
+ -h "${MYSQL_HOST}" -P "${MYSQL_PORT}" \
25
+ -u "${MYSQL_USER}" -p"${MYSQL_PASSWORD}" \
26
+ --silent > /dev/null 2>&1; then
27
+ echo "MySQL is ready"
28
+ break
29
+ fi
30
+ sleep 1
31
+ done
32
+
33
+ cat <<'MSG'
34
+
35
+ setup done.
36
+
37
+ bundle exec rake test # run the tests
38
+ bundle exec rubocop # run the linter
39
+ bin/console # interactive prompt
40
+
41
+ MSG
@@ -0,0 +1 @@
1
+ ../CLAUDE.md
@@ -0,0 +1,28 @@
1
+ ruby:
2
+ - changed-files:
3
+ - any-glob-to-any-file:
4
+ - 'lib/**/*.rb'
5
+ - 'Rakefile'
6
+ - 'resizing.gemspec'
7
+ - '.rubocop.yml'
8
+
9
+ tests:
10
+ - changed-files:
11
+ - any-glob-to-any-file:
12
+ - 'test/**'
13
+
14
+ github_actions:
15
+ - changed-files:
16
+ - any-glob-to-any-file:
17
+ - '.github/**'
18
+
19
+ documentation:
20
+ - changed-files:
21
+ - any-glob-to-any-file:
22
+ - '**/*.md'
23
+
24
+ dependencies:
25
+ - changed-files:
26
+ - any-glob-to-any-file:
27
+ - 'Gemfile'
28
+ - 'Gemfile.lock'
@@ -0,0 +1,35 @@
1
+ changelog:
2
+ exclude:
3
+ labels:
4
+ - release
5
+ categories:
6
+ - title: Breaking Changes
7
+ labels:
8
+ - breaking change
9
+ - title: New Features
10
+ labels:
11
+ - enhancement
12
+ - title: Improvements
13
+ labels:
14
+ - improvement
15
+ - title: Bug Fixes
16
+ labels:
17
+ - bug
18
+ - title: Security
19
+ labels:
20
+ - security
21
+ - title: Dependencies
22
+ labels:
23
+ - dependencies
24
+ - title: CI
25
+ labels:
26
+ - github_actions
27
+ - title: Housekeeping
28
+ labels:
29
+ - housekeeping
30
+ - title: Documentation
31
+ labels:
32
+ - documentation
33
+ - title: Other Changes
34
+ labels:
35
+ - "*"
@@ -0,0 +1,20 @@
1
+ name: labeler
2
+
3
+ on:
4
+ pull_request_target:
5
+ types:
6
+ - opened
7
+ - synchronize
8
+ - reopened
9
+
10
+ jobs:
11
+ labeler:
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: read
15
+ pull-requests: write
16
+ steps:
17
+ - uses: actions/labeler@b8dd2d9be0f68b860e7dae5dae7d772984eacd6d # v6
18
+ with:
19
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
20
+ sync-labels: false
@@ -0,0 +1,37 @@
1
+ name: lint
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - master
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ rubocop:
14
+ name: RuboCop
15
+ runs-on: ubuntu-22.04
16
+
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+
20
+ - name: "Install ruby dependencies"
21
+ run: |
22
+ sudo apt update
23
+ sudo apt install -y libyaml-dev curl libmysqlclient-dev
24
+
25
+ - uses: ruby/setup-ruby@v1
26
+ with:
27
+ # Matches the devcontainer, so local and CI report the same offenses
28
+ ruby-version: '3.1'
29
+ bundler-cache: false
30
+
31
+ - name: bundle install
32
+ run: |
33
+ bundle install
34
+
35
+ - name: Run RuboCop
36
+ run: |
37
+ bundle exec rubocop
@@ -12,27 +12,30 @@ permissions:
12
12
 
13
13
  jobs:
14
14
  test:
15
- name: Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}
15
+ name: Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }} / Faraday ${{ matrix.faraday }}
16
16
  strategy:
17
17
  fail-fast: false
18
18
  matrix:
19
- ruby: ['3.1', '3.2','3.3', '3.4']
20
- rails: ['6.1', '7.0', '7.1', '7.2']
19
+ ruby: ['3.1', '3.2', '3.3', '3.4', '4.0']
20
+ rails: ['7.0', '7.1', '7.2', '8.0', '8.1']
21
+ faraday: ['1.10', '2.0']
21
22
  exclude:
22
- # Rails 7.2 requires Ruby 3.1+
23
+ # Rails 8.x requires Ruby 3.2+
23
24
  - ruby: '3.1'
24
- rails: '7.2'
25
- # Rails 7.1 requires Ruby 3.1+
25
+ rails: '8.0'
26
26
  - ruby: '3.1'
27
+ rails: '8.1'
28
+ # Upstream does not support Ruby 4.0 on Rails 7.0 / 7.1
29
+ - ruby: '4.0'
30
+ rails: '7.0'
31
+ - ruby: '4.0'
27
32
  rails: '7.1'
28
- # Rails 6.1 requires Ruby under 3.3
29
- - ruby: '3.4'
30
- rails: '6.1'
31
33
 
32
34
  runs-on: ubuntu-22.04
33
35
 
34
36
  env:
35
37
  RAILS_VERSION: ${{ matrix.rails }}
38
+ FARADAY_VERSION: ${{ matrix.faraday }}
36
39
 
37
40
  steps:
38
41
  - uses: actions/checkout@v4
@@ -61,6 +64,10 @@ jobs:
61
64
  run: |
62
65
  bundle install
63
66
 
67
+ - name: Show Faraday version
68
+ run: |
69
+ bundle list | grep faraday
70
+
64
71
  - name: Run test
65
72
  run: |
66
73
  bundle exec rake test
data/.gitignore CHANGED
@@ -6,3 +6,9 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ vendor/
10
+ Gemfile.lock
11
+ tags
12
+ sample1.jpg
13
+ .ruby-version
14
+ uploads/
data/AGENTS.md ADDED
@@ -0,0 +1 @@
1
+ CLAUDE.md
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ > このファイルは v0.8.2 までの履歴です。以降のリリースノートは
4
+ > [GitHub Releases](https://github.com/jksy/resizing-gem/releases) に一本化しています。
5
+
3
6
  **Merged pull requests:**
4
7
 
5
8
  - v0.8.2 [\#53](https://github.com/jksy/resizing-gem/pull/53) ([jksy](https://github.com/jksy))
data/CLAUDE.md ADDED
@@ -0,0 +1,68 @@
1
+ # CLAUDE.md — resizing-gem
2
+
3
+ [Resizing](https://www.resizing.net/) の Ruby クライアント gem(rubygems.org に `resizing` として公開)。
4
+
5
+ ## 開発環境
6
+
7
+ devcontainer(`.devcontainer/`)を用意してある。VS Code の "Reopen in Container"、または `devcontainer up --workspace-folder .` で、Ruby・MySQL・`bundle install` まで揃った状態になる。
8
+
9
+ Ruby は rbenv 管理で `.ruby-version` に従う。別バージョンを試す場合はコンテナ内で `rbenv install <version>` → `rbenv local <version>` → `bundle install`(sudo 不要)。イメージに焼くバージョンを変える場合は `.devcontainer/compose.yaml` の `RUBY_VERSION` を変更してリビルドする。
10
+
11
+ devcontainer を使わない場合はテスト用に MySQL を自前で起動する(`docker compose up -d mysql`)。接続先は `MYSQL_HOST` / `MYSQL_PORT` / `MYSQL_USER` / `MYSQL_PASSWORD` で上書きでき、既定は `root:secret@127.0.0.1:3306`。
12
+
13
+ データベースはテストプロセスごとに `resizing_gem_test_<ホスト識別子>_<pid>` を作成し、終了時に破棄する(並行実行しても壊れないようにするため。強制終了で残ったものは次回実行時に掃除する)。`MYSQL_DATABASE` を指定した場合はそのデータベースをそのまま使い破棄もしないので、並行実行するときは名前を分ける。
14
+
15
+ ## テスト・Lint
16
+
17
+ 外部 API 呼び出しは `test/vcr/` のカセットを使い、実 API を叩くテストは追加しない。
18
+
19
+ ```bash
20
+ bundle exec rake ci # RuboCop + テスト(push 前チェックと同じ)
21
+ bundle exec rake test # 全件
22
+ bundle exec ruby -Itest -Ilib test/resizing/client_test.rb # 単一ファイル
23
+ RAILS_VERSION=7.1 bundle exec rake test # Rails バージョンを変えて実行(既定は Ruby 3.2 以上で 8.1、3.1 で 7.2)
24
+ bundle exec rubocop
25
+ ```
26
+
27
+ ローカルで実行できない場合、確認は CI に任せてよい。テストは `.github/workflows/test.yml`(Ruby 3.1〜4.0 × Rails 7.0〜8.1)、RuboCop は `.github/workflows/lint.yml`(Ruby 3.1)で走る。
28
+
29
+ ## push 前チェック
30
+
31
+ `git push` すると `git-hooks/pre-push` が `bundle exec rake ci`(RuboCop + テスト)を実行し、失敗した時点で push を中断する。**CI が落ちる前に気づくための仕組みなので、`--no-verify` で飛ばさないこと**(飛ばした場合はその旨を報告する)。
32
+
33
+ 有効化はクローンごとに一度だけ必要で、`bin/setup` が `git config core.hooksPath git-hooks` を設定する。設定済みかは `git config core.hooksPath` で確認できる(worktree でも設定は共有される)。
34
+
35
+ ```bash
36
+ bin/setup # bundle install + git hooks の有効化
37
+ PRE_PUSH_SKIP_TESTS=1 git push # RuboCop だけにしてテストを省く
38
+ ```
39
+
40
+ チェックは gem が入っている環境で走る。`bundle check` が通る環境(devcontainer の中、または `bundle install` 済みのホスト)ならそのまま、通らなければ devcontainer CLI か docker compose 経由で devcontainer 内で実行する。
41
+
42
+ ## PR 運用
43
+
44
+ - `master` に直接 push しない。feature ブランチ(`claude/` プレフィックス可)から PR を出す
45
+ - **PR には種別ラベルを必ず 1 つ付ける**(`enhancement` / `improvement` / `bug` / `security` / `documentation` / `housekeeping` / `breaking change` のいずれか)。リリースノートのカテゴリ分け(`.github/release.yml`)に使われる
46
+ - `improvement` は gem の機能改善。CI・開発環境の整備など利用者に見えない変更は `housekeeping`
47
+ - バージョンバンプだけの PR には `release` を付ける(リリースノートから除外される)
48
+ - `ruby` / `tests` / `github_actions` / `documentation` / `dependencies` は `.github/labeler.yml` で自動付与される。種別ラベルは自動では付かない
49
+ - Issue 番号は PR タイトルに含めず、PR 説明に `Closes #N` と書く
50
+ - 公開 API を変える場合は `breaking change` ラベルを付け、README も更新する
51
+
52
+ ## リリース手順
53
+
54
+ 1. `lib/resizing/version.rb` を更新する PR に `release` ラベルを付けてマージする
55
+ 2. `master` で `bundle exec rake release`(rubygems.org への公開と `v<version>` タグの push)
56
+ 3. GitHub の Releases で該当タグを選び、"Generate release notes" で本文を生成して公開する
57
+
58
+ `CHANGELOG.md` は v0.8.2 で更新を止めており、リリースノートは GitHub Releases に一本化している。
59
+
60
+ ## 言語ルール
61
+
62
+ | 場所 | 言語 |
63
+ |------|------|
64
+ | コミットメッセージ | 英語(Issue 番号は含めない) |
65
+ | ソースコード内コメント | 英語 |
66
+ | PR タイトル・説明 | 日本語 |
67
+ | コードレビューコメント | 日本語 |
68
+ | 人間とのやり取り全般 | 日本語 |
data/Gemfile CHANGED
@@ -5,12 +5,18 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in resizing.gemspec
6
6
  gemspec
7
7
 
8
- # Allow testing against different Rails versions
9
- rails_version = ENV['RAILS_VERSION'] || '7.0'
8
+ # Allow testing against different Rails versions (e.g. RAILS_VERSION=7.1).
9
+ # Unset, the newest supported Rails that runs on the current Ruby is used:
10
+ # Rails 8.x needs Ruby 3.2+, so Ruby 3.1 falls back to 7.2.
11
+ rails_version = ENV['RAILS_VERSION'] || (RUBY_VERSION >= '3.2' ? '8.1' : '7.2')
10
12
  gem 'rails', "~> #{rails_version}"
11
13
 
14
+ # Allow testing against different Faraday versions (e.g. FARADAY_VERSION=1.10).
15
+ # Unset, the gemspec constraint picks the latest release.
16
+ faraday_version = ENV['FARADAY_VERSION']
17
+ gem 'faraday', "~> #{faraday_version}" if faraday_version
18
+
12
19
  gem 'byebug'
13
- gem 'github_changelog_generator'
14
20
  gem 'mysql2'
15
21
  gem 'pry-byebug'
16
22
  gem 'rake', '~> 13.0'
data/README.md CHANGED
@@ -8,7 +8,13 @@ Client and utilities for [Resizing](https://www.resizing.net/) - an image hostin
8
8
 
9
9
  ## Requirements
10
10
 
11
- - Ruby 3.1.0 or later
11
+ - Ruby 3.1.0 or later (tested against 3.1, 3.2, 3.3, 3.4 and 4.0)
12
+ - Rails 7.0 or later for the CarrierWave integration (tested against 7.0, 7.1, 7.2, 8.0 and 8.1)
13
+ - Faraday 1.x or 2.x (tested against 1.10 and the latest 2.x)
14
+
15
+ The exact combinations exercised in CI are listed in `.github/workflows/test.yml`.
16
+ Support for a Ruby or Rails series that has reached upstream end-of-life may be dropped in
17
+ a minor release; such changes are announced in the release notes.
12
18
 
13
19
  ## Installation
14
20
 
@@ -31,12 +37,13 @@ Or install it yourself as:
31
37
  ```ruby
32
38
  Resizing.configure = {
33
39
  image_host: 'https://img.resizing.net',
34
- video_host: 'https://video.resizing.net',
35
40
  project_id: 'your-project-id',
36
41
  secret_token: 'your-secret-token'
37
42
  }
38
43
  ```
39
44
 
45
+ `video_host` は動画 API の廃止にともない非推奨です。指定しても利用されず、`Configuration#video_host` や `Configuration::DEFAULT_VIDEO_HOST` を参照すると警告が出ます。将来のバージョンで削除します。
46
+
40
47
  ## Usage
41
48
 
42
49
  ### Basic Client Usage
@@ -81,10 +88,115 @@ class User
81
88
  end
82
89
  ```
83
90
 
91
+ `process` declares the transformation applied when the browser fetches the image URL, so
92
+ the processors are never run as local image processing on upload.
93
+
94
+ The uploader validations hooked on CarrierWave's `:cache` callbacks are checked before the
95
+ image is uploaded to Resizing:
96
+
97
+ ```ruby
98
+ class ImageUploader < CarrierWave::Uploader::Base
99
+ include Resizing::CarrierWave
100
+
101
+ def extension_allowlist
102
+ %w[jpg jpeg gif png]
103
+ end
104
+
105
+ def content_type_allowlist
106
+ [%r{\Aimage/}]
107
+ end
108
+
109
+ def size_range
110
+ 0..(5 * 1024 * 1024)
111
+ end
112
+ end
113
+ ```
114
+
115
+ `extension_denylist` and `content_type_denylist` work the same way. A rejected file is not
116
+ uploaded, and the model becomes invalid with an error on the mounted column, as in plain
117
+ CarrierWave.
118
+
119
+ The extension checked by `extension_allowlist` / `extension_denylist` is derived from the
120
+ content type of the file whenever it is known, not from the file name. A file downloaded
121
+ from a Resizing URL (e.g. assigned through `remote_<column>_url=`) ends with the version
122
+ string, so its file name has no meaningful extension; the `Content-Type` of the response
123
+ is used instead. When the content type is unknown (`application/octet-stream`), the
124
+ extension of the file name is used as in plain CarrierWave.
125
+
126
+ Versions are not uploaded separately: a version only changes the transformation in the
127
+ generated URL, so a single upload backs every version.
128
+
84
129
  ## Development
85
130
 
131
+ ### Dev Container (recommended)
132
+
133
+ This repository ships a [Dev Container](https://containers.dev/) so that everyone develops
134
+ against the same Ruby / MySQL setup.
135
+
136
+ Requirements: Docker and either VS Code + the *Dev Containers* extension, or the
137
+ [`devcontainer` CLI](https://github.com/devcontainers/cli).
138
+
139
+ 1. Open the repository in VS Code and run **Dev Containers: Reopen in Container**
140
+ (or run `devcontainer up --workspace-folder .`).
141
+ 2. `bundle install` and the MySQL wait are executed automatically by
142
+ `.devcontainer/post-create.sh`.
143
+ 3. Inside the container:
144
+
145
+ ```console
146
+ $ bundle exec rake test # run the tests
147
+ $ bundle exec rubocop # run the linter
148
+ $ bin/console # interactive prompt
149
+ ```
150
+
151
+ The container provides:
152
+
153
+ - Ruby managed by [rbenv](https://github.com/rbenv/rbenv), so the version can be changed
154
+ from inside the container (see below)
155
+ - MySQL 5.7 with the `resizing_gem_test` database, matching CI
156
+ - `RAILS_VERSION` to test against another Rails version, matching the `RAILS_VERSION`
157
+ switch in the `Gemfile` and in CI. Unset, the `Gemfile` picks the newest supported Rails
158
+ that runs on the current Ruby (8.1, or 7.2 on Ruby 3.1)
159
+
160
+ Gems are installed into a named volume (`/usr/local/bundle`). `vendor/`, `.bundle/` and
161
+ `.ruby-lsp/` are kept on their own volumes so that Ruby artifacts generated on the host do
162
+ not leak into the container through the bind mount: `vendor/` holds gems whose native
163
+ extensions are built against the host's libraries, `.bundle/config` points `BUNDLE_PATH`
164
+ at it, and `.ruby-lsp/` records which gems the Ruby LSP extension has installed. The host
165
+ copies are left untouched.
166
+
167
+ #### Changing the Ruby version
168
+
169
+ Ruby 3.1.7 is installed when the image is built, and `.ruby-version` is honoured on
170
+ container creation. To switch to another version from inside the container:
171
+
172
+ ```console
173
+ $ rbenv install 3.3.12
174
+ $ rbenv local 3.3.12 # writes .ruby-version (gitignored)
175
+ $ bundle install
176
+ ```
177
+
178
+ `rbenv install` needs no `sudo`; the build dependencies are already in the image. To
179
+ change the version the image ships with, set the `RUBY_VERSION` build arg in
180
+ `.devcontainer/compose.yaml` and rebuild.
181
+
182
+ ### Without a Dev Container
183
+
86
184
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
87
185
 
186
+ The tests need a MySQL server. `docker-compose.yml` in the repository root starts a
187
+ suitable one (`docker compose up -d mysql`).
188
+
189
+ Each test process creates its own database (`resizing_gem_test_<host>_<pid>`) and drops it
190
+ when the run finishes, so several test processes can share one MySQL server without
191
+ breaking each other's tables. Databases left behind by killed processes are cleaned up on
192
+ the next run.
193
+
194
+ The connection defaults to `root:secret@127.0.0.1:3306` and can be overridden with the
195
+ `MYSQL_HOST`, `MYSQL_PORT`, `MYSQL_USER` and `MYSQL_PASSWORD` environment variables.
196
+ Setting `MYSQL_DATABASE` uses that database as is and never drops it; in that case give
197
+ each concurrent test process a different name, otherwise they will overwrite each other's
198
+ tables.
199
+
88
200
  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](https://rubygems.org).
89
201
 
90
202
  ## Contributing