archipelago-rails 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +27 -18
- data/test/archipelago/resolver_test.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cc3ff097bdcb50e59b6ace832f59db53b77d1bf2d4d50e10da0595b38804afbd
|
|
4
|
+
data.tar.gz: cd849b78be869b5626e4582ddd8966be6626bce1540dcb7cb2b1613ebf238d03
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 92f4432fa77ce8ee1442c210a29dbee01c22e6dac9958c7f1652290a1d9e5cde97eff943276e9d755beeff6c601958370d4a6c4c4a601fad1399a133c91df437
|
|
7
|
+
data.tar.gz: 12efedc0b57f6d59fc3a3edca4e08f51c93f3fb07a727f606939c2cca39cdc3106558ceb0a2cc11c5728f38f4f2325d431eb7635e0f338e6f566eba304f5cfe3
|
data/README.md
CHANGED
|
@@ -57,15 +57,17 @@ Actions live in `app/islands/<component>/` and handle requests from island compo
|
|
|
57
57
|
```ruby
|
|
58
58
|
# app/islands/team_members/add_member.rb
|
|
59
59
|
class TeamMembers::AddMember < Archipelago::Action
|
|
60
|
-
param :
|
|
60
|
+
param :team_id, :integer, required: true
|
|
61
|
+
param :email, :string, required: true, strip: true, downcase: true
|
|
61
62
|
|
|
62
|
-
authorize { current_user.
|
|
63
|
+
authorize { current_user.teams.exists?(id: team_id) }
|
|
63
64
|
|
|
64
65
|
def perform
|
|
65
|
-
|
|
66
|
+
team = current_user.teams.find(team_id)
|
|
67
|
+
team.members.create!(email: email)
|
|
66
68
|
|
|
67
69
|
props(
|
|
68
|
-
members:
|
|
70
|
+
members: team.members.map { |m| { id: m.id, email: m.email } }
|
|
69
71
|
)
|
|
70
72
|
end
|
|
71
73
|
end
|
|
@@ -73,7 +75,7 @@ end
|
|
|
73
75
|
|
|
74
76
|
### Action lifecycle
|
|
75
77
|
|
|
76
|
-
1. **Param coercion** — declared params are validated and coerced
|
|
78
|
+
1. **Param coercion** — declared params are validated and coerced into typed accessors
|
|
77
79
|
2. **Authorization** — the `authorize` block runs (raises `Forbidden` on failure)
|
|
78
80
|
3. **`perform`** — your business logic executes
|
|
79
81
|
4. **Response** — returns `ok` (with props), `error` (with field errors), `redirect`, or `forbidden`
|
|
@@ -82,14 +84,11 @@ end
|
|
|
82
84
|
|
|
83
85
|
```ruby
|
|
84
86
|
def perform
|
|
85
|
-
#
|
|
86
|
-
props(members: [...])
|
|
87
|
+
props(members: [...]) # return updated props
|
|
87
88
|
|
|
88
|
-
#
|
|
89
|
-
redirect_to "/teams/#{team.id}"
|
|
89
|
+
redirect_to "/teams/#{team_id}" # or redirect
|
|
90
90
|
|
|
91
|
-
#
|
|
92
|
-
add_error(:email, "is already taken")
|
|
91
|
+
add_error(:email, "is already taken") # or add field errors
|
|
93
92
|
end
|
|
94
93
|
```
|
|
95
94
|
|
|
@@ -99,7 +98,7 @@ Available in all actions, delegating to the configured user method:
|
|
|
99
98
|
|
|
100
99
|
```ruby
|
|
101
100
|
def perform
|
|
102
|
-
|
|
101
|
+
project = current_user.projects.find(project_id)
|
|
103
102
|
# ...
|
|
104
103
|
end
|
|
105
104
|
```
|
|
@@ -192,12 +191,13 @@ Include `Archipelago::PunditAdapter` for Pundit-style authorization:
|
|
|
192
191
|
class TeamMembers::AddMember < Archipelago::Action
|
|
193
192
|
include Archipelago::PunditAdapter
|
|
194
193
|
|
|
195
|
-
|
|
194
|
+
param :team_id, :integer, required: true
|
|
196
195
|
|
|
197
196
|
def perform
|
|
198
|
-
|
|
199
|
-
authorize(
|
|
200
|
-
|
|
197
|
+
team = current_user.teams.find(team_id)
|
|
198
|
+
authorize(team) # infers query from action class name
|
|
199
|
+
team.members.create!(email: email)
|
|
200
|
+
props(members: team.members.as_json)
|
|
201
201
|
end
|
|
202
202
|
end
|
|
203
203
|
```
|
|
@@ -214,10 +214,13 @@ Include `Archipelago::CanCanAdapter` for CanCan-style authorization:
|
|
|
214
214
|
class TeamMembers::AddMember < Archipelago::Action
|
|
215
215
|
include Archipelago::CanCanAdapter
|
|
216
216
|
|
|
217
|
+
param :team_id, :integer, required: true
|
|
218
|
+
|
|
217
219
|
def perform
|
|
218
|
-
team =
|
|
220
|
+
team = current_user.teams.find(team_id)
|
|
219
221
|
authorize!(:manage, team)
|
|
220
|
-
|
|
222
|
+
team.members.create!(email: email)
|
|
223
|
+
props(members: team.members.as_json)
|
|
221
224
|
end
|
|
222
225
|
end
|
|
223
226
|
```
|
|
@@ -325,6 +328,12 @@ bin/test-appraisal rails-7-2
|
|
|
325
328
|
bin/test-appraisal rails-8-1
|
|
326
329
|
```
|
|
327
330
|
|
|
331
|
+
## Stability
|
|
332
|
+
|
|
333
|
+
This library follows [Semantic Versioning](https://semver.org/). The public API surface — `Archipelago::Action`, the Params DSL, `authorize`, response helpers (`props`, `redirect_to`, `add_error`), configuration options, stream authorization, and the Pundit/CanCan adapter interfaces — is considered stable. Breaking changes will only occur in major version bumps.
|
|
334
|
+
|
|
335
|
+
Internal modules, resolver internals, and the `raw_params` hash shape are not part of the public contract and may change in minor releases.
|
|
336
|
+
|
|
328
337
|
## License
|
|
329
338
|
|
|
330
339
|
MIT
|
|
@@ -77,4 +77,13 @@ class ResolverTest < ArchipelagoTestCase
|
|
|
77
77
|
Archipelago::Resolver.new.resolve(component: "UnknownIsland", operation: "add_member")
|
|
78
78
|
end
|
|
79
79
|
end
|
|
80
|
+
|
|
81
|
+
def test_rejects_handler_that_does_not_inherit_from_action
|
|
82
|
+
not_an_action = Class.new
|
|
83
|
+
Archipelago.map "TeamMembers#not_action" => not_an_action
|
|
84
|
+
|
|
85
|
+
assert_raises(Archipelago::ResolutionError) do
|
|
86
|
+
Archipelago::Resolver.new.resolve(component: "TeamMembers", operation: "not_action")
|
|
87
|
+
end
|
|
88
|
+
end
|
|
80
89
|
end
|