azeroth 2.2.0 → 2.3.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +21 -10
  3. data/.claude/agents/architect.md +55 -0
  4. data/.claude/agents/docs.md +38 -0
  5. data/.claude/agents/ruby.md +48 -0
  6. data/.claude/agents/security.md +27 -0
  7. data/.claude/configuration/auto-fix-all.json +3 -0
  8. data/.claude/scripts/check_ruby.sh +8 -0
  9. data/.github/commit_message_template.md +8 -0
  10. data/.github/copilot-instructions.md +1 -70
  11. data/.github/pull_request_template.md +17 -0
  12. data/.gitignore +1 -0
  13. data/AGENTS.md +103 -0
  14. data/CLAUDE.md +1 -0
  15. data/Dockerfile +2 -2
  16. data/Gemfile +20 -17
  17. data/README.md +8 -8
  18. data/azeroth.gemspec +3 -3
  19. data/azeroth.jpg +0 -0
  20. data/docs/agents/architecture.md +79 -0
  21. data/docs/agents/contributing.md +195 -0
  22. data/docs/agents/flow.md +5 -0
  23. data/docs/agents/folder-structure.md +43 -0
  24. data/docs/agents/issue-enhancement.md +10 -0
  25. data/docs/agents/issues/.gitkeep +1 -0
  26. data/docs/agents/plans/.gitkeep +1 -0
  27. data/docs/guides/azeroth/basic-usage.md +66 -0
  28. data/docs/guides/azeroth/best-practices.md +9 -0
  29. data/docs/guides/azeroth/decorators.md +58 -0
  30. data/docs/guides/azeroth/installation.md +15 -0
  31. data/docs/guides/azeroth/model-for.md +40 -0
  32. data/docs/guides/azeroth/resource-for-options.md +64 -0
  33. data/docs/guides/azeroth/testing.md +30 -0
  34. data/docs/guides/azeroth-usage.md +28 -0
  35. data/lib/azeroth/version.rb +1 -1
  36. data/scripts/bump_version.sh +62 -0
  37. data/spec/dummy/bin/setup +1 -2
  38. data/spec/dummy/bin/update +1 -2
  39. data/spec/dummy/db/schema.rb +2 -2
  40. metadata +35 -13
  41. data/.github/azeroth-usage.md +0 -277
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env bash
2
+ # Usage: scripts/bump_version.sh [major|minor|patch|X.Y.Z]
3
+ # Without arguments, bumps the patch version of the current version.
4
+
5
+ set -euo pipefail
6
+
7
+ ROOT="$(git rev-parse --show-toplevel)"
8
+ README="$ROOT/README.md"
9
+ VERSION_FILE="$ROOT/lib/azeroth/version.rb"
10
+ LOCKFILE="$ROOT/Gemfile.lock"
11
+ GEM="azeroth"
12
+
13
+ current=$(grep -oE "VERSION = '[0-9]+\.[0-9]+\.[0-9]+'" "$VERSION_FILE" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
14
+ IFS='.' read -r cmajor cminor cpatch <<< "$current"
15
+
16
+ arg="${1:-patch}"
17
+
18
+ case "$arg" in
19
+ major) new_version="$((cmajor + 1)).0.0" ;;
20
+ minor) new_version="${cmajor}.$((cminor + 1)).0" ;;
21
+ patch) new_version="${cmajor}.${cminor}.$((cpatch + 1))" ;;
22
+ *) new_version="$arg" ;;
23
+ esac
24
+
25
+ # Validate semver format
26
+ if ! echo "$new_version" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
27
+ echo "Error: version must be major, minor, patch or X.Y.Z" >&2
28
+ exit 1
29
+ fi
30
+
31
+ # Next release: following minor
32
+ IFS='.' read -r major minor _patch <<< "$new_version"
33
+ next_release="${major}.$((minor + 1)).0"
34
+
35
+ echo "Current version: $current"
36
+ echo "New version: $new_version"
37
+ echo "Next release: $next_release"
38
+
39
+ # version.rb
40
+ sed -i '' "s|VERSION = '[0-9.]*'|VERSION = '${new_version}'|" "$VERSION_FILE"
41
+
42
+ # README: YARD docs link
43
+ sed -i '' \
44
+ "s|rubydoc.info/gems/${GEM}/[0-9.]*|rubydoc.info/gems/${GEM}/${new_version}|g" \
45
+ "$README"
46
+
47
+ # README: Current Release line
48
+ sed -i '' \
49
+ "s|\*\*Current Release\*\*: \[[0-9.]*\](https://github.com/darthjee/azeroth/tree/[0-9.]*)|**Current Release**: [${new_version}](https://github.com/darthjee/azeroth/tree/${new_version})|" \
50
+ "$README"
51
+
52
+ # README: Next release line
53
+ sed -i '' \
54
+ "s|\*\*Next release\*\*: \[[0-9.]*\](https://github.com/darthjee/azeroth/compare/[0-9.]*\.\.\.main)|**Next release**: [${next_release}](https://github.com/darthjee/azeroth/compare/${new_version}...main)|" \
55
+ "$README"
56
+
57
+ # Gemfile.lock
58
+ if [ -f "$LOCKFILE" ]; then
59
+ sed -i '' "s|^\( *${GEM} (\)[0-9.]*)|\1${new_version})|" "$LOCKFILE"
60
+ fi
61
+
62
+ echo "Done."
data/spec/dummy/bin/setup CHANGED
@@ -2,9 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'fileutils'
5
- # rubocop:disable Style/MixinUsage
5
+ # rubocop:disable-next Style/MixinUsage
6
6
  include FileUtils
7
- # rubocop:enable Style/MixinUsage
8
7
 
9
8
  # path to your application root.
10
9
  APP_ROOT = File.expand_path('..', __dir__)
@@ -2,9 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'fileutils'
5
- # rubocop:disable Style/MixinUsage
5
+ # rubocop:disable-next Style/MixinUsage
6
6
  include FileUtils
7
- # rubocop:enable Style/MixinUsage
8
7
 
9
8
  # path to your application root.
10
9
  APP_ROOT = File.expand_path('..', __dir__)
@@ -4,8 +4,8 @@ ActiveRecord::Schema.define do
4
4
  self.verbose = false
5
5
 
6
6
  create_table :documents, force: true do |t|
7
- t.string :name
8
- t.string :reference
7
+ t.string :name
8
+ t.string :reference
9
9
  end
10
10
 
11
11
  create_table :users, force: true do |t|
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azeroth
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darthjee
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-03-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -30,42 +29,42 @@ dependencies:
30
29
  requirements:
31
30
  - - ">="
32
31
  - !ruby/object:Gem::Version
33
- version: 1.4.0
32
+ version: 2.0.0
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - ">="
39
38
  - !ruby/object:Gem::Version
40
- version: 1.4.0
39
+ version: 2.0.0
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: jace
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - ">="
46
45
  - !ruby/object:Gem::Version
47
- version: 0.1.2
46
+ version: 1.0.0
48
47
  type: :runtime
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - ">="
53
52
  - !ruby/object:Gem::Version
54
- version: 0.1.2
53
+ version: 1.0.0
55
54
  - !ruby/object:Gem::Dependency
56
55
  name: sinclair
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - ">="
60
59
  - !ruby/object:Gem::Version
61
- version: 3.1.0
60
+ version: 3.2.0
62
61
  type: :runtime
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
65
  - - ">="
67
66
  - !ruby/object:Gem::Version
68
- version: 3.1.0
67
+ version: 3.2.0
69
68
  description: Rails controller builder
70
69
  email:
71
70
  - darthjee@gmail.com
@@ -75,14 +74,23 @@ extensions: []
75
74
  extra_rdoc_files: []
76
75
  files:
77
76
  - ".circleci/config.yml"
77
+ - ".claude/agents/architect.md"
78
+ - ".claude/agents/docs.md"
79
+ - ".claude/agents/ruby.md"
80
+ - ".claude/agents/security.md"
81
+ - ".claude/configuration/auto-fix-all.json"
82
+ - ".claude/scripts/check_ruby.sh"
78
83
  - ".github/active_ext-usage.md"
79
- - ".github/azeroth-usage.md"
84
+ - ".github/commit_message_template.md"
80
85
  - ".github/copilot-instructions.md"
81
86
  - ".github/core_ext-usage.md"
82
87
  - ".github/jace-usage.md"
88
+ - ".github/pull_request_template.md"
83
89
  - ".gitignore"
84
90
  - ".rubocop.yml"
85
91
  - ".rubocop_todo.yml"
92
+ - AGENTS.md
93
+ - CLAUDE.md
86
94
  - Dockerfile
87
95
  - Gemfile
88
96
  - LICENSE
@@ -97,6 +105,21 @@ files:
97
105
  - config/yardstick.rb
98
106
  - config/yardstick.yml
99
107
  - docker-compose.yml
108
+ - docs/agents/architecture.md
109
+ - docs/agents/contributing.md
110
+ - docs/agents/flow.md
111
+ - docs/agents/folder-structure.md
112
+ - docs/agents/issue-enhancement.md
113
+ - docs/agents/issues/.gitkeep
114
+ - docs/agents/plans/.gitkeep
115
+ - docs/guides/azeroth-usage.md
116
+ - docs/guides/azeroth/basic-usage.md
117
+ - docs/guides/azeroth/best-practices.md
118
+ - docs/guides/azeroth/decorators.md
119
+ - docs/guides/azeroth/installation.md
120
+ - docs/guides/azeroth/model-for.md
121
+ - docs/guides/azeroth/resource-for-options.md
122
+ - docs/guides/azeroth/testing.md
100
123
  - lib/azeroth.rb
101
124
  - lib/azeroth/controller_interface.rb
102
125
  - lib/azeroth/decorator.rb
@@ -125,6 +148,7 @@ files:
125
148
  - lib/azeroth/resourceable/resources_builder.rb
126
149
  - lib/azeroth/routes_builder.rb
127
150
  - lib/azeroth/version.rb
151
+ - scripts/bump_version.sh
128
152
  - spec/controllers/documents_controller_spec.rb
129
153
  - spec/controllers/documents_with_error_controller_spec.rb
130
154
  - spec/controllers/index_documents_controller_spec.rb
@@ -286,7 +310,6 @@ files:
286
310
  homepage: https://github.com/darthjee/azeroth
287
311
  licenses: []
288
312
  metadata: {}
289
- post_install_message:
290
313
  rdoc_options: []
291
314
  require_paths:
292
315
  - lib
@@ -301,8 +324,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
324
  - !ruby/object:Gem::Version
302
325
  version: '0'
303
326
  requirements: []
304
- rubygems_version: 3.5.9
305
- signing_key:
327
+ rubygems_version: 4.0.23
306
328
  specification_version: 4
307
329
  summary: Azeroth
308
330
  test_files: []
@@ -1,277 +0,0 @@
1
- # Azeroth Gem Usage Instructions
2
-
3
- This file provides guidance for GitHub Copilot when working in projects that use the [Azeroth](https://github.com/darthjee/azeroth) gem.
4
-
5
- ## About Azeroth
6
-
7
- Azeroth is a Ruby gem that simplifies the creation of Rails controller endpoints. Its main feature is the `resource_for` class method, which automatically generates controller action methods (`create`, `show`, `index`, `update`, `delete`, `edit`) and handles both HTML and JSON request formats transparently.
8
-
9
- - HTML requests render templates without performing database operations.
10
- - JSON requests perform database operations and return serialized JSON.
11
-
12
- ## Installation
13
-
14
- Add Azeroth to your `Gemfile`:
15
-
16
- ```ruby
17
- gem 'azeroth'
18
- ```
19
-
20
- Then run:
21
-
22
- ```bash
23
- bundle install
24
- ```
25
-
26
- ## Basic Usage
27
-
28
- ### Setting Up `resource_for`
29
-
30
- Include `Azeroth::Resourceable` in your controller and call `resource_for` with the resource name:
31
-
32
- ```ruby
33
- class PublishersController < ApplicationController
34
- include Azeroth::Resourceable
35
- skip_before_action :verify_authenticity_token
36
-
37
- resource_for :publisher, only: %i[create index]
38
- end
39
- ```
40
-
41
- This generates the following behavior:
42
- - `GET /publishers` → calls `index`, returns all publishers
43
- - `POST /publishers` → calls `create`, creates a new publisher
44
-
45
- ### Available Actions
46
-
47
- By default, `resource_for` builds all six standard actions: `create`, `show`, `index`, `update`, `delete`, and `edit`. Use `only:` or `except:` to restrict which actions are generated:
48
-
49
- ```ruby
50
- # Only generate index and show
51
- resource_for :article, only: %i[index show]
52
-
53
- # Generate everything except delete
54
- resource_for :article, except: :delete
55
- ```
56
-
57
- ### Nested Resources
58
-
59
- Override the collection method to scope resources to a parent:
60
-
61
- ```ruby
62
- class GamesController < ApplicationController
63
- include Azeroth::Resourceable
64
- skip_before_action :verify_authenticity_token
65
-
66
- resource_for :game, except: :delete
67
-
68
- private
69
-
70
- def games
71
- publisher.games
72
- end
73
-
74
- def publisher
75
- @publisher ||= Publisher.find(publisher_id)
76
- end
77
-
78
- def publisher_id
79
- params.require(:publisher_id)
80
- end
81
- end
82
- ```
83
-
84
- ## `resource_for` Options
85
-
86
- | Option | Type | Description |
87
- |---|---|---|
88
- | `only` | Symbol / Array | List of actions to generate |
89
- | `except` | Symbol / Array | List of actions to skip |
90
- | `decorator` | Class / Boolean | Decorator class or flag to enable/disable decoration |
91
- | `before_save` | Symbol / Proc | Method or proc called before `create` or `update` saves |
92
- | `after_save` | Symbol / Proc | Method or proc called after `create` or `update` saves |
93
- | `build_with` | Symbol / Proc | Method or block used to build the resource on `create` |
94
- | `update_with` | Symbol / Proc | Method or block used to update the resource on `update` |
95
- | `paginated` | Boolean | Enable pagination on the `index` action |
96
- | `per_page` | Integer | Number of items per page when pagination is active (default: 20) |
97
- | `id_key` | Symbol | Parameter key used to look up a single resource (default: `:id`) |
98
- | `param_key` | Symbol | Parameter key used to find the model |
99
-
100
- ### Callbacks: `before_save` and `after_save`
101
-
102
- ```ruby
103
- class PokemonsController < ApplicationController
104
- include Azeroth::Resourceable
105
-
106
- resource_for :pokemon,
107
- only: %i[create update],
108
- before_save: :set_favorite
109
-
110
- private
111
-
112
- def set_favorite
113
- pokemon.favorite = true
114
- end
115
- end
116
- ```
117
-
118
- ### Pagination
119
-
120
- ```ruby
121
- class DocumentsController < ApplicationController
122
- include Azeroth::Resourceable
123
-
124
- resource_for :document, only: :index, paginated: true, per_page: 10
125
- end
126
- ```
127
-
128
- A paginated `index` request returns the items for the requested page and sets the following response headers:
129
-
130
- | Header | Description |
131
- |---|---|
132
- | `pages` | Total number of pages |
133
- | `per_page` | Number of items per page |
134
- | `page` | Current page number |
135
-
136
- ```bash
137
- GET /documents.json # page 1 – first 10 documents
138
- GET /documents.json?page=2 # page 2 – next 10 documents
139
- ```
140
-
141
- ## JSON Serialization with `Azeroth::Decorator`
142
-
143
- Decorators control which attributes are included in JSON responses.
144
-
145
- ### Defining a Decorator
146
-
147
- Create a decorator class that inherits from `Azeroth::Decorator` and call `expose` for each attribute to include:
148
-
149
- ```ruby
150
- # app/decorators/pokemon/decorator.rb
151
- class Pokemon::Decorator < Azeroth::Decorator
152
- expose :name
153
- expose :previous_form_name, as: :evolution_of, if: :evolution?
154
-
155
- def evolution?
156
- previous_form
157
- end
158
-
159
- def previous_form_name
160
- previous_form.name
161
- end
162
- end
163
- ```
164
-
165
- ### `expose` Options
166
-
167
- | Option | Type | Description |
168
- |---|---|---|
169
- | `as` | Symbol | Custom JSON key for the attribute |
170
- | `if` | Symbol / Proc | Method or block; attribute is only included when it returns truthy |
171
- | `decorator` | Class / Boolean | Nested decorator class or flag to enable/disable decoration |
172
- | `reader` | Boolean | Whether to create a reader method for the attribute |
173
- | `override` | Boolean | Whether to override an existing method with the same name |
174
-
175
- ### Decorator Inheritance
176
-
177
- Extend decorators by subclassing them:
178
-
179
- ```ruby
180
- # app/decorators/pokemon/favorite_decorator.rb
181
- class Pokemon::FavoriteDecorator < Pokemon::Decorator
182
- expose :nickname
183
- end
184
- ```
185
-
186
- ### Using a Custom Decorator in a Controller
187
-
188
- Pass the decorator class to `resource_for`:
189
-
190
- ```ruby
191
- class PokemonsController < ApplicationController
192
- include Azeroth::Resourceable
193
-
194
- resource_for :pokemon, decorator: Pokemon::FavoriteDecorator
195
- end
196
- ```
197
-
198
- ## `model_for`
199
-
200
- `model_for` adds singular and plural resource accessor methods to a controller (e.g., `document` and `documents`) **without** generating any HTTP route actions. This is useful when a controller needs to access a resource as context (for example a parent record) but should not expose CRUD endpoints for it.
201
-
202
- ### Options
203
-
204
- | Option | Type | Description |
205
- |---|---|---|
206
- | `id_key` | Symbol | Parameter key used to find the record (default: `:id`) |
207
- | `param_key` | Symbol | Parameter key used to find the model |
208
-
209
- ### Example
210
-
211
- ```ruby
212
- class PostsController < ApplicationController
213
- include Azeroth::Resourceable
214
-
215
- # Generates full CRUD endpoints for Post,
216
- # scoped to the author resolved by model_for below.
217
- resource_for :post
218
-
219
- # Only adds `author` and `authors` helper methods —
220
- # no HTTP actions are created for Author.
221
- model_for :author, id_key: :author_id
222
-
223
- private
224
-
225
- def posts
226
- author.posts
227
- end
228
- end
229
- ```
230
-
231
- In this example:
232
- - `GET /authors/:author_id/posts.json` returns all posts belonging to the author.
233
- - `author` is resolved automatically via `Author.find(params[:author_id])`.
234
- - No `/authors` CRUD endpoints are generated.
235
-
236
- ## Best Practices
237
-
238
- - **Use `only:` / `except:`** to expose only the actions your controller actually needs.
239
- - **Override collection methods** (e.g., `def games`) to scope resources to a parent instead of returning the full table.
240
- - **Use decorators** to keep serialization logic out of controllers and models.
241
- - **Use `before_save` / `after_save`** callbacks for business logic that must run around persistence, rather than overriding generated action methods.
242
- - **Prefer `resource_for`** over hand-written CRUD actions for standard resources to ensure consistent behavior across your application.
243
-
244
- ## Testing Controllers That Use Azeroth
245
-
246
- Use standard Rails request specs or controller specs with RSpec. Since Azeroth generates conventional Rails actions, they can be exercised like any other controller action:
247
-
248
- ```ruby
249
- RSpec.describe PokemonsController, type: :request do
250
- let(:master) { create(:pokemon_master) }
251
-
252
- describe 'POST /pokemons' do
253
- it 'creates a pokemon' do
254
- post "/pokemon_masters/#{master.id}/pokemons.json",
255
- params: { pokemon: { name: 'Bulbasaur' } }
256
-
257
- expect(response).to have_http_status(:created)
258
- expect(response.parsed_body['name']).to eq('Bulbasaur')
259
- end
260
- end
261
-
262
- describe 'GET /pokemons' do
263
- it 'returns all pokemons' do
264
- get "/pokemon_masters/#{master.id}/pokemons.json"
265
-
266
- expect(response).to have_http_status(:ok)
267
- expect(response.parsed_body).to be_an(Array)
268
- end
269
- end
270
- end
271
- ```
272
-
273
- ## Further Reading
274
-
275
- - [Azeroth on RubyGems](https://rubygems.org/gems/azeroth)
276
- - [YARD Documentation](https://www.rubydoc.info/gems/azeroth)
277
- - [GitHub Repository](https://github.com/darthjee/azeroth)