hub_kernel 0.8.0 → 0.9.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 +18 -0
- data/lib/hub_kernel/conformance/exposed.rb +22 -0
- data/lib/hub_kernel/exposes.rb +21 -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: 6c55c177c5ca371059cf35185392a5b283a314254dff6b18aa2d13f7c12793cd
|
|
4
|
+
data.tar.gz: 23afef8f196447cecf97c1b2e0355aba897388784e2c1ddb80d6ff7ff9da7f98
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 61caa0ec7d31d6fbd86dc005dae507895eb2a7e4a1f1c09b3be2976edbc8ff69b5f14108a007dffe38b501b4d773250544ed625457d87e8ed7cbdf7f811796ff
|
|
7
|
+
data.tar.gz: 532c56d1800f02ab79faab68553fc75edd7f20bdcbc8677d2a4e7416dde7ec063ff79c94825db9bf99f10bd380b5874d52657e6beef5a03b8ef08532b6c71a93
|
data/README.md
CHANGED
|
@@ -116,6 +116,24 @@ Supplies.exposed("record_purchase").takes # => [:supplier_id, :bought_on, :lines
|
|
|
116
116
|
Supplies.exposed("delete_everything") # => nil
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
+
### The exposed-list check
|
|
120
|
+
A hub's own test can check its exposed list, so a listed method the hub lacks, or one
|
|
121
|
+
listed with values it does not take, shows in the suite rather than on a caller's
|
|
122
|
+
request:
|
|
123
|
+
|
|
124
|
+
```ruby
|
|
125
|
+
require "hub_kernel/conformance/exposed"
|
|
126
|
+
|
|
127
|
+
class SuppliesHubTest < ActiveSupport::TestCase
|
|
128
|
+
include HubKernel::Conformance::Exposed
|
|
129
|
+
|
|
130
|
+
hub { Supplies }
|
|
131
|
+
end
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The test fails and names each problem. A method that takes `**` values accepts any
|
|
135
|
+
values it is listed with, as long as it is listed with each value it requires.
|
|
136
|
+
|
|
119
137
|
## Installation
|
|
120
138
|
Add this line to your application's Gemfile:
|
|
121
139
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require "active_support/concern"
|
|
2
|
+
|
|
3
|
+
module HubKernel
|
|
4
|
+
module Conformance
|
|
5
|
+
module Exposed
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
class_methods do
|
|
9
|
+
def hub(&block)
|
|
10
|
+
define_method(:the_hub, &block)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
included do
|
|
15
|
+
test "every method the hub exposes exists and takes the values it is listed with" do
|
|
16
|
+
problems = the_hub.exposure_problems
|
|
17
|
+
flunk problems.join("\n") if problems.any?
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/hub_kernel/exposes.rb
CHANGED
|
@@ -8,8 +8,29 @@ module HubKernel
|
|
|
8
8
|
|
|
9
9
|
def exposed(name) = exposed_methods[name.to_s]
|
|
10
10
|
|
|
11
|
+
def exposure_problems
|
|
12
|
+
exposed_methods.values.filter_map { |exposure| exposure_problem(exposure) }
|
|
13
|
+
end
|
|
14
|
+
|
|
11
15
|
private
|
|
12
16
|
|
|
13
17
|
def exposed_methods = @exposed_methods ||= {}
|
|
18
|
+
|
|
19
|
+
def exposing_hub = name.demodulize
|
|
20
|
+
|
|
21
|
+
def exposure_problem(exposure)
|
|
22
|
+
return "#{exposing_hub} exposes #{exposure.name}, which it has no method for" unless respond_to?(exposure.name)
|
|
23
|
+
return if takes_listed_values?(exposure)
|
|
24
|
+
|
|
25
|
+
"#{exposing_hub} exposes #{exposure.name} with #{exposure.takes.join(", ")}, but it takes #{keywords(exposure, :keyreq, :key).join(", ")}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def takes_listed_values?(exposure)
|
|
29
|
+
(keywords(exposure, :keyreq) - exposure.takes).empty? && (takes_any_values?(exposure) || (exposure.takes - keywords(exposure, :keyreq, :key)).empty?)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def takes_any_values?(exposure) = method(exposure.name).parameters.any? { |kind, _| kind == :keyrest }
|
|
33
|
+
|
|
34
|
+
def keywords(exposure, *kinds) = method(exposure.name).parameters.filter_map { |kind, value| value if kinds.include?(kind) }
|
|
14
35
|
end
|
|
15
36
|
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.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- tylercschneider
|
|
@@ -42,6 +42,7 @@ files:
|
|
|
42
42
|
- lib/hub_kernel/answer.rb
|
|
43
43
|
- lib/hub_kernel/authz.rb
|
|
44
44
|
- lib/hub_kernel/conformance/action.rb
|
|
45
|
+
- lib/hub_kernel/conformance/exposed.rb
|
|
45
46
|
- lib/hub_kernel/conformance/hub.rb
|
|
46
47
|
- lib/hub_kernel/conformance/partial.rb
|
|
47
48
|
- lib/hub_kernel/context.rb
|