hub_kernel 0.29.0 → 0.30.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: 0b75dd33da96e8bc1bd5161a74fc004c527892842f1cd118827353874fb7e0a4
4
- data.tar.gz: 9f17abdb22deb70e29c7bc80642e4a264340220cbdbbec299ef2b4ba51fa3c1b
3
+ metadata.gz: 3bd5059f8cefe97155641bc63d4c09c593b539788ae211ed2c9e7f088538ac6d
4
+ data.tar.gz: cb389fde65506d87873ae721081ab41a8a69aa57a4542dec84fa21cd2dedf9ee
5
5
  SHA512:
6
- metadata.gz: eff51e2b76a8a5dd6c4c98e083c5b6090bea2318feb468d7c2e25ee8d625aec56eb55dba088e1f3f622f73f11a413e841661a2d2de09a6a6713a8e0b235b4371
7
- data.tar.gz: fd005c78271dba55057cca73001445d614ba461c7ae0b1cc1b0fc26e60d26d7a1aab5b9e0a1ddef1bf14eba701f5264e7af7b993b7b2fdc2235889cde018aaf7
6
+ metadata.gz: efb8fa31202a5d7519bfeaf9d7e5cc196ce3a566db448a2443e234d80be6e07653934a6062f962fbecf156fcf061a0d4d3e7da96426c1d2ee6f888c9dae46a55
7
+ data.tar.gz: 17e75d2a1b1c0d0c74b85eca7b23bca96c616c8f31de33b51fafd3e7c91ac585134a60d9a43c3c741749ae6ba926b2541298dae06975e62343b2fa6724388642
data/README.md CHANGED
@@ -102,6 +102,33 @@ returns its answer. An error it raises reaches the caller unchanged. Calling a p
102
102
  app left unfilled raises `HubKernel::UnwiredPortError`, such as "Supplies' spend
103
103
  recorder is not wired".
104
104
 
105
+ ### The business time zone
106
+ The app sets one business time zone for every hub, with a callable that answers a
107
+ time zone name:
108
+
109
+ ```ruby
110
+ Rails.application.config.to_prepare do
111
+ HubKernel.time_zone_reader = -> { "America/Chicago" }
112
+ end
113
+ ```
114
+
115
+ Every hub that extends `HubKernel::Ports` then answers `time_zone`, which calls the
116
+ reader each time so a changed setting is read on the next call, and `today`, which is
117
+ the current date in that zone:
118
+
119
+ ```ruby
120
+ Supplies.time_zone # => "America/Chicago"
121
+ Supplies.today # => the current date in Chicago
122
+ ```
123
+
124
+ `HubKernel.time_zone` and `HubKernel.today` answer the same for code that has no hub at
125
+ hand. Reading either before the app set a reader raises `HubKernel::UnwiredPortError`
126
+ with "hub_kernel's business time zone is not wired". The start check does not check it,
127
+ so an app whose hubs never read the time zone need not set one.
128
+
129
+ A hub that declares its own `port :time_zone_reader, as: :time_zone` keeps answering
130
+ from that port, and its `today` uses that zone.
131
+
105
132
  ### Record ports
106
133
  A record port is a port the app fills with an Active Record model class, so a hub can
107
134
  name a model another part of the app owns without naming its class. The hub declares it
@@ -0,0 +1,12 @@
1
+ require "hub_kernel/exposes"
2
+
3
+ module HubKernel
4
+ singleton_class.attr_writer :time_zone_reader
5
+
6
+ def self.time_zone = time_zone_reader.call
7
+
8
+ def self.today = Time.current.in_time_zone(time_zone).to_date
9
+
10
+ def self.time_zone_reader = @time_zone_reader || raise(UnwiredPortError, "hub_kernel's business time zone is not wired")
11
+ private_class_method :time_zone_reader
12
+ end
@@ -1,5 +1,6 @@
1
1
  require "active_support/core_ext/string/inflections"
2
2
  require "hub_kernel/hubs"
3
+ require "hub_kernel/business_clock"
3
4
 
4
5
  require "hub_kernel/exposes"
5
6
 
@@ -31,6 +32,10 @@ module HubKernel
31
32
 
32
33
  def port_names = declared_ports.dup
33
34
 
35
+ def time_zone = HubKernel.time_zone
36
+
37
+ def today = Time.current.in_time_zone(time_zone).to_date
38
+
34
39
  def unwired_ports
35
40
  declared_ports.reject { |name| instance_variable_get(:"@#{name}") }.map { |name| unwired_message(name) }
36
41
  end
@@ -1,3 +1,3 @@
1
1
  module HubKernel
2
- VERSION = "0.29.0"
2
+ VERSION = "0.30.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: hub_kernel-develop
3
- description: Use PROACTIVELY for writing or changing a hub — generating one, declaring the ports it needs from other hubs, calling those ports from the hub's code, listing the methods outside callers may reach by name, refusing a request with a reason, calling a hub method by name from an interface such as a JSON API, listing the methods a hub exposes or the ones a person may call on an account, and adding the check that the listed methods match the hub's real methods — MUST BE USED instead of calling another hub's classes directly or hand-writing a name-to-method lookup.
3
+ description: Use PROACTIVELY for writing or changing a hub — generating one, declaring the ports it needs from other hubs, calling those ports from the hub's code, reading the business time zone or today's business date, listing the methods outside callers may reach by name, refusing a request with a reason, calling a hub method by name from an interface such as a JSON API, listing the methods a hub exposes or the ones a person may call on an account, and adding the check that the listed methods match the hub's real methods — MUST BE USED instead of calling another hub's classes directly, reading `Time.zone` or `Date.today` in hub code, or hand-writing a name-to-method lookup.
4
4
  tools: Read, Write, Edit, Grep
5
5
  scope: hubs — a domain gem declares the ports it needs and the methods it exposes, and the host app fills those ports and checks each hub is wired and crosses into no other hub
6
6
  ---
@@ -8,12 +8,16 @@ scope: hubs — a domain gem declares the ports it needs and the methods it expo
8
8
  This local writes hubs and the code that calls them by name, following these steps exactly and inventing none. Where a step needs a value only the developer knows, it asks.
9
9
 
10
10
  ## What hub_kernel is
11
- hub_kernel lets a hub, one domain area written as a module, state what it needs from outside itself as named ports and list the methods outside callers may reach by name. The hub's code never names another hub's classes, and an interface such as a JSON API reaches the hub only through its list. Use this local when creating a hub, adding a port, exposing a hub method, calling a hub method by name, listing what a hub exposes or what a person may call, or when hub code is about to call another hub directly.
11
+ hub_kernel lets a hub, one domain area written as a module, state what it needs from outside itself as named ports and list the methods outside callers may reach by name. The hub's code never names another hub's classes, and an interface such as a JSON API reaches the hub only through its list. Every hub also answers the business time zone the host set and today's date in it. Use this local when creating a hub, adding a port, reading the business time zone or today's date, exposing a hub method, calling a hub method by name, listing what a hub exposes or what a person may call, or when hub code is about to call another hub directly.
12
12
 
13
13
  ## Interface
14
14
  - `bin/rails generate hub_kernel:hub` — writes a new hub module with its ports declared, and in a gem adds hub_kernel to the gemspec.
15
15
  - `HubKernel::Ports` — the module a hub extends to declare ports.
16
16
  - `port` — declares one port by name and the method the hub's own code calls to use it.
17
+ - `time_zone` — answers the business time zone from any hub that extends `HubKernel::Ports`.
18
+ - `today` — answers the current date in the business time zone from any hub that extends `HubKernel::Ports`.
19
+ - `HubKernel.time_zone` — answers the business time zone for code that has no hub at hand.
20
+ - `HubKernel.today` — answers the current date in the business time zone for code that has no hub at hand.
17
21
  - `HubKernel::Exposes` — the module a hub extends to list the methods callers may reach by name.
18
22
  - `exposes` — lists one hub method with the values it takes and whether it writes.
19
23
  - `exposed` — looks up one listed method by name and answers its entry, or `nil` when it is not listed.
@@ -77,10 +81,33 @@ hub_kernel lets a hub, one domain area written as a module, state what it needs
77
81
  - Calling a port the host left unfilled raises an error naming it, such as "Supplies' spend recorder is not wired".
78
82
  - Never name another hub's classes in place of a port.
79
83
 
84
+ ### Read the business time zone and today's date
85
+ 5. Where hub code needs the business time zone or the current business date, ask the hub rather than reading `Time.zone`, `Date.today` or `Date.current`:
86
+
87
+ ```ruby
88
+ Supplies.time_zone # => "America/Chicago"
89
+ Supplies.today # => the current date in Chicago
90
+ ```
91
+
92
+ - Any hub that extends `HubKernel::Ports` answers both, with no port declared for them.
93
+ - `time_zone` answers the time zone name the host set, and reads it again on every call, so a changed setting is seen on the next call.
94
+ - `today` is the current date in that time zone, not in UTC or the server's zone.
95
+ - Code with no hub at hand, such as a job or a helper, calls `HubKernel.time_zone` and `HubKernel.today`, which answer the same.
96
+ - Reading either before the host set the business time zone raises the same error as an unfilled port, with the message "hub_kernel's business time zone is not wired".
97
+
98
+ 6. When a hub needs a time zone other than the business one, ask the developer whether it should. Only if they say yes, declare its own port named `time_zone_reader` that its code calls as `time_zone`:
99
+
100
+ ```ruby
101
+ port :time_zone_reader, as: :time_zone
102
+ ```
103
+
104
+ - That hub's `time_zone` then answers from its own port, and its `today` is the date in that zone.
105
+ - Every host app must fill that port, as with any other port.
106
+
80
107
  ### Expose methods
81
- 5. Ask the developer which hub methods outside callers may reach by name, and for each, whether it writes. Do not decide either yourself.
108
+ 7. Ask the developer which hub methods outside callers may reach by name, and for each, whether it writes. Do not decide either yourself.
82
109
 
83
- 6. Write each exposed method as a module method on the hub that takes keyword arguments only, since a call by name passes values as keywords:
110
+ 8. Write each exposed method as a module method on the hub that takes keyword arguments only, since a call by name passes values as keywords:
84
111
 
85
112
  ```ruby
86
113
  module Supplies
@@ -101,10 +128,10 @@ hub_kernel lets a hub, one domain area written as a module, state what it needs
101
128
  - `writes:` is `true` or `false`, and both `takes:` and `writes:` must be given.
102
129
  - A hub can extend both `HubKernel::Ports` and `HubKernel::Exposes`.
103
130
 
104
- 7. When the method will not do what was asked, raise `HubKernel::Refused` with the reason a person should read. The reason reaches the caller unchanged.
131
+ 9. When the method will not do what was asked, raise `HubKernel::Refused` with the reason a person should read. The reason reaches the caller unchanged.
105
132
 
106
133
  ### Check the exposed list
107
- 8. Add the exposed-list check to the tests of the gem or app that holds the hub, such as `test/models/supplies_exposed_test.rb`:
134
+ 10. Add the exposed-list check to the tests of the gem or app that holds the hub, such as `test/models/supplies_exposed_test.rb`:
108
135
 
109
136
  ```ruby
110
137
  require "hub_kernel/conformance/exposed"
@@ -119,7 +146,7 @@ hub_kernel lets a hub, one domain area written as a module, state what it needs
119
146
  The `require` line is needed because the gem does not load the test modules on its own. This check needs no ports filled, so it runs in a domain gem's own suite.
120
147
 
121
148
  ### Call a hub method by name
122
- 9. In the interface that serves callers, such as a JSON API controller, look the method up with `exposed` and call it with `call_exposed`:
149
+ 11. In the interface that serves callers, such as a JSON API controller, look the method up with `exposed` and call it with `call_exposed`:
123
150
 
124
151
  ```ruby
125
152
  Supplies.exposed("record_purchase") # => entry with .name, .takes, .writes
@@ -138,7 +165,7 @@ hub_kernel lets a hub, one domain area written as a module, state what it needs
138
165
  - The permission is asked for an action named after the hub, without its namespace, and the method, such as `"supplies:record_purchase"` or `"ledger:record_entry"`.
139
166
  - It returns the result of the call made inside the host's account scope.
140
167
 
141
- 10. A call by name fails in this order, and each failure stops the call:
168
+ 12. A call by name fails in this order, and each failure stops the call:
142
169
  1. `HubKernel::MissingArgumentError` when `person:` or `account:` is `nil`.
143
170
  2. `HubKernel::UnexposedMethodError` when the hub does not list the name.
144
171
  3. An error naming the host's permission check when the host has not set it.
@@ -148,10 +175,10 @@ hub_kernel lets a hub, one domain area written as a module, state what it needs
148
175
  7. An error naming the host's account scope when the host has not set it.
149
176
  8. `HubKernel::Refused`, or any other error, raised by the hub method itself.
150
177
 
151
- 11. Ask the developer how the interface answers each of those failures, such as which HTTP status each one returns. Do not pick the responses yourself. Show a `HubKernel::Refused` message to the caller as it is.
178
+ 13. Ask the developer how the interface answers each of those failures, such as which HTTP status each one returns. Do not pick the responses yourself. Show a `HubKernel::Refused` message to the caller as it is.
152
179
 
153
180
  ### List what a hub exposes
154
- 12. Where the interface shows callers which methods they can reach, such as a list of tools or actions, read it from the hub rather than writing it out again:
181
+ 14. Where the interface shows callers which methods they can reach, such as a list of tools or actions, read it from the hub rather than writing it out again:
155
182
 
156
183
  ```ruby
157
184
  Supplies.exposures
@@ -168,13 +195,15 @@ hub_kernel lets a hub, one domain area written as a module, state what it needs
168
195
  - Pass the same `person:` and `account:` the interface passes to `call_exposed`.
169
196
  - Ask the developer whether the interface shows every exposed method or only those the person may call. Do not pick yourself.
170
197
 
171
- 13. Run the test suite and confirm the conventions below hold.
198
+ 15. Run the test suite and confirm the conventions below hold.
172
199
 
173
200
  ## Conventions
174
201
  - A hub's code reaches another hub only through a port, never by naming its classes.
202
+ - Hub code reads the business time zone and today's date from the hub, never from `Time.zone`, `Date.today` or `Date.current`.
203
+ - When hub code first reads the business time zone or today's date, tell the developer every host app must set the business time zone, since the host's start check does not check it and the first read raises an error.
175
204
  - An outside caller reaches a hub only through `call_exposed`, never by sending a name to the hub with `public_send` or `send`.
176
205
  - Every exposed method is listed with `exposes`, and the exposed-list check passes.
177
206
  - When an exposed method gains, loses or renames a keyword, update its `takes:` in the same change.
178
207
  - When a hub gains a port, tell the developer every host app must fill it, since calling it unfilled raises an error and the host's start check fails.
179
208
  - When a hub exposes its first method, tell the developer every host app must set the permission check and the account scope, since the host's start check fails while any hub exposes a method and either is unset or cannot be called.
180
- - Adding the gem to a host, filling ports, running the start check, setting the permission check and the account scope, and the host's hub and crossing checks belong to the install local and are out of scope here.
209
+ - Adding the gem to a host, filling ports, running the start check, setting the permission check, the account scope and the business time zone, and the host's hub and crossing checks belong to the install local and are out of scope here.
@@ -11,14 +11,16 @@ This local explains hub_kernel and the words it uses. It makes no changes and gi
11
11
 
12
12
  hub_kernel splits a Rails app into hubs, where each hub is one area of the domain, such as supplies or finance, usually shipped in its own domain gem. A hub states what it needs from outside itself as named ports, and the host app decides what fills each one, so a hub never names another hub's code directly.
13
13
 
14
- A hub also lists the methods outside callers may reach by name, with the values each takes and whether it writes. An interface such as a JSON API calls through that list, and every call is checked against the host's permission rule and run inside the host's account scope. The same list can be read back whole, or cut down to only the methods one person is allowed to call on one account, so an interface can show a person what they may do before they try it. That list, calling by name, the permission check and the account scope come from hub_kernel-interface, which hub_kernel depends on, so a hub that lists methods needs no second gem. Reach for hub_kernel when an app has several domain areas that should talk to each other only through declared entry points, and you want the app to refuse to start, or the suite to fail, when that is not true.
14
+ A hub also lists the methods outside callers may reach by name, with the values each takes and whether it writes. An interface such as a JSON API calls through that list, and every call is checked against the host's permission rule and run inside the host's account scope. The same list can be read back whole, or cut down to only the methods one person is allowed to call on one account, so an interface can show a person what they may do before they try it. That list, calling by name, the permission check and the account scope come from hub_kernel-interface, which hub_kernel depends on, so a hub that lists methods needs no second gem.
15
+
16
+ Every hub can also answer the business time zone and the current date in that zone, from one setting the host app makes for all hubs, so no hub has to declare a port of its own for it. Reach for hub_kernel when an app has several domain areas that should talk to each other only through declared entry points, and you want the app to refuse to start, or the suite to fail, when that is not true.
15
17
 
16
18
  ## Interface
17
19
 
18
20
  This local documents no commands. The surface belongs to the other two locals:
19
21
 
20
- - **hub_kernel-install** owns everything the host app does: adding the gem, filling each hub's ports, running the start check, setting the permission rule and the account scope, and adding the hub check and the crossing check to the host's tests.
21
- - **hub_kernel-develop** owns everything a hub's author does: generating a hub, declaring its ports, listing the methods callers may reach by name, reading that list back for a person and an account, refusing a request, and adding the check that the listed methods match the hub's real methods.
22
+ - **hub_kernel-install** owns everything the host app does: adding the gem, filling each hub's ports, running the start check, setting the permission rule, the account scope and the business time zone, and adding the hub check and the crossing check to the host's tests.
23
+ - **hub_kernel-develop** owns everything a hub's author does: generating a hub, declaring its ports, reading the business time zone and the current date in it, listing the methods callers may reach by name, reading that list back for a person and an account, refusing a request, and adding the check that the listed methods match the hub's real methods.
22
24
 
23
25
  ## How to use it
24
26
 
@@ -34,6 +36,7 @@ Decide which side you are on:
34
36
  - **Ports** — what a hub needs from outside. Each has a name and the method the hub's own code calls, such as a spend recorder called as record_spend.
35
37
  - **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.
36
38
  - **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.
39
+ - **Business time zone** — the one time zone every hub works in, which the host app sets once for all hubs and which is read again on each use, so a changed setting takes effect on the next call. A hub reading it while the app has not set it raises "hub_kernel's business time zone is not wired", and the start check does not look for it, so an app whose hubs never read it need not set one. A hub that declares its own time zone port keeps answering from that port instead.
37
40
  - **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.
38
41
  - **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.
39
42
  - **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.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: hub_kernel-install
3
- description: Use to hook hub_kernel into a project — adding the gem, filling each hub's ports and running the start check, listing the loaded hubs, setting the permission check and the account scope, and adding the hub check and the crossing check to the host's tests.
3
+ description: Use to hook hub_kernel into a project — adding the gem, filling each hub's ports and running the start check, listing the loaded hubs, setting the permission check and the account scope, setting the business time zone, and adding the hub check and the crossing check to the host's tests.
4
4
  tools: Bash, Read, Edit
5
5
  scope: hubs — a domain gem declares the ports it needs and the methods it exposes, and the host app fills those ports and checks each hub is wired and crosses into no other hub
6
6
  ---
@@ -8,15 +8,16 @@ scope: hubs — a domain gem declares the ports it needs and the methods it expo
8
8
  This local follows these steps exactly and invents none. Where a step needs a value only the developer knows, it asks.
9
9
 
10
10
  ## What hub_kernel is
11
- hub_kernel lets a Rails host app fill the ports each hub declares, refuse to start while a port is unfilled, answer permission and account scope for calls made by name, answer permission when an interface lists what a person may call, and fail its suite when one hub's code names a class another hub owns. Hook it in when the app uses hubs, its own or ones shipped in domain gems.
11
+ hub_kernel lets a Rails host app fill the ports each hub declares, refuse to start while a port is unfilled, answer permission and account scope for calls made by name, answer permission when an interface lists what a person may call, give every hub one business time zone, and fail its suite when one hub's code names a class another hub owns. Hook it in when the app uses hubs, its own or ones shipped in domain gems.
12
12
 
13
13
  ## Interface
14
14
  - `gem "hub_kernel"` — the Gemfile line that adds the gem to the host app.
15
15
  - `HubKernel::Hubs.check!` — raises `HubKernel::UnwiredPortError` naming every unfilled port of every loaded hub, one per line, such as "Supplies' spend recorder is not wired", and, while any loaded hub exposes a method, the permission check or the account scope when either is unset or cannot be called.
16
16
  - `HubKernel::Hubs.list` — the hubs that have loaded and declared at least one port or exposed at least one method.
17
- - `HubKernel::UnwiredPortError` — raised by the start check, by calling an unfilled port, and by a call by name while the permission check or the account scope is unset.
17
+ - `HubKernel::UnwiredPortError` — raised by the start check, by calling an unfilled port, by a call by name while the permission check or the account scope is unset, and by reading the business time zone before its reader is set.
18
18
  - `HubKernel::Authz.check` — the host-wide permission rule, a callable taking a person, an action and an account and answering `true` or `false`.
19
19
  - `HubKernel::Context.scope` — the host-wide account scope, a callable taking an account and a block and running the block inside that account.
20
+ - `HubKernel.time_zone_reader=` — sets the host-wide business time zone, a callable taking no arguments and answering a time zone name such as `"America/Chicago"`, which every hub reads for its time zone and today's date.
20
21
  - `HubKernel::Conformance::Hub` — a test module that fails naming each of one hub's ports left unfilled or filled with something that cannot be called.
21
22
  - `HubKernel::Crossings` — the crossing map: which classes each hub owns, the shared classes, the host's layer, each hub's interface module, and any namespace a hub owns whole.
22
23
  - `HubKernel::Conformance::Crossings` — a test module that reads the host's files against the crossing map and fails on each crossing, each unowned class, each class owned twice, and each mapped class that does not exist.
@@ -63,7 +64,23 @@ hub_kernel lets a Rails host app fill the ports each hub declares, refuse to sta
63
64
  - The permission check must answer exactly `true` or `false`, and any other answer makes the call or the listing raise an error.
64
65
  - The account scope must take the block and run it, or the hub method never runs.
65
66
 
66
- 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`:
67
+ 6. Ask the developer whether any hub reads the business time zone or today's date, and where the app keeps its time zone, since it has no default. Set the reader in the same `to_prepare` block:
68
+
69
+ ```ruby
70
+ Rails.application.config.to_prepare do
71
+ Supplies.spend_recorder = Finance.method(:record_spend)
72
+ HubKernel.time_zone_reader = -> { "America/Chicago" }
73
+ HubKernel::Hubs.check!
74
+ end
75
+ ```
76
+
77
+ - The reader takes no arguments and answers a time zone name, such as `"America/Chicago"`.
78
+ - The reader is called on every read, so a reader that looks up a stored setting, such as `-> { Setting.time_zone }`, picks up a change on the next call.
79
+ - The start check does not report an unset reader, so an app whose hubs never read the time zone may leave it unset.
80
+ - Reading the time zone or today's date while the reader is unset raises `HubKernel::UnwiredPortError` with "hub_kernel's business time zone is not wired".
81
+ - A hub that declares its own time zone port keeps its own zone, so fill that port in step 3 like any other.
82
+
83
+ 7. 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`:
67
84
 
68
85
  ```ruby
69
86
  require "hub_kernel/conformance/hub"
@@ -78,7 +95,7 @@ hub_kernel lets a Rails host app fill the ports each hub declares, refuse to sta
78
95
  - The `require` line is needed because the gem does not load the test modules on its own.
79
96
  - A hub that exposes methods but declares no port gets no hub check, since the check errors on a hub with no ports.
80
97
 
81
- 7. Ask the developer for the crossing map, since only they know which hub owns which class:
98
+ 8. Ask the developer for the crossing map, since only they know which hub owns which class:
82
99
  - which classes each hub owns;
83
100
  - which classes all hubs share, such as a base controller;
84
101
  - which hub name stands for the host's own layer;
@@ -87,7 +104,7 @@ hub_kernel lets a Rails host app fill the ports each hub declares, refuse to sta
87
104
 
88
105
  Also ask which files the check should read, and which to skip, such as the file that defines the interface modules.
89
106
 
90
- 8. Add the crossing check to the host's tests, such as `test/hub_crossings_test.rb`:
107
+ 9. Add the crossing check to the host's tests, such as `test/hub_crossings_test.rb`:
91
108
 
92
109
  ```ruby
93
110
  require "hub_kernel/conformance/crossings"
@@ -112,11 +129,13 @@ hub_kernel lets a Rails host app fill the ports each hub declares, refuse to sta
112
129
  - `except:` lists paths to skip, written relative to that folder.
113
130
  - Hub names are symbols, and class names are strings.
114
131
 
115
- 9. Run the app and the test suite, and confirm the checks below.
132
+ 10. Run the app and the test suite, and confirm the checks below.
116
133
 
117
134
  ## Conventions
118
135
  - After installing, `bin/rails runner 'HubKernel::Hubs.check!'` exits with no error, and every hub check and the crossing check pass.
136
+ - When the business time zone reader is set, `bin/rails runner 'puts HubKernel.time_zone, HubKernel.today'` prints the zone name and today's date in that zone.
119
137
  - The start check reports unfilled ports, and the permission check or account scope when unset or not callable while a hub exposes a method.
138
+ - The start check does not report the business time zone reader, so an unset reader surfaces only when a hub reads the time zone.
120
139
  - The hub check reports one hub's unfilled ports and each port filled with something that cannot be called, which the start check does not report.
121
140
  - 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.
122
141
  - 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.
@@ -125,5 +144,5 @@ hub_kernel lets a Rails host app fill the ports each hub declares, refuse to sta
125
144
  - A class listed by name under `owners` belongs to that hub even inside another hub's namespace.
126
145
  - The check for unowned classes reads only Ruby files outside `app/views`, so a view never needs its own entry in the map.
127
146
  - 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.
128
- - 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.
147
+ - 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 hub first reads the business time zone, set its reader 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.
129
148
  - Writing a hub, declaring its ports, and listing the methods it exposes are not part of installing and are out of scope here.
@@ -7,6 +7,7 @@ install:
7
7
  - HubKernel::UnwiredPortError
8
8
  - HubKernel::Authz.check
9
9
  - HubKernel::Context.scope
10
+ - HubKernel.time_zone_reader=
10
11
  - HubKernel::Conformance::Hub
11
12
  - HubKernel::Crossings
12
13
  - HubKernel::Conformance::Crossings
@@ -15,6 +16,10 @@ develop:
15
16
  - bin/rails generate hub_kernel:hub
16
17
  - HubKernel::Ports
17
18
  - port
19
+ - time_zone
20
+ - today
21
+ - HubKernel.time_zone
22
+ - HubKernel.today
18
23
  - HubKernel::Exposes
19
24
  - exposes
20
25
  - exposed
@@ -31,6 +36,7 @@ develop:
31
36
  sources:
32
37
  - lib/hub_kernel.rb
33
38
  - lib/hub_kernel/ports.rb
39
+ - lib/hub_kernel/business_clock.rb
34
40
  - lib/hub_kernel/hubs.rb
35
41
  - lib/hub_kernel/action.rb
36
42
  - lib/hub_kernel/crossings.rb
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hub_kernel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.0
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider
@@ -54,6 +54,7 @@ files:
54
54
  - lib/hub_kernel.rb
55
55
  - lib/hub_kernel/action.rb
56
56
  - lib/hub_kernel/answer.rb
57
+ - lib/hub_kernel/business_clock.rb
57
58
  - lib/hub_kernel/conformance/action.rb
58
59
  - lib/hub_kernel/conformance/crossings.rb
59
60
  - lib/hub_kernel/conformance/exposed.rb