coach 0.4.5 → 0.4.6
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/.rubocop.yml +12 -21
- data/CHANGELOG.md +7 -0
- data/README.md +1 -0
- data/coach.gemspec +4 -3
- data/lib/coach/handler.rb +12 -9
- data/lib/coach/notifications.rb +2 -2
- data/lib/coach/version.rb +1 -1
- data/spec/lib/coach/handler_spec.rb +35 -3
- data/spec/lib/coach/notifications_spec.rb +1 -1
- data/spec/lib/coach/request_benchmark_spec.rb +1 -1
- data/spec/lib/coach/router_spec.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e57234c99f6622d05b93fed13fb589250cab7082
|
4
|
+
data.tar.gz: 950d40743209a397c5509438b2056a9aa06e16ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 926d433306e25f0aba99f433a491b135e17405da467b5baaf36466d96929aeb7fc42204321b88ca74855e1a01dbe7f158b16474cfe905ce6ba3a3a259f2a93f1
|
7
|
+
data.tar.gz: 1b79b97214372ffa5411cd6c94d165af8efee424a4cf3542b0e91755ea34bac765d1f9873ad4e1584dd2f02ca4f17cf8f9557e958cbe1b71838792b4f67ab49f
|
data/.rubocop.yml
CHANGED
@@ -4,27 +4,14 @@
|
|
4
4
|
LineLength:
|
5
5
|
Max: 90
|
6
6
|
|
7
|
-
ClassLength:
|
8
|
-
Enabled: false
|
9
|
-
|
10
|
-
ModuleLength:
|
11
|
-
Enabled: false
|
12
|
-
|
13
7
|
# Avoid methods longer than 30 lines of code
|
14
8
|
MethodLength:
|
15
9
|
CountComments: false # count full line comments?
|
16
|
-
Max:
|
17
|
-
|
18
|
-
# Avoid single-line methods.
|
19
|
-
SingleLineMethods:
|
20
|
-
AllowIfMethodIsEmpty: true
|
10
|
+
Max: 16
|
21
11
|
|
22
12
|
StringLiterals:
|
23
13
|
Enabled: false
|
24
14
|
|
25
|
-
GlobalVars:
|
26
|
-
Enabled: false # We use them Redis + StatsD (though maybe we shouldn't?)
|
27
|
-
|
28
15
|
# Wants underscores in all large numbers. Pain in the ass for things like
|
29
16
|
# unix timestamps.
|
30
17
|
NumericLiterals:
|
@@ -39,7 +26,7 @@ Style/SignalException:
|
|
39
26
|
EnforcedStyle: 'only_raise'
|
40
27
|
|
41
28
|
# Use trailing rather than leading dots on multi-line call chains
|
42
|
-
|
29
|
+
Layout/DotPosition:
|
43
30
|
EnforcedStyle: trailing
|
44
31
|
|
45
32
|
Lint/NestedMethodDefinition:
|
@@ -65,7 +52,7 @@ Style/AsciiComments:
|
|
65
52
|
Enabled: false
|
66
53
|
|
67
54
|
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
|
68
|
-
|
55
|
+
Layout/AlignHash:
|
69
56
|
Enabled: false
|
70
57
|
|
71
58
|
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
|
@@ -76,7 +63,7 @@ Style/BlockDelimiters:
|
|
76
63
|
Style/ClassAndModuleChildren:
|
77
64
|
Enabled: false
|
78
65
|
|
79
|
-
|
66
|
+
Layout/ClosingParenthesisIndentation:
|
80
67
|
Enabled: false
|
81
68
|
|
82
69
|
# Configuration parameters: Keywords.
|
@@ -94,14 +81,14 @@ Style/GuardClause:
|
|
94
81
|
Enabled: false
|
95
82
|
|
96
83
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
97
|
-
|
84
|
+
Layout/IndentHash:
|
98
85
|
Enabled: false
|
99
86
|
|
100
87
|
Style/Lambda:
|
101
88
|
Enabled: false
|
102
89
|
|
103
90
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
104
|
-
|
91
|
+
Layout/MultilineOperationIndentation:
|
105
92
|
Enabled: false
|
106
93
|
|
107
94
|
# Configuration parameters: NamePrefix, NamePrefixBlacklist.
|
@@ -111,13 +98,17 @@ Style/PredicateName:
|
|
111
98
|
Style/RedundantSelf:
|
112
99
|
Enabled: false
|
113
100
|
|
114
|
-
|
101
|
+
Layout/SpaceBeforeFirstArg:
|
115
102
|
Enabled: false
|
116
103
|
|
117
104
|
# Configuration parameters: MultiSpaceAllowedForOperators.
|
118
|
-
|
105
|
+
Layout/SpaceAroundOperators:
|
119
106
|
Enabled: false
|
120
107
|
|
121
108
|
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist.
|
122
109
|
Style/TrivialAccessors:
|
123
110
|
Enabled: false
|
111
|
+
|
112
|
+
Metrics/BlockLength:
|
113
|
+
Exclude:
|
114
|
+
- "**/*_spec.rb"
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/coach.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'coach/version'
|
@@ -8,9 +9,9 @@ Gem::Specification.new do |spec|
|
|
8
9
|
spec.version = Coach::VERSION
|
9
10
|
spec.summary = 'coach middleware'
|
10
11
|
spec.description = 'Controller framework'
|
11
|
-
spec.authors = %w
|
12
|
+
spec.authors = %w[GoCardless]
|
12
13
|
spec.homepage = "https://github.com/gocardless/coach"
|
13
|
-
spec.email = %w
|
14
|
+
spec.email = %w[developers@gocardless.com]
|
14
15
|
spec.license = 'MIT'
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -23,5 +24,5 @@ Gem::Specification.new do |spec|
|
|
23
24
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
24
25
|
spec.add_development_dependency 'rspec-its', '~> 1.2'
|
25
26
|
spec.add_development_dependency 'pry', '~> 0.10'
|
26
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
27
|
+
spec.add_development_dependency 'rubocop', '~> 0.49.1'
|
27
28
|
end
|
data/lib/coach/handler.rb
CHANGED
@@ -2,6 +2,8 @@ require "coach/errors"
|
|
2
2
|
|
3
3
|
module Coach
|
4
4
|
class Handler
|
5
|
+
STATUS_CODE_FOR_EXCEPTIONS = 500
|
6
|
+
|
5
7
|
def initialize(middleware, config = {})
|
6
8
|
@root_item = MiddlewareItem.new(middleware, config)
|
7
9
|
validate!
|
@@ -25,16 +27,17 @@ module Coach
|
|
25
27
|
start = Time.now
|
26
28
|
|
27
29
|
publish('coach.handler.start', start_event.dup)
|
28
|
-
response = chain.instrument.call
|
29
|
-
|
30
|
-
finish = Time.now
|
31
|
-
publish('coach.handler.finish',
|
32
|
-
start, finish, nil,
|
33
|
-
start_event.
|
34
|
-
merge(response: { status: response[0] },
|
35
|
-
metadata: context.fetch(:_metadata, {})))
|
36
30
|
|
37
|
-
|
31
|
+
begin
|
32
|
+
response = chain.instrument.call
|
33
|
+
ensure
|
34
|
+
status = response.try(:first) || STATUS_CODE_FOR_EXCEPTIONS
|
35
|
+
publish('coach.handler.finish', start, Time.now, nil,
|
36
|
+
start_event.merge(
|
37
|
+
response: { status: status },
|
38
|
+
metadata: context.fetch(:_metadata, {})
|
39
|
+
))
|
40
|
+
end
|
38
41
|
end
|
39
42
|
|
40
43
|
# Traverse the middlware tree to build a linear middleware sequence,
|
data/lib/coach/notifications.rb
CHANGED
@@ -32,11 +32,11 @@ module Coach
|
|
32
32
|
@benchmarks[event[:request].uuid] = RequestBenchmark.new(event[:middleware])
|
33
33
|
end
|
34
34
|
|
35
|
-
@subscriptions << subscribe('middleware.finish') do |
|
35
|
+
@subscriptions << subscribe('middleware.finish') do |_name, start, finish, _, event|
|
36
36
|
log_middleware_finish(event, start, finish)
|
37
37
|
end
|
38
38
|
|
39
|
-
@subscriptions << subscribe('handler.finish') do |
|
39
|
+
@subscriptions << subscribe('handler.finish') do |_name, start, finish, _, event|
|
40
40
|
log_handler_finish(event, start, finish)
|
41
41
|
end
|
42
42
|
end
|
data/lib/coach/version.rb
CHANGED
@@ -26,7 +26,7 @@ describe Coach::Handler do
|
|
26
26
|
result = handler.call({})
|
27
27
|
expect(a_spy).to have_received(:call)
|
28
28
|
expect(b_spy).to have_received(:call)
|
29
|
-
expect(result).to eq(%w
|
29
|
+
expect(result).to eq(%w[A{} B{} Terminal{:handler=>true}])
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -94,7 +94,7 @@ describe Coach::Handler do
|
|
94
94
|
|
95
95
|
it "sets up the chain correctly, calling each item in the correct order" do
|
96
96
|
expect(handler.build_request_chain(sequence, {}).call).
|
97
|
-
to eq(%w
|
97
|
+
to eq(%w[A{} B{:b=>true} Terminal{}])
|
98
98
|
end
|
99
99
|
|
100
100
|
context "with inheriting config" do
|
@@ -103,7 +103,7 @@ describe Coach::Handler do
|
|
103
103
|
|
104
104
|
it "calls lambda with parent middlewares config" do
|
105
105
|
expect(handler.build_request_chain(sequence, {}).call).
|
106
|
-
to eq(%w
|
106
|
+
to eq(%w[A{} C{:b=>true} D{} B{:b=>true} Terminal{}])
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
@@ -137,6 +137,38 @@ describe Coach::Handler do
|
|
137
137
|
it { is_expected.to include('coach.request') }
|
138
138
|
it { is_expected.to include('coach.middleware.finish') }
|
139
139
|
it { is_expected.to include('coach.handler.finish') }
|
140
|
+
|
141
|
+
context "when an exception is raised in the chain" do
|
142
|
+
let(:explosive_action) { -> { raise "AH" } }
|
143
|
+
before { terminal_middleware.uses(middleware_a, callback: explosive_action) }
|
144
|
+
|
145
|
+
subject(:coach_events) do
|
146
|
+
events = []
|
147
|
+
subscription = ActiveSupport::Notifications.subscribe(/coach/) do |name, *args|
|
148
|
+
events << [name, args.last]
|
149
|
+
end
|
150
|
+
|
151
|
+
begin
|
152
|
+
handler.call({})
|
153
|
+
rescue
|
154
|
+
:continue_anyway
|
155
|
+
end
|
156
|
+
ActiveSupport::Notifications.unsubscribe(subscription)
|
157
|
+
events
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should capture the error event with the metadata " do
|
161
|
+
is_expected.
|
162
|
+
to include(['coach.handler.finish', hash_including(
|
163
|
+
response: { status: 500 },
|
164
|
+
metadata: { A: true }
|
165
|
+
)])
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should bubble the error to the next handler" do
|
169
|
+
expect { handler.call({}) }.to raise_error(StandardError, "AH")
|
170
|
+
end
|
171
|
+
end
|
140
172
|
end
|
141
173
|
end
|
142
174
|
|
@@ -53,7 +53,7 @@ describe Coach::Notifications do
|
|
53
53
|
|
54
54
|
it "contains all middleware that have been run" do
|
55
55
|
middleware_names = middleware_event[:chain].map { |item| item[:name] }
|
56
|
-
expect(middleware_names).to include(
|
56
|
+
expect(middleware_names).to include('Terminal', 'A', 'B')
|
57
57
|
end
|
58
58
|
|
59
59
|
it "includes all logged metadata" do
|
@@ -13,7 +13,7 @@ describe Coach::Router do
|
|
13
13
|
|
14
14
|
let(:resource_routes) do
|
15
15
|
routes_module = Module.new
|
16
|
-
[
|
16
|
+
%i[Index Show Create Update Destroy Refund].each do |class_name|
|
17
17
|
routes_module.const_set(class_name, Class.new)
|
18
18
|
end
|
19
19
|
routes_module
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coach
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GoCardless
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: 0.49.1
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: 0.49.1
|
97
97
|
description: Controller framework
|
98
98
|
email:
|
99
99
|
- developers@gocardless.com
|
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
149
|
version: '0'
|
150
150
|
requirements: []
|
151
151
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.6.
|
152
|
+
rubygems_version: 2.6.11
|
153
153
|
signing_key:
|
154
154
|
specification_version: 4
|
155
155
|
summary: coach middleware
|