hub_kernel 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 026174ef5963518769182562042464615e204f2a32f7e4260c9ed390fc5b2160
|
|
4
|
+
data.tar.gz: 5d2fbdbb14248e8e145eb545246063e883fd196fb68b930180ff9b067a9c341c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9a7a2a568be438e982a2c0d688fdc61e5fd4ade3b49070d3ffccff71e662b6748185e2e19a1b1beedb6f3c2d14bf5e899faf12598ce7cbcf6e225d7a8c859389
|
|
7
|
+
data.tar.gz: 5f189db08ded136cb2adc871613545ba62f8f163938b63587e47a7382a745d12cceff6606fb7a5f137b4b0db5ca2c09db321cd91dc600140a7c4edde1e2f4c1f
|
data/lib/hub_kernel/authz.rb
CHANGED
|
@@ -4,26 +4,5 @@ module HubKernel
|
|
|
4
4
|
|
|
5
5
|
module Authz
|
|
6
6
|
singleton_class.attr_accessor :check
|
|
7
|
-
|
|
8
|
-
module Vocabulary
|
|
9
|
-
def gates(*actions)
|
|
10
|
-
gated_actions.concat(actions)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def gated_actions
|
|
14
|
-
@gated_actions ||= []
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def self.included(hub)
|
|
19
|
-
hub.extend(Vocabulary)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def allowed?(actor, action)
|
|
23
|
-
answer = authz.allowed?(actor, action)
|
|
24
|
-
raise NonBooleanAnswerError, "allowed? must return true or false, got #{answer.inspect}" unless [ true, false ].include?(answer)
|
|
25
|
-
|
|
26
|
-
answer
|
|
27
|
-
end
|
|
28
7
|
end
|
|
29
8
|
end
|
data/lib/hub_kernel/context.rb
CHANGED
data/lib/hub_kernel/version.rb
CHANGED
|
@@ -38,7 +38,9 @@ hub_kernel lets a hub, one domain area written as a module, state what it needs
|
|
|
38
38
|
bin/rails generate hub_kernel:hub Ledger entry_recorder:record_entry
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
- In a Rails engine gem it
|
|
41
|
+
- In a Rails engine gem it adds hub_kernel to the gemspec once, and writes no test, since the gem never fills its own ports.
|
|
42
|
+
- When the engine isolates its namespace, the hub goes under that namespace, such as `app/models/billing/ledger.rb` holding `module Billing::Ledger`.
|
|
43
|
+
- A namespaced name such as `Console::Hubs::Billing` writes the hub at the matching nested path, such as `app/models/console/hubs/billing.rb`.
|
|
42
44
|
- In an app it writes the hub under `app/models` and the hub's wiring test under `test/models`.
|
|
43
45
|
|
|
44
46
|
The generated hub:
|
|
@@ -34,11 +34,13 @@ Decide which side you are on:
|
|
|
34
34
|
- **Filling ports** — the host app sets each of a hub's ports to any callable, usually another hub's method, in its setup that runs again on every code reload. Ports are "wired" once they are filled.
|
|
35
35
|
- **Start check** — the app refuses to start while any hub's ports are not wired, and names each one, such as "Supplies' spend recorder is not wired". While any hub lists a method callable by name, it also refuses to start until the permission check and the account scope are both set to something that can be called, and names whichever is missing or cannot be called. An app whose hubs list no such methods starts without either.
|
|
36
36
|
- **Hub check** — a host test that fails naming each of a hub's ports left unfilled or filled with something that cannot be called. A domain gem never runs it, since the gem never fills its own ports.
|
|
37
|
-
- **Call by name** — a caller reaches a hub method by its name as a string, with the values sent, the person, and the account.
|
|
37
|
+
- **Call by name** — a caller reaches a hub method by its name as a string, with the values sent, the person, and the account. A missing person or account, an unknown name, a call the permission check does not allow, and missing required values are each refused, in that order. Only the values the method is listed with are passed on.
|
|
38
38
|
- **What a person may call** — the hub's list of methods callable by name, kept to those the permission check allows for one person on one account. Asking with no person or no account is refused, the same as a call by name. A hub that lists nothing, or a person allowed nothing, gets an empty list rather than an error.
|
|
39
39
|
- **Action** — the name a permission is asked for, made of the hub and the method, such as supplies:record_purchase.
|
|
40
40
|
- **Permission check** — one host-wide rule answering true or false for a person, an action, and an account. Any other answer is an error.
|
|
41
41
|
- **Account scope** — one host-wide wrapper that runs each call by name inside the account it was made for.
|
|
42
42
|
- **Refusing** — what a hub does when it will not do what was asked, and its reason reaches the caller unchanged.
|
|
43
|
+
- **Listed-methods check** — a hub's own test that fails naming each listed method the hub has no method for, and each one listed with values it does not take.
|
|
43
44
|
- **Crossing** — a file in one hub naming a class another hub owns. A constant inside that class counts.
|
|
44
|
-
- **Crossing map** — the host's statement of which classes each hub owns, plus the classes shared by all, the host's own layer, each hub's interface module, and any namespace a hub owns whole. Only the host's layer may name a hub's interface module
|
|
45
|
+
- **Crossing map** — the host's statement of which classes each hub owns, plus the classes shared by all, the host's own layer, each hub's interface module, and any namespace a hub owns whole. Only the host's layer may name a hub's interface module. A view belongs to the hub that owns its controller, then to the hub that owns the record its folder is named after, and otherwise to the host's layer.
|
|
46
|
+
- **Crossing check** — a host test that fails naming each crossing, each class no hub owns, each class given to two hubs, and each class the map names that no longer exists. It also fails when none of the files it read belongs to a hub, so a wrong file pattern does not pass unnoticed.
|
|
@@ -58,11 +58,11 @@ hub_kernel lets a Rails host app fill the ports each hub declares, refuse to sta
|
|
|
58
58
|
- While any loaded hub exposes a method, the start check refuses to start until both are set to something that responds to `call`.
|
|
59
59
|
- The permission check answers both a call by name and a listing of what a person may call, so the two always agree.
|
|
60
60
|
- Listing what a person may call needs only the permission check, while a call by name needs both.
|
|
61
|
-
- The action is a string made of the hub and the method, such as `"supplies:record_purchase"`.
|
|
61
|
+
- The action is a string made of the hub's own name, without its namespace and in snake case, then the method, such as `"supplies:record_purchase"` for `Shop::Supplies`.
|
|
62
62
|
- The permission check must answer exactly `true` or `false`, and any other answer makes the call or the listing raise an error.
|
|
63
63
|
- The account scope must take the block and run it, or the hub method never runs.
|
|
64
64
|
|
|
65
|
-
6. Add one hub check
|
|
65
|
+
6. Add one hub check to the host's tests for each hub that declares at least one port, such as `test/hubs/supplies_hub_test.rb`:
|
|
66
66
|
|
|
67
67
|
```ruby
|
|
68
68
|
require "hub_kernel/conformance/hub"
|
|
@@ -74,7 +74,8 @@ hub_kernel lets a Rails host app fill the ports each hub declares, refuse to sta
|
|
|
74
74
|
end
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
The `require` line is needed because the gem does not load the test modules on its own.
|
|
77
|
+
- The `require` line is needed because the gem does not load the test modules on its own.
|
|
78
|
+
- A hub that exposes methods but declares no port gets no hub check, since the check errors on a hub with no ports.
|
|
78
79
|
|
|
79
80
|
7. Ask the developer for the crossing map, since only they know which hub owns which class:
|
|
80
81
|
- which classes each hub owns;
|
|
@@ -119,8 +120,9 @@ hub_kernel lets a Rails host app fill the ports each hub declares, refuse to sta
|
|
|
119
120
|
- A domain gem never runs the hub check, since it never fills its own ports, so the hub check always lives in the host's tests.
|
|
120
121
|
- A view belongs to the hub that owns its controller, then to the hub that owns the record its folder is named after, and otherwise to the host's layer.
|
|
121
122
|
- A constant inside another hub's class counts as naming that class.
|
|
122
|
-
-
|
|
123
|
+
- A hub's interface module may be named by the host's layer and by that hub, and by no other hub.
|
|
123
124
|
- A class listed by name under `owners` belongs to that hub even inside another hub's namespace.
|
|
125
|
+
- The check for unowned classes reads only Ruby files outside `app/views`, so a view never needs its own entry in the map.
|
|
124
126
|
- The crossing check fails with "The crossing check found no files to read" when its `files:` pattern matches nothing the map owns, so fix the pattern or the map rather than the test.
|
|
125
127
|
- When a hub gains a port, fill it in the `to_prepare` block. When a hub first exposes a method, set the permission check and the account scope there too. When a class is added, renamed or removed, update the crossing map, since the check fails on a class no hub owns and on a mapped class that no longer exists.
|
|
126
128
|
- Writing a hub, declaring its ports, and listing the methods it exposes are not part of installing and are out of scope here.
|