hub_kernel 0.6.0 → 0.7.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 +12 -0
- data/lib/generators/hub_kernel/hub/hub_generator.rb +38 -0
- data/lib/hub_kernel/version.rb +1 -1
- 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: 03e711745ec2a1b5caccf83f09e80cad02ba4214cc7eff72745c2a6d760e175e
|
|
4
|
+
data.tar.gz: f3bc9c33cd2f1ae4878f9cb9dd2216ebda64c2c3628f7d1a29794dee4f10ef11
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 443d578d53ebb20b08fb3e3c3557df70780f8f85e8aab44af99c68ee6f3311897649210b544ba6356b4d1e7a1692576e36e84c36daed045ab2d47270ddc69b2c
|
|
7
|
+
data.tar.gz: 833fba7864e95ad4ff7e18284bd07998f7ff30df5269489c879a447541e207997ebeb09d2dafad1596aa0299c7a05259d2e997682c6b5edffe490772f405a061
|
data/README.md
CHANGED
|
@@ -3,6 +3,18 @@ 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
|
+
### Starting a hub
|
|
7
|
+
The generator writes a new hub's module and its test. Name each port as the port and
|
|
8
|
+
the method the hub's own code calls:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
bin/rails generate hub_kernel:hub Console::Hubs::Billing spend_recorder:record_spend
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
It writes `app/models/console/hubs/billing.rb`, which extends `HubKernel::Ports` and
|
|
15
|
+
declares each port, and `test/models/console/hubs/billing_test.rb`, which includes the
|
|
16
|
+
hub check below. The app then fills the new ports where it fills its others.
|
|
17
|
+
|
|
6
18
|
### Ports
|
|
7
19
|
A port is something a hub needs from outside itself. The hub declares it by name,
|
|
8
20
|
with the method its own code calls:
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require "rails/generators/named_base"
|
|
2
|
+
|
|
3
|
+
module HubKernel
|
|
4
|
+
module Generators
|
|
5
|
+
class HubGenerator < Rails::Generators::NamedBase
|
|
6
|
+
argument :ports, type: :array, default: [], banner: "port:method port:method"
|
|
7
|
+
|
|
8
|
+
def create_hub
|
|
9
|
+
create_file "app/models/#{file_path}.rb", <<~RUBY
|
|
10
|
+
module #{class_name}
|
|
11
|
+
extend HubKernel::Ports
|
|
12
|
+
#{port_lines}end
|
|
13
|
+
RUBY
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def create_hub_test
|
|
17
|
+
create_file "test/models/#{file_path}_test.rb", <<~RUBY
|
|
18
|
+
require "test_helper"
|
|
19
|
+
require "hub_kernel/conformance/hub"
|
|
20
|
+
|
|
21
|
+
class #{class_name}Test < ActiveSupport::TestCase
|
|
22
|
+
include HubKernel::Conformance::Hub
|
|
23
|
+
|
|
24
|
+
hub { #{class_name} }
|
|
25
|
+
end
|
|
26
|
+
RUBY
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def port_lines
|
|
32
|
+
return "" if ports.empty?
|
|
33
|
+
|
|
34
|
+
"\n" + ports.map { |pair| pair.split(":") }.map { |port, method| " port :#{port}, as: :#{method}\n" }.join
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/lib/hub_kernel/version.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.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- tylercschneider
|
|
@@ -36,6 +36,7 @@ files:
|
|
|
36
36
|
- README.md
|
|
37
37
|
- Rakefile
|
|
38
38
|
- config/routes.rb
|
|
39
|
+
- lib/generators/hub_kernel/hub/hub_generator.rb
|
|
39
40
|
- lib/hub_kernel.rb
|
|
40
41
|
- lib/hub_kernel/action.rb
|
|
41
42
|
- lib/hub_kernel/answer.rb
|