hub_kernel 0.1.0 → 0.2.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 +26 -2
- data/lib/hub_kernel/ports.rb +21 -0
- data/lib/hub_kernel/version.rb +1 -1
- data/lib/hub_kernel.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d0aadeed46c5d7c19209c32b3fb4de077a80ebb2670d5f5545918fe3f9421e14
|
|
4
|
+
data.tar.gz: d3f57b2de645c719357101e13752b464b67c31ea38fa169281c7213c95c6f273
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2b78566e883135e653f2638c2986ba74e14153443b56fd923a14a6dae50eef107acbdc9ccf6c96774d8c96fce7802497a2643f66c316f3186ef976a5bb031a85
|
|
7
|
+
data.tar.gz: a939a5363771f77fedf2f4c647a5e67287a6bef22fac61665a5d818f5667ed6a066fda7227efbd8b8a115f17ddbd197e14a271b8d82005d559df2bd5a19d0fdc
|
data/README.md
CHANGED
|
@@ -1,8 +1,32 @@
|
|
|
1
1
|
# HubKernel
|
|
2
|
-
|
|
2
|
+
Gives every hub in a Rails app one way to declare what it needs from another hub.
|
|
3
3
|
|
|
4
4
|
## Usage
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
### Ports
|
|
7
|
+
A port is something a hub needs from outside itself. The hub declares it by name,
|
|
8
|
+
with the method its own code calls:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
module Supplies
|
|
12
|
+
extend HubKernel::Ports
|
|
13
|
+
|
|
14
|
+
port :spend_recorder, as: :record_spend
|
|
15
|
+
end
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The app fills each port with any callable, usually another hub's method:
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
Rails.application.config.to_prepare do
|
|
22
|
+
Supplies.spend_recorder = Finance.method(:record_spend)
|
|
23
|
+
end
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`Supplies.record_spend(amount: 5)` then calls what the app filled the port with and
|
|
27
|
+
returns its answer. An error it raises reaches the caller unchanged. Calling a port the
|
|
28
|
+
app left unfilled raises `HubKernel::UnwiredPortError`, such as "Supplies' spend
|
|
29
|
+
recorder is not wired".
|
|
6
30
|
|
|
7
31
|
## Installation
|
|
8
32
|
Add this line to your application's Gemfile:
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "active_support/core_ext/string/inflections"
|
|
2
|
+
|
|
3
|
+
module HubKernel
|
|
4
|
+
class UnwiredPortError < StandardError; end
|
|
5
|
+
|
|
6
|
+
module Ports
|
|
7
|
+
def port(name, as:)
|
|
8
|
+
singleton_class.attr_writer name
|
|
9
|
+
define_singleton_method(name) { instance_variable_get(:"@#{name}") || unwired(name) }
|
|
10
|
+
define_singleton_method(as) { |*args, **options| public_send(name).call(*args, **options) }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def unwired(name)
|
|
16
|
+
->(*, **) { raise UnwiredPortError, "#{hub_name} #{name.to_s.tr("_", " ")} is not wired" }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def hub_name = self.name.demodulize.then { |hub| hub.end_with?("s") ? "#{hub}'" : "#{hub}'s" }
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/hub_kernel/version.rb
CHANGED
data/lib/hub_kernel.rb
CHANGED
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.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- tylercschneider
|
|
@@ -47,6 +47,7 @@ files:
|
|
|
47
47
|
- lib/hub_kernel/events.rb
|
|
48
48
|
- lib/hub_kernel/follow_up.rb
|
|
49
49
|
- lib/hub_kernel/markup.rb
|
|
50
|
+
- lib/hub_kernel/ports.rb
|
|
50
51
|
- lib/hub_kernel/version.rb
|
|
51
52
|
homepage: https://github.com/tylercschneider/hub_kernel
|
|
52
53
|
licenses:
|