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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e433f46a0cd33d7236e9f57f150a4c8e59b778a320c4dcf1252093a405fbcce
4
- data.tar.gz: c8898bc61f4c65dd72a0008ca1dd75e36508102089636964c68da9ec4863115a
3
+ metadata.gz: d0aadeed46c5d7c19209c32b3fb4de077a80ebb2670d5f5545918fe3f9421e14
4
+ data.tar.gz: d3f57b2de645c719357101e13752b464b67c31ea38fa169281c7213c95c6f273
5
5
  SHA512:
6
- metadata.gz: a453b3e41b68ba7f7b9c06b31546fb92ec0d840e6f949657a5a5ec6a8d4b4708d88c3fd21963bd37fe9ebb224362a69e4d287d20f65c24eb275d557dacdee923
7
- data.tar.gz: 1eb7d7a09b26da2997ebee5145d148c5f98111fe8372b868e3bdb1290bc2decb401aa406fe6405844d9b0aa00527ef03101939482c970f0f7e3de35ad40da4d1
6
+ metadata.gz: 2b78566e883135e653f2638c2986ba74e14153443b56fd923a14a6dae50eef107acbdc9ccf6c96774d8c96fce7802497a2643f66c316f3186ef976a5bb031a85
7
+ data.tar.gz: a939a5363771f77fedf2f4c647a5e67287a6bef22fac61665a5d818f5667ed6a066fda7227efbd8b8a115f17ddbd197e14a271b8d82005d559df2bd5a19d0fdc
data/README.md CHANGED
@@ -1,8 +1,32 @@
1
1
  # HubKernel
2
- Short description and motivation.
2
+ Gives every hub in a Rails app one way to declare what it needs from another hub.
3
3
 
4
4
  ## Usage
5
- How to use my plugin.
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
@@ -1,3 +1,3 @@
1
1
  module HubKernel
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/hub_kernel.rb CHANGED
@@ -4,6 +4,7 @@ require "hub_kernel/action"
4
4
  require "hub_kernel/answer"
5
5
  require "hub_kernel/follow_up"
6
6
  require "hub_kernel/markup"
7
+ require "hub_kernel/ports"
7
8
 
8
9
  module HubKernel
9
10
  end
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.1.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: