From 4c62457e3a38951d566f1d16a551c3dfb57d44e7 Mon Sep 17 00:00:00 2001 From: mizuki-y Date: Mon, 12 Oct 2026 19:41:17 +0900 Subject: [PATCH 1/3] refactor: move the core gem into its own structured_params/ folder Mirror structured_params-openapi/ so the repository holds one folder per gem (as sentry-ruby does). The repository root keeps what is shared: README, Gemfile, Rakefile, Steepfile, lefthook.yml and the RuboCop configuration. - lib/, sig/, spec/, docs/, the gemspec, CHANGELOG.md and .rspec move to structured_params/; git detects the files as renames - Rakefile: spec tasks per gem and Bundler::GemHelper for the core gem, so rake build/release keep acting on structured_params - RuboCop: set TargetRubyVersion (it can no longer be inferred from a root gemspec) and make the spec excludes match nested spec folders - release/tagging workflows: new paths for the version file, CHANGELOG and the gem build (run from the gem folder) - README links, AGENTS.md, CONTRIBUTING.md, Procfile.dev, lefthook.yml updated Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/release.yml | 13 +++-- .github/workflows/tagging.yml | 4 +- .gitignore | 2 +- .rubocop.yml | 10 +++- .rubocop_rbs.yml | 4 +- AGENTS.md | 35 ++++++------ CONTRIBUTING.md | 55 +++++++++++-------- Gemfile | 2 +- Procfile.dev | 3 +- README.md | 14 ++--- README_ja.md | 14 ++--- Rakefile | 27 +++++---- Steepfile | 6 +- bin/console | 2 +- lefthook.yml | 4 +- .rspec => structured_params/.rspec | 0 .../CHANGELOG.md | 0 structured_params/LICENSE.txt | 21 +++++++ .../docs}/basic-usage.md | 0 .../docs}/error-handling.md | 0 .../docs}/form-objects.md | 0 .../docs}/installation.md | 0 .../docs}/serialization.md | 0 .../docs}/strong-parameters.md | 0 .../docs}/validation.md | 0 .../lib}/structured_params.rb | 0 .../structured_params/attribute_methods.rb | 0 .../lib}/structured_params/errors.rb | 0 .../lib}/structured_params/i18n.rb | 0 .../lib}/structured_params/params.rb | 0 .../lib}/structured_params/type/array.rb | 0 .../lib}/structured_params/type/object.rb | 0 .../lib}/structured_params/validations.rb | 0 .../lib}/structured_params/version.rb | 0 .../sig}/structured_params.rbs | 0 .../structured_params/attribute_methods.rbs | 0 .../sig}/structured_params/errors.rbs | 0 .../sig}/structured_params/i18n.rbs | 0 .../sig}/structured_params/params.rbs | 0 .../sig}/structured_params/type/array.rbs | 0 .../sig}/structured_params/type/object.rbs | 0 .../sig}/structured_params/validations.rbs | 0 .../sig}/structured_params/version.rbs | 0 .../spec}/attribute_methods_spec.rb | 0 .../spec}/errors_spec.rb | 0 .../spec}/factories/address_parameters.rb | 0 .../spec}/factories/hobby_parameters.rb | 0 .../spec}/factories/user_parameters.rb | 0 .../spec}/form_object_spec.rb | 0 {spec => structured_params/spec}/i18n_spec.rb | 0 .../spec}/params_spec.rb | 0 .../spec}/permit_spec.rb | 0 .../spec}/spec_helper.rb | 0 .../spec}/support/locales/ja.yml | 0 .../support/shared_contexts/ja_locale.rb | 0 .../test_classes/form_object_classes.rb | 0 .../support/test_classes/params_classes.rb | 0 .../spec}/type/array_spec.rb | 0 .../spec}/type/object_spec.rb | 0 .../spec}/validations_spec.rb | 0 .../structured_params.gemspec | 2 +- 61 files changed, 133 insertions(+), 85 deletions(-) rename .rspec => structured_params/.rspec (100%) rename CHANGELOG.md => structured_params/CHANGELOG.md (100%) create mode 100644 structured_params/LICENSE.txt rename {docs => structured_params/docs}/basic-usage.md (100%) rename {docs => structured_params/docs}/error-handling.md (100%) rename {docs => structured_params/docs}/form-objects.md (100%) rename {docs => structured_params/docs}/installation.md (100%) rename {docs => structured_params/docs}/serialization.md (100%) rename {docs => structured_params/docs}/strong-parameters.md (100%) rename {docs => structured_params/docs}/validation.md (100%) rename {lib => structured_params/lib}/structured_params.rb (100%) rename {lib => structured_params/lib}/structured_params/attribute_methods.rb (100%) rename {lib => structured_params/lib}/structured_params/errors.rb (100%) rename {lib => structured_params/lib}/structured_params/i18n.rb (100%) rename {lib => structured_params/lib}/structured_params/params.rb (100%) rename {lib => structured_params/lib}/structured_params/type/array.rb (100%) rename {lib => structured_params/lib}/structured_params/type/object.rb (100%) rename {lib => structured_params/lib}/structured_params/validations.rb (100%) rename {lib => structured_params/lib}/structured_params/version.rb (100%) rename {sig => structured_params/sig}/structured_params.rbs (100%) rename {sig => structured_params/sig}/structured_params/attribute_methods.rbs (100%) rename {sig => structured_params/sig}/structured_params/errors.rbs (100%) rename {sig => structured_params/sig}/structured_params/i18n.rbs (100%) rename {sig => structured_params/sig}/structured_params/params.rbs (100%) rename {sig => structured_params/sig}/structured_params/type/array.rbs (100%) rename {sig => structured_params/sig}/structured_params/type/object.rbs (100%) rename {sig => structured_params/sig}/structured_params/validations.rbs (100%) rename {sig => structured_params/sig}/structured_params/version.rbs (100%) rename {spec => structured_params/spec}/attribute_methods_spec.rb (100%) rename {spec => structured_params/spec}/errors_spec.rb (100%) rename {spec => structured_params/spec}/factories/address_parameters.rb (100%) rename {spec => structured_params/spec}/factories/hobby_parameters.rb (100%) rename {spec => structured_params/spec}/factories/user_parameters.rb (100%) rename {spec => structured_params/spec}/form_object_spec.rb (100%) rename {spec => structured_params/spec}/i18n_spec.rb (100%) rename {spec => structured_params/spec}/params_spec.rb (100%) rename {spec => structured_params/spec}/permit_spec.rb (100%) rename {spec => structured_params/spec}/spec_helper.rb (100%) rename {spec => structured_params/spec}/support/locales/ja.yml (100%) rename {spec => structured_params/spec}/support/shared_contexts/ja_locale.rb (100%) rename {spec => structured_params/spec}/support/test_classes/form_object_classes.rb (100%) rename {spec => structured_params/spec}/support/test_classes/params_classes.rb (100%) rename {spec => structured_params/spec}/type/array_spec.rb (100%) rename {spec => structured_params/spec}/type/object_spec.rb (100%) rename {spec => structured_params/spec}/validations_spec.rb (100%) rename structured_params.gemspec => structured_params/structured_params.gemspec (96%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dca9870..ab69971 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -56,21 +56,21 @@ jobs: echo "" >> temp_changelog.md # Prepend to existing CHANGELOG (skip the header) - if [ -f CHANGELOG.md ]; then - tail -n +3 CHANGELOG.md >> temp_changelog.md + if [ -f structured_params/CHANGELOG.md ]; then + tail -n +3 structured_params/CHANGELOG.md >> temp_changelog.md fi # Add header back - echo "# Changelog" > CHANGELOG.md - echo "" >> CHANGELOG.md - cat temp_changelog.md >> CHANGELOG.md + echo "# Changelog" > structured_params/CHANGELOG.md + echo "" >> structured_params/CHANGELOG.md + cat temp_changelog.md >> structured_params/CHANGELOG.md # Clean up temporary file rm -f temp_changelog.md - name: Commit CHANGELOG update run: | - git add CHANGELOG.md + git add structured_params/CHANGELOG.md if git diff --staged --quiet; then echo "No CHANGELOG changes to commit" else @@ -85,6 +85,7 @@ jobs: bundler-cache: true - name: Build gem + working-directory: structured_params run: | gem build structured_params.gemspec diff --git a/.github/workflows/tagging.yml b/.github/workflows/tagging.yml index 8fc1e11..45f9057 100644 --- a/.github/workflows/tagging.yml +++ b/.github/workflows/tagging.yml @@ -32,11 +32,11 @@ jobs: - name: Update version file run: | VERSION="${{ steps.extract_version.outputs.version }}" - sed -i "s/VERSION = '[^']*'/VERSION = '$VERSION'/" lib/structured_params/version.rb + sed -i "s/VERSION = '[^']*'/VERSION = '$VERSION'/" structured_params/lib/structured_params/version.rb - name: Commit version update run: | - git add lib/structured_params/version.rb + git add structured_params/lib/structured_params/version.rb if git diff --staged --quiet; then echo "No version changes to commit" else diff --git a/.gitignore b/.gitignore index 46688bd..6e5774c 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ Gemfile.lock /.config /coverage/ /InstalledFiles -/pkg/ +pkg/ /spec/reports/ /spec/examples.txt /test/tmp/ diff --git a/.rubocop.yml b/.rubocop.yml index 03edc96..8d1cae2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,10 +5,18 @@ plugins: AllCops: NewCops: enable + # Both gemspecs require Ruby >= 3.2.0; RuboCop cannot infer it from a gemspec in a subdirectory. + TargetRubyVersion: 3.2 Style/OneClassPerFile: Exclude: - - spec/support/test_classes/**/* + - '**/spec/support/test_classes/**/*' + +# RuboCop's default excludes match spec/ at the repository root only. +Style/Documentation: + Exclude: + - '**/spec/**/*' + - '**/test/**/*' Layout/LeadingCommentSpace: Enabled: false diff --git a/.rubocop_rbs.yml b/.rubocop_rbs.yml index 704a13a..3171f62 100644 --- a/.rubocop_rbs.yml +++ b/.rubocop_rbs.yml @@ -11,8 +11,8 @@ Style/RbsInline/MissingTypeAnnotation: - '**/spec/**/*' Style/RbsInline/UntypedInstanceVariable: Exclude: - - 'lib/structured_params/params.rb' - - 'lib/structured_params.rb' + - 'structured_params/lib/structured_params/params.rb' + - 'structured_params/lib/structured_params.rb' - 'structured_params-openapi/lib/structured_params/openapi/configuration.rb' - 'structured_params-openapi/lib/structured_params/openapi/registry.rb' diff --git a/AGENTS.md b/AGENTS.md index a66deac..72c9328 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -5,22 +5,23 @@ ## プロジェクト概要 - `structured_params` は Rails 向けの型付きパラメータ/フォームオブジェクト用 gem です。 -- コア実装は `lib/structured_params/` 配下にあります。 +- このリポジトリには 2 つの gem があり、それぞれ独自のフォルダを持ちます。コア gem は `structured_params/`、OpenAPI drift check は `structured_params-openapi/` です。 +- コア実装は `structured_params/lib/structured_params/` 配下にあります。 - テストは RSpec、Lint は RuboCop、型検査は Steep を使います。 - RBS シグネチャは `rbs-inline` から生成されます。 ## 主要ディレクトリ -- `structured_params-openapi/`: OpenAPI drift check の別 gem(`structured_params-openapi`)。 - 独自の `lib/`・`sig/`・`spec/`・`docs/` と gemspec を持ちます。コアとは同じリポジトリで管理し、 - テストは `cd structured_params-openapi && bundle exec rspec` で実行します。 +- `structured_params/`: コア gem。`lib/`・`sig/`・`spec/`・`docs/`・`structured_params.gemspec`・`CHANGELOG.md` を持ちます。 +- `structured_params-openapi/`: OpenAPI drift check の別 gem。同じ構成の独自の `lib/`・`sig/`・`spec/`・`docs/` と gemspec を持ちます。 +- リポジトリ直下: `README.md`、`Gemfile`、`Rakefile`、`Steepfile`、`lefthook.yml`、RuboCop 設定など、両方の gem に共通のもの。 -- `lib/structured_params.rb`: エントリーポイント -- `lib/structured_params/params.rb`: コアの `Params` 実装 -- `lib/structured_params/type/`: `array` / `object` 型ハンドラ -- `spec/`: RSpec テスト -- `docs/`: 利用者向けドキュメント -- `sig/`: `rbs-inline` により生成された RBS +- `structured_params/lib/structured_params.rb`: エントリーポイント +- `structured_params/lib/structured_params/params.rb`: コアの `Params` 実装 +- `structured_params/lib/structured_params/type/`: `array` / `object` 型ハンドラ +- `structured_params/spec/`: RSpec テスト +- `structured_params/docs/`: 利用者向けドキュメント +- `structured_params/sig/`: `rbs-inline` により生成された RBS ## セットアップと実行 @@ -43,13 +44,13 @@ Ruby 3.2 系では `steep` や `.rubocop_rbs.yml` 前提のチェックが使え 個別実行例: ```bash -bundle exec rspec spec/params_spec.rb -bundle exec rubocop lib/structured_params/params.rb +(cd structured_params && bundle exec rspec spec/params_spec.rb) +bundle exec rubocop structured_params/lib/structured_params/params.rb ``` ## 変更時のルール -- `sig/**/*.rbs` は手編集しないでください。必要なら `bundle exec rbs-inline --output=sig lib/**/*.rb` で再生成します。 +- `sig/**/*.rbs` は手編集しないでください。必要なら各 gem のフォルダ(`structured_params/` など)で `bundle exec rbs-inline --output=sig lib/**/*.rb` を実行して再生成します。 - Ruby メソッドの型注釈は `rbs-inline` の `method_type_signature` スタイルを使ってください。 - インスタンス変数の型注釈は `# @rbs` コメントを使ってください。 - 既存の公開 API を変える場合は、README と `docs/` の整合も確認してください。 @@ -58,16 +59,16 @@ bundle exec rubocop lib/structured_params/params.rb ## テスト方針 - 振る舞い変更には RSpec を追加または更新してください。 -- 既存 spec のスタイルに合わせ、必要に応じて `spec/factories/` と `spec/support/` を再利用してください。 +- 既存 spec のスタイルに合わせ、必要に応じて `structured_params/spec/factories/` と `structured_params/spec/support/` を再利用してください。 - 修正が型やシリアライズ、permit 生成に関わる場合は、関連 spec を広めに実行してください。 ## コミット前チェック `lefthook.yml` によりコミット前に以下が走ります。 -- `bundle exec rbs-inline --output=sig lib/**/*.rb`(`structured_params-openapi/` でも同様) +- 各 gem のフォルダでの `bundle exec rbs-inline --output=sig lib/**/*.rb`(`structured_params/` と `structured_params-openapi/`) - `bundle exec rubocop` -- `bundle exec rspec`(`structured_params-openapi/` でも実行) +- 各 gem のフォルダでの `bundle exec rspec`(`structured_params/` と `structured_params-openapi/`) - `bundle exec steep check` フックで失敗しない状態まで揃えてから完了扱いにしてください。 @@ -81,4 +82,4 @@ bundle exec rubocop lib/structured_params/params.rb - エラーフォーマットやバリデーション挙動の変更 - Rails / Ruby サポート範囲の変更 -利用者向け概要は `README.md`、詳細仕様は `docs/*.md`、日本語 README が必要なら `README_ja.md` も更新します。 +利用者向け概要は `README.md`、詳細仕様は `structured_params/docs/*.md`、日本語 README が必要なら `README_ja.md` も更新します。 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2c589d0..e76026f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,7 +25,15 @@ bin/setup ### Running Tests ```bash -# Run all tests +# Run the specs of every gem (from the repository root) +bundle exec rake spec + +# The repository holds two gems, each in its own folder: +# structured_params/ the core gem +# structured_params-openapi/ the OpenAPI drift check gem +cd structured_params + +# Run all tests of the gem bundle exec rspec # Run specific test file @@ -62,15 +70,15 @@ Automatically regenerate signatures on file changes: ./bin/dev ``` -This command uses `fswatch` to monitor the `lib/` directory and automatically runs `rbs-inline` when files change. +This command uses `fswatch` to monitor the `lib/` directory of each gem and automatically runs `rbs-inline` when files change. ### Manual Generation Generate all signatures manually: ```bash -# Generate for all lib files -bundle exec rbs-inline --output=sig lib/**/*.rb +# Generate for all lib files (run inside each gem folder, e.g. structured_params/) +cd structured_params && bundle exec rbs-inline --output=sig lib/**/*.rb ``` ### Automatic Generation (Git Hooks) @@ -88,7 +96,7 @@ The git hook configuration is in `lefthook.yml`: prepare-commit-msg: commands: rbs-inline: - run: bundle exec rbs-inline --output=sig lib/**/*.rb + run: (cd structured_params && bundle exec rbs-inline --output=sig lib/**/*.rb) && ... ``` ## Coding Style @@ -176,23 +184,26 @@ RAILS_VERSION="~> 8.0.0" bundle update && bundle exec rspec ## Project Structure ``` -structured_params/ -├── lib/ -│ ├── structured_params.rb # Main entry point -│ ├── structured_params/ -│ │ ├── params.rb # Core Params class -│ │ ├── errors.rb # Enhanced error handling -│ │ ├── version.rb # Version constant -│ │ └── type/ -│ │ ├── array.rb # Array type handler -│ │ └── object.rb # Object type handler -├── sig/ # Auto-generated RBS files -│ └── generated/ # DO NOT EDIT -├── spec/ # RSpec tests -│ ├── factories/ # Test parameter classes -│ ├── support/ # Test helpers -│ └── *_spec.rb # Test files -└── docs/ # Documentation +. # repository root: README, Gemfile, Rakefile, Steepfile, lefthook.yml, RuboCop config +├── structured_params/ # core gem +│ ├── structured_params.gemspec +│ ├── CHANGELOG.md +│ ├── lib/ +│ │ ├── structured_params.rb # Main entry point +│ │ └── structured_params/ +│ │ ├── params.rb # Core Params class +│ │ ├── errors.rb # Enhanced error handling +│ │ ├── version.rb # Version constant +│ │ └── type/ +│ │ ├── array.rb # Array type handler +│ │ └── object.rb # Object type handler +│ ├── sig/ # Auto-generated RBS files (DO NOT EDIT) +│ ├── spec/ # RSpec tests +│ │ ├── factories/ # Test parameter classes +│ │ ├── support/ # Test helpers +│ │ └── *_spec.rb # Test files +│ └── docs/ # Documentation +└── structured_params-openapi/ # OpenAPI drift check gem (same layout) ``` ## Submitting Changes diff --git a/Gemfile b/Gemfile index d70f085..46caa11 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' -gemspec +gemspec path: 'structured_params' gemspec path: 'structured_params-openapi' # Allow testing different Rails versions via environment variable diff --git a/Procfile.dev b/Procfile.dev index f1902a5..f0c8dc2 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1 +1,2 @@ -rbs-inline: fswatch -0 lib | xargs -0 -n1 bundle exec rbs-inline --output=sig +rbs-inline: sh -c 'cd structured_params && fswatch -0 lib | xargs -0 -n1 bundle exec rbs-inline --output=sig' +rbs-inline-openapi: sh -c 'cd structured_params-openapi && fswatch -0 lib | xargs -0 -n1 bundle exec rbs-inline --output=sig' diff --git a/README.md b/README.md index 51f4aa9..234c04d 100644 --- a/README.md +++ b/README.md @@ -123,14 +123,14 @@ bundle exec rake structured_params:openapi:drift_check ## Documentation -- **[Installation and Setup](docs/installation.md)** - Getting started with StructuredParams -- **[Basic Usage](docs/basic-usage.md)** - Parameter classes, nested objects, and arrays -- **[Validation](docs/validation.md)** - Using ActiveModel validations with nested structures +- **[Installation and Setup](structured_params/docs/installation.md)** - Getting started with StructuredParams +- **[Basic Usage](structured_params/docs/basic-usage.md)** - Parameter classes, nested objects, and arrays +- **[Validation](structured_params/docs/validation.md)** - Using ActiveModel validations with nested structures - **[OpenAPI Drift Check](structured_params-openapi/docs/drift-check.md)** - Detect differences between request schemas and Params classes (`structured_params-openapi` gem) -- **[Strong Parameters](docs/strong-parameters.md)** - Automatic permit list generation -- **[Error Handling](docs/error-handling.md)** - Flat and structured error formats -- **[Serialization](docs/serialization.md)** - Converting parameters to hashes and JSON -- **[Form Objects](docs/form-objects.md)** - Form object pattern with Rails views +- **[Strong Parameters](structured_params/docs/strong-parameters.md)** - Automatic permit list generation +- **[Error Handling](structured_params/docs/error-handling.md)** - Flat and structured error formats +- **[Serialization](structured_params/docs/serialization.md)** - Converting parameters to hashes and JSON +- **[Form Objects](structured_params/docs/form-objects.md)** - Form object pattern with Rails views ## Contributing diff --git a/README_ja.md b/README_ja.md index 8e85ef4..09b6508 100644 --- a/README_ja.md +++ b/README_ja.md @@ -123,14 +123,14 @@ bundle exec rake structured_params:openapi:drift_check ## ドキュメント -- **[インストールとセットアップ](docs/installation.md)** - StructuredParams の始め方 -- **[基本的な使い方](docs/basic-usage.md)** - パラメータクラス、ネストオブジェクト、配列 -- **[バリデーション](docs/validation.md)** - ネスト構造での ActiveModel バリデーション +- **[インストールとセットアップ](structured_params/docs/installation.md)** - StructuredParams の始め方 +- **[基本的な使い方](structured_params/docs/basic-usage.md)** - パラメータクラス、ネストオブジェクト、配列 +- **[バリデーション](structured_params/docs/validation.md)** - ネスト構造での ActiveModel バリデーション - **[OpenAPI Drift Check](structured_params-openapi/docs/drift-check_ja.md)** - OpenAPI schema と Params class の乖離検出(`structured_params-openapi` gem) -- **[Strong Parameters](docs/strong-parameters.md)** - permit リストの自動生成 -- **[エラーハンドリング](docs/error-handling.md)** - フラット形式と構造化形式のエラー -- **[シリアライゼーション](docs/serialization.md)** - パラメータのハッシュと JSON 変換 -- **[フォームオブジェクト](docs/form-objects.md)** - Rails ビューとのフォームオブジェクトパターン +- **[Strong Parameters](structured_params/docs/strong-parameters.md)** - permit リストの自動生成 +- **[エラーハンドリング](structured_params/docs/error-handling.md)** - フラット形式と構造化形式のエラー +- **[シリアライゼーション](structured_params/docs/serialization.md)** - パラメータのハッシュと JSON 変換 +- **[フォームオブジェクト](structured_params/docs/form-objects.md)** - Rails ビューとのフォームオブジェクトパターン ## コントリビューション diff --git a/Rakefile b/Rakefile index 0b01eab..ae02914 100644 --- a/Rakefile +++ b/Rakefile @@ -1,12 +1,24 @@ # frozen_string_literal: true # rbs_inline: enabled -require 'bundler/gem_tasks' -require 'rspec/core/rake_task' +require 'bundler/gem_helper' +require 'rubocop/rake_task' -RSpec::Core::RakeTask.new(:spec) +# The repository holds two gems, each in its own directory with its own spec suite. +# `rake build`/`install`/`release` act on the core gem; build the others from their directory. +GEM_DIRS = %w[structured_params structured_params-openapi].freeze #: Array[String] -require 'rubocop/rake_task' +Bundler::GemHelper.install_tasks(dir: 'structured_params', name: 'structured_params') + +GEM_DIRS.each do |gem_dir| + desc "Run the #{gem_dir} specs" + task "spec:#{gem_dir}" do + Dir.chdir(gem_dir) { sh 'bundle exec rspec' } + end +end + +desc 'Run the specs of every gem' +task spec: GEM_DIRS.map { |gem_dir| "spec:#{gem_dir}" } # Use RBS Inline configuration for Ruby 3.3+ rubocop_config = if RUBY_VERSION >= '3.3.0' @@ -28,11 +40,4 @@ if RUBY_VERSION >= '3.3.0' default_tasks << :steep end -# The OpenAPI plugin lives in its own gem directory with its own spec suite. -desc 'Run the structured_params-openapi specs' -task :spec_openapi do - Dir.chdir('structured_params-openapi') { sh 'bundle exec rspec' } -end -default_tasks << :spec_openapi - task default: default_tasks diff --git a/Steepfile b/Steepfile index fb68fbe..016d827 100644 --- a/Steepfile +++ b/Steepfile @@ -3,9 +3,9 @@ # D = Steep::Diagnostic target :lib do - signature 'sig' + signature 'structured_params/sig' - check 'lib' + check 'structured_params/lib' # Suppress errors from broken library RBS files in gem_rbs_collection configure_code_diagnostics do |hash| @@ -14,7 +14,7 @@ target :lib do end target :openapi do - signature 'sig', 'structured_params-openapi/sig' + signature 'structured_params/sig', 'structured_params-openapi/sig' check 'structured_params-openapi/lib' diff --git a/bin/console b/bin/console index 4fdf31d..b8263b7 100755 --- a/bin/console +++ b/bin/console @@ -9,7 +9,7 @@ require 'structured_params' # with your gem easier. You can also use a different console, if you like. require 'factory_bot' StructuredParams.register_types -FactoryBot.definition_file_paths = [File.expand_path('../spec/factories', __dir__)] +FactoryBot.definition_file_paths = [File.expand_path('../structured_params/spec/factories', __dir__)] FactoryBot.find_definitions require 'irb' diff --git a/lefthook.yml b/lefthook.yml index 2ddee2e..e79692b 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -1,14 +1,14 @@ prepare-commit-msg: commands: rbs-inline: - run: bundle exec rbs-inline --output=sig lib/**/*.rb && (cd structured_params-openapi && bundle exec rbs-inline --output=sig lib/**/*.rb) && git add sig/ structured_params-openapi/sig/ + run: (cd structured_params && bundle exec rbs-inline --output=sig lib/**/*.rb) && (cd structured_params-openapi && bundle exec rbs-inline --output=sig lib/**/*.rb) && git add structured_params/sig/ structured_params-openapi/sig/ pre-commit: commands: rubocop: run: ./bin/rubocop rspec: - run: bundle exec rspec + run: cd structured_params && bundle exec rspec rspec-open-api: run: cd structured_params-openapi && bundle exec rspec steep: diff --git a/.rspec b/structured_params/.rspec similarity index 100% rename from .rspec rename to structured_params/.rspec diff --git a/CHANGELOG.md b/structured_params/CHANGELOG.md similarity index 100% rename from CHANGELOG.md rename to structured_params/CHANGELOG.md diff --git a/structured_params/LICENSE.txt b/structured_params/LICENSE.txt new file mode 100644 index 0000000..0626645 --- /dev/null +++ b/structured_params/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2024 Mizuki Yamamoto + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/docs/basic-usage.md b/structured_params/docs/basic-usage.md similarity index 100% rename from docs/basic-usage.md rename to structured_params/docs/basic-usage.md diff --git a/docs/error-handling.md b/structured_params/docs/error-handling.md similarity index 100% rename from docs/error-handling.md rename to structured_params/docs/error-handling.md diff --git a/docs/form-objects.md b/structured_params/docs/form-objects.md similarity index 100% rename from docs/form-objects.md rename to structured_params/docs/form-objects.md diff --git a/docs/installation.md b/structured_params/docs/installation.md similarity index 100% rename from docs/installation.md rename to structured_params/docs/installation.md diff --git a/docs/serialization.md b/structured_params/docs/serialization.md similarity index 100% rename from docs/serialization.md rename to structured_params/docs/serialization.md diff --git a/docs/strong-parameters.md b/structured_params/docs/strong-parameters.md similarity index 100% rename from docs/strong-parameters.md rename to structured_params/docs/strong-parameters.md diff --git a/docs/validation.md b/structured_params/docs/validation.md similarity index 100% rename from docs/validation.md rename to structured_params/docs/validation.md diff --git a/lib/structured_params.rb b/structured_params/lib/structured_params.rb similarity index 100% rename from lib/structured_params.rb rename to structured_params/lib/structured_params.rb diff --git a/lib/structured_params/attribute_methods.rb b/structured_params/lib/structured_params/attribute_methods.rb similarity index 100% rename from lib/structured_params/attribute_methods.rb rename to structured_params/lib/structured_params/attribute_methods.rb diff --git a/lib/structured_params/errors.rb b/structured_params/lib/structured_params/errors.rb similarity index 100% rename from lib/structured_params/errors.rb rename to structured_params/lib/structured_params/errors.rb diff --git a/lib/structured_params/i18n.rb b/structured_params/lib/structured_params/i18n.rb similarity index 100% rename from lib/structured_params/i18n.rb rename to structured_params/lib/structured_params/i18n.rb diff --git a/lib/structured_params/params.rb b/structured_params/lib/structured_params/params.rb similarity index 100% rename from lib/structured_params/params.rb rename to structured_params/lib/structured_params/params.rb diff --git a/lib/structured_params/type/array.rb b/structured_params/lib/structured_params/type/array.rb similarity index 100% rename from lib/structured_params/type/array.rb rename to structured_params/lib/structured_params/type/array.rb diff --git a/lib/structured_params/type/object.rb b/structured_params/lib/structured_params/type/object.rb similarity index 100% rename from lib/structured_params/type/object.rb rename to structured_params/lib/structured_params/type/object.rb diff --git a/lib/structured_params/validations.rb b/structured_params/lib/structured_params/validations.rb similarity index 100% rename from lib/structured_params/validations.rb rename to structured_params/lib/structured_params/validations.rb diff --git a/lib/structured_params/version.rb b/structured_params/lib/structured_params/version.rb similarity index 100% rename from lib/structured_params/version.rb rename to structured_params/lib/structured_params/version.rb diff --git a/sig/structured_params.rbs b/structured_params/sig/structured_params.rbs similarity index 100% rename from sig/structured_params.rbs rename to structured_params/sig/structured_params.rbs diff --git a/sig/structured_params/attribute_methods.rbs b/structured_params/sig/structured_params/attribute_methods.rbs similarity index 100% rename from sig/structured_params/attribute_methods.rbs rename to structured_params/sig/structured_params/attribute_methods.rbs diff --git a/sig/structured_params/errors.rbs b/structured_params/sig/structured_params/errors.rbs similarity index 100% rename from sig/structured_params/errors.rbs rename to structured_params/sig/structured_params/errors.rbs diff --git a/sig/structured_params/i18n.rbs b/structured_params/sig/structured_params/i18n.rbs similarity index 100% rename from sig/structured_params/i18n.rbs rename to structured_params/sig/structured_params/i18n.rbs diff --git a/sig/structured_params/params.rbs b/structured_params/sig/structured_params/params.rbs similarity index 100% rename from sig/structured_params/params.rbs rename to structured_params/sig/structured_params/params.rbs diff --git a/sig/structured_params/type/array.rbs b/structured_params/sig/structured_params/type/array.rbs similarity index 100% rename from sig/structured_params/type/array.rbs rename to structured_params/sig/structured_params/type/array.rbs diff --git a/sig/structured_params/type/object.rbs b/structured_params/sig/structured_params/type/object.rbs similarity index 100% rename from sig/structured_params/type/object.rbs rename to structured_params/sig/structured_params/type/object.rbs diff --git a/sig/structured_params/validations.rbs b/structured_params/sig/structured_params/validations.rbs similarity index 100% rename from sig/structured_params/validations.rbs rename to structured_params/sig/structured_params/validations.rbs diff --git a/sig/structured_params/version.rbs b/structured_params/sig/structured_params/version.rbs similarity index 100% rename from sig/structured_params/version.rbs rename to structured_params/sig/structured_params/version.rbs diff --git a/spec/attribute_methods_spec.rb b/structured_params/spec/attribute_methods_spec.rb similarity index 100% rename from spec/attribute_methods_spec.rb rename to structured_params/spec/attribute_methods_spec.rb diff --git a/spec/errors_spec.rb b/structured_params/spec/errors_spec.rb similarity index 100% rename from spec/errors_spec.rb rename to structured_params/spec/errors_spec.rb diff --git a/spec/factories/address_parameters.rb b/structured_params/spec/factories/address_parameters.rb similarity index 100% rename from spec/factories/address_parameters.rb rename to structured_params/spec/factories/address_parameters.rb diff --git a/spec/factories/hobby_parameters.rb b/structured_params/spec/factories/hobby_parameters.rb similarity index 100% rename from spec/factories/hobby_parameters.rb rename to structured_params/spec/factories/hobby_parameters.rb diff --git a/spec/factories/user_parameters.rb b/structured_params/spec/factories/user_parameters.rb similarity index 100% rename from spec/factories/user_parameters.rb rename to structured_params/spec/factories/user_parameters.rb diff --git a/spec/form_object_spec.rb b/structured_params/spec/form_object_spec.rb similarity index 100% rename from spec/form_object_spec.rb rename to structured_params/spec/form_object_spec.rb diff --git a/spec/i18n_spec.rb b/structured_params/spec/i18n_spec.rb similarity index 100% rename from spec/i18n_spec.rb rename to structured_params/spec/i18n_spec.rb diff --git a/spec/params_spec.rb b/structured_params/spec/params_spec.rb similarity index 100% rename from spec/params_spec.rb rename to structured_params/spec/params_spec.rb diff --git a/spec/permit_spec.rb b/structured_params/spec/permit_spec.rb similarity index 100% rename from spec/permit_spec.rb rename to structured_params/spec/permit_spec.rb diff --git a/spec/spec_helper.rb b/structured_params/spec/spec_helper.rb similarity index 100% rename from spec/spec_helper.rb rename to structured_params/spec/spec_helper.rb diff --git a/spec/support/locales/ja.yml b/structured_params/spec/support/locales/ja.yml similarity index 100% rename from spec/support/locales/ja.yml rename to structured_params/spec/support/locales/ja.yml diff --git a/spec/support/shared_contexts/ja_locale.rb b/structured_params/spec/support/shared_contexts/ja_locale.rb similarity index 100% rename from spec/support/shared_contexts/ja_locale.rb rename to structured_params/spec/support/shared_contexts/ja_locale.rb diff --git a/spec/support/test_classes/form_object_classes.rb b/structured_params/spec/support/test_classes/form_object_classes.rb similarity index 100% rename from spec/support/test_classes/form_object_classes.rb rename to structured_params/spec/support/test_classes/form_object_classes.rb diff --git a/spec/support/test_classes/params_classes.rb b/structured_params/spec/support/test_classes/params_classes.rb similarity index 100% rename from spec/support/test_classes/params_classes.rb rename to structured_params/spec/support/test_classes/params_classes.rb diff --git a/spec/type/array_spec.rb b/structured_params/spec/type/array_spec.rb similarity index 100% rename from spec/type/array_spec.rb rename to structured_params/spec/type/array_spec.rb diff --git a/spec/type/object_spec.rb b/structured_params/spec/type/object_spec.rb similarity index 100% rename from spec/type/object_spec.rb rename to structured_params/spec/type/object_spec.rb diff --git a/spec/validations_spec.rb b/structured_params/spec/validations_spec.rb similarity index 100% rename from spec/validations_spec.rb rename to structured_params/spec/validations_spec.rb diff --git a/structured_params.gemspec b/structured_params/structured_params.gemspec similarity index 96% rename from structured_params.gemspec rename to structured_params/structured_params.gemspec index 0489492..b1404f2 100644 --- a/structured_params.gemspec +++ b/structured_params/structured_params.gemspec @@ -28,7 +28,7 @@ Gem::Specification.new do |spec| spec.metadata = { 'homepage_uri' => 'https://github.com/Syati/structured_params#readme', - 'changelog_uri' => 'https://github.com/Syati/structured_params/blob/main/CHANGELOG.md', + 'changelog_uri' => 'https://github.com/Syati/structured_params/blob/main/structured_params/CHANGELOG.md', 'bug_tracker_uri' => 'https://github.com/Syati/structured_params/issues', 'source_code_uri' => 'https://github.com/Syati/structured_params', 'rubygems_mfa_required' => 'true' From 35bd567c1b3ff167a2ad5a6633ae013ccad016b2 Mon Sep 17 00:00:00 2001 From: mizuki-y Date: Mon, 12 Oct 2026 20:28:45 +0900 Subject: [PATCH 2/3] fix: release the core gem from its own folder with a per-gem Rakefile rubygems/release-gem waits for pkg/*.gem in its working directory, but the gem is built under the gem folder's own pkg/. Give structured_params/ a Rakefile with bundler/gem_tasks and run release-gem with working-directory: structured_params instead of routing it through the root Rakefile. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/release.yml | 2 ++ Rakefile | 7 ++----- structured_params/Rakefile | 6 ++++++ 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 structured_params/Rakefile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ab69971..5cb613b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -91,3 +91,5 @@ jobs: - name: Publish to RubyGems uses: rubygems/release-gem@v1 + with: + working-directory: structured_params diff --git a/Rakefile b/Rakefile index ae02914..441aa0a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,15 +1,12 @@ # frozen_string_literal: true # rbs_inline: enabled -require 'bundler/gem_helper' require 'rubocop/rake_task' -# The repository holds two gems, each in its own directory with its own spec suite. -# `rake build`/`install`/`release` act on the core gem; build the others from their directory. +# The repository holds two gems, each in its own directory with its own spec suite and its +# own Rakefile for `build`/`install`/`release` (run those from the gem's directory). GEM_DIRS = %w[structured_params structured_params-openapi].freeze #: Array[String] -Bundler::GemHelper.install_tasks(dir: 'structured_params', name: 'structured_params') - GEM_DIRS.each do |gem_dir| desc "Run the #{gem_dir} specs" task "spec:#{gem_dir}" do diff --git a/structured_params/Rakefile b/structured_params/Rakefile new file mode 100644 index 0000000..fa8fbc4 --- /dev/null +++ b/structured_params/Rakefile @@ -0,0 +1,6 @@ +# frozen_string_literal: true +# rbs_inline: enabled + +# Release tasks (`rake build`, `rake release`) for this gem; run them from this directory. +# The repository-wide checks (specs, RuboCop, Steep) live in the root Rakefile. +require 'bundler/gem_tasks' From fce2e68bf029f3762c88f362c097815f574bae1d Mon Sep 17 00:00:00 2001 From: mizuki-y Date: Tue, 13 Oct 2026 07:44:47 +0900 Subject: [PATCH 3/3] fix: regenerate RBS for every lib file and point docs at rake spec - lefthook ran `rbs-inline lib/**/*.rb` under sh, where ** matches a single directory level, so nested files such as lib/structured_params/type/*.rb were skipped (6 of 9 files). Pass the lib directory instead, which rbs-inline processes recursively. Same change in CONTRIBUTING.md and AGENTS.md. - Replace the root-level `bundle exec rspec` instructions with `bundle exec rake spec`, which runs both gem suites. Co-Authored-By: Claude Sonnet 5.5 --- AGENTS.md | 6 +++--- CONTRIBUTING.md | 10 +++++----- lefthook.yml | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 72c9328..1f96a9e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -34,7 +34,7 @@ bin/setup 通常の確認: ```bash -bundle exec rspec +bundle exec rake spec # 両方の gem の spec(各 gem のフォルダで bundle exec rspec でも可) bundle exec rubocop bundle exec steep check ``` @@ -50,7 +50,7 @@ bundle exec rubocop structured_params/lib/structured_params/params.rb ## 変更時のルール -- `sig/**/*.rbs` は手編集しないでください。必要なら各 gem のフォルダ(`structured_params/` など)で `bundle exec rbs-inline --output=sig lib/**/*.rb` を実行して再生成します。 +- `sig/**/*.rbs` は手編集しないでください。必要なら各 gem のフォルダ(`structured_params/` など)で `bundle exec rbs-inline --output=sig lib` を実行して再生成します。 - Ruby メソッドの型注釈は `rbs-inline` の `method_type_signature` スタイルを使ってください。 - インスタンス変数の型注釈は `# @rbs` コメントを使ってください。 - 既存の公開 API を変える場合は、README と `docs/` の整合も確認してください。 @@ -66,7 +66,7 @@ bundle exec rubocop structured_params/lib/structured_params/params.rb `lefthook.yml` によりコミット前に以下が走ります。 -- 各 gem のフォルダでの `bundle exec rbs-inline --output=sig lib/**/*.rb`(`structured_params/` と `structured_params-openapi/`) +- 各 gem のフォルダでの `bundle exec rbs-inline --output=sig lib`(`structured_params/` と `structured_params-openapi/`) - `bundle exec rubocop` - 各 gem のフォルダでの `bundle exec rspec`(`structured_params/` と `structured_params-openapi/`) - `bundle exec steep check` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e76026f..1850818 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -78,7 +78,7 @@ Generate all signatures manually: ```bash # Generate for all lib files (run inside each gem folder, e.g. structured_params/) -cd structured_params && bundle exec rbs-inline --output=sig lib/**/*.rb +cd structured_params && bundle exec rbs-inline --output=sig lib ``` ### Automatic Generation (Git Hooks) @@ -96,7 +96,7 @@ The git hook configuration is in `lefthook.yml`: prepare-commit-msg: commands: rbs-inline: - run: (cd structured_params && bundle exec rbs-inline --output=sig lib/**/*.rb) && ... + run: (cd structured_params && bundle exec rbs-inline --output=sig lib) && ... ``` ## Coding Style @@ -175,10 +175,10 @@ You can test against different Rails versions using the `RAILS_VERSION` environm ```bash # Test with Rails 7.2 -RAILS_VERSION="~> 7.2.0" bundle update && bundle exec rspec +RAILS_VERSION="~> 7.2.0" bundle update && bundle exec rake spec # Test with Rails 8.0 -RAILS_VERSION="~> 8.0.0" bundle update && bundle exec rspec +RAILS_VERSION="~> 8.0.0" bundle update && bundle exec rake spec ``` ## Project Structure @@ -213,7 +213,7 @@ RAILS_VERSION="~> 8.0.0" bundle update && bundle exec rspec 1. **Fork the repository** and create your branch from `main` 2. **Write tests** for your changes 3. **Update documentation** if needed (README, docs/, inline comments) -4. **Ensure all tests pass**: `bundle exec rspec` +4. **Ensure all tests pass**: `bundle exec rake spec` 5. **Ensure code quality**: `bundle exec rubocop` 6. **Ensure type safety** (Ruby 3.3+): `bundle exec steep check` 7. **RBS signatures will be auto-generated** by git hooks diff --git a/lefthook.yml b/lefthook.yml index e79692b..8418c52 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -1,7 +1,7 @@ prepare-commit-msg: commands: rbs-inline: - run: (cd structured_params && bundle exec rbs-inline --output=sig lib/**/*.rb) && (cd structured_params-openapi && bundle exec rbs-inline --output=sig lib/**/*.rb) && git add structured_params/sig/ structured_params-openapi/sig/ + run: (cd structured_params && bundle exec rbs-inline --output=sig lib) && (cd structured_params-openapi && bundle exec rbs-inline --output=sig lib) && git add structured_params/sig/ structured_params-openapi/sig/ pre-commit: commands: