coach 0.4.6 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/LICENSE.txt +22 -0
- data/README.md +7 -0
- data/coach.gemspec +1 -2
- data/lib/coach/handler.rb +21 -20
- data/lib/coach/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f7d2343c7e554691c7dc038d2673e23c46656fb
|
4
|
+
data.tar.gz: 2cd586a0f983cd8e357f230fc9cacfdf11dbf4ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6879f15e2f13a29c063274ebc59ddac2006e7343848d2e188f83821f6a796d0e61549cabbcc125c5d66790221b7fa9e618ad97064b4c61f982366f6cc6592f61
|
7
|
+
data.tar.gz: 88c3755e9df7000de77a7c0a5f0dc4e92c0ff4ba4257b4dba56580a7fc61b9f8067e66751c511317e94b5e386b4fcf8b1428b9988d494fd04f083a1856f14ca3
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
# 0.5.0 / 2017-08-07
|
4
|
+
|
5
|
+
* [https://github.com/gocardless/coach/pull/24](#24) Use
|
6
|
+
ActiveSupport.instrument for coach.handler.finish event. Potentially breaking
|
7
|
+
change as the coach.handler.finish subscribers may trigger twice, depending on
|
8
|
+
how users have subscribed to them.
|
2
9
|
|
3
10
|
# 0.4.6
|
4
11
|
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2017 GoCardless
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -292,3 +292,10 @@ solution to Rails `process_action.action_controller` event emitted on controller
|
|
292
292
|
|
293
293
|
The benchmarking data includes information on how long each middleware took to process,
|
294
294
|
along with the total duration of the chain.
|
295
|
+
|
296
|
+
# License & Contributing
|
297
|
+
|
298
|
+
* Coach is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
299
|
+
* Bug reports and pull requests are welcome on GitHub at https://github.com/gocardless/coach.
|
300
|
+
|
301
|
+
GoCardless ♥ open source. If you do too, come [join us](https://gocardless.com/about/jobs).
|
data/coach.gemspec
CHANGED
@@ -7,8 +7,7 @@ require 'coach/version'
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'coach'
|
9
9
|
spec.version = Coach::VERSION
|
10
|
-
spec.summary = '
|
11
|
-
spec.description = 'Controller framework'
|
10
|
+
spec.summary = 'Alternative controllers built with middleware'
|
12
11
|
spec.authors = %w[GoCardless]
|
13
12
|
spec.homepage = "https://github.com/gocardless/coach"
|
14
13
|
spec.email = %w[developers@gocardless.com]
|
data/lib/coach/handler.rb
CHANGED
@@ -15,6 +15,7 @@ module Coach
|
|
15
15
|
|
16
16
|
# Run validation on the root of the middleware chain
|
17
17
|
delegate :validate!, to: :@root_item
|
18
|
+
delegate :publish, :instrument, to: ActiveSupport::Notifications
|
18
19
|
|
19
20
|
# The Rack interface to handler - builds a middleware chain based on
|
20
21
|
# the current request, and invokes it.
|
@@ -23,20 +24,25 @@ module Coach
|
|
23
24
|
sequence = build_sequence(@root_item, context)
|
24
25
|
chain = build_request_chain(sequence, context)
|
25
26
|
|
26
|
-
|
27
|
-
start = Time.now
|
27
|
+
event = build_event(context)
|
28
28
|
|
29
|
-
publish('coach.handler.start',
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
29
|
+
publish('coach.handler.start', event.dup)
|
30
|
+
instrument('coach.handler.finish', event) do
|
31
|
+
begin
|
32
|
+
response = chain.instrument.call
|
33
|
+
ensure
|
34
|
+
# We want to populate the response and metadata fields after the middleware
|
35
|
+
# chain has completed so that the end of the instrumentation can see them. The
|
36
|
+
# simplest way to do this is pass the event by reference to ActiveSupport, then
|
37
|
+
# modify the hash to contain this detail before the instrumentation completes.
|
38
|
+
#
|
39
|
+
# This way, the last coach.handler.finish event will have all the details.
|
40
|
+
status = response.try(:first) || STATUS_CODE_FOR_EXCEPTIONS
|
41
|
+
event.merge!(
|
42
|
+
response: { status: status },
|
43
|
+
metadata: context.fetch(:_metadata, {})
|
44
|
+
)
|
45
|
+
end
|
40
46
|
end
|
41
47
|
end
|
42
48
|
|
@@ -65,19 +71,14 @@ module Coach
|
|
65
71
|
|
66
72
|
private
|
67
73
|
|
68
|
-
# Trigger ActiveSupport::Notification
|
69
|
-
def publish(name, *args)
|
70
|
-
ActiveSupport::Notifications.publish(name, *args)
|
71
|
-
end
|
72
|
-
|
73
74
|
# Remove middleware that have been included multiple times with the same
|
74
75
|
# config, leaving only the first instance
|
75
76
|
def dedup_sequence(sequence)
|
76
77
|
sequence.uniq { |item| [item.class, item.middleware, item.config] }
|
77
78
|
end
|
78
79
|
|
79
|
-
# Event to send
|
80
|
-
def
|
80
|
+
# Event to send with notifications
|
81
|
+
def build_event(context)
|
81
82
|
{
|
82
83
|
middleware: @root_item.middleware.name,
|
83
84
|
request: context[:request]
|
data/lib/coach/version.rb
CHANGED
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
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GoCardless
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.49.1
|
97
|
-
description:
|
97
|
+
description:
|
98
98
|
email:
|
99
99
|
- developers@gocardless.com
|
100
100
|
executables: []
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- ".travis.yml"
|
108
108
|
- CHANGELOG.md
|
109
109
|
- Gemfile
|
110
|
+
- LICENSE.txt
|
110
111
|
- README.md
|
111
112
|
- coach.gemspec
|
112
113
|
- lib/coach.rb
|
@@ -149,10 +150,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
150
|
version: '0'
|
150
151
|
requirements: []
|
151
152
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.6.
|
153
|
+
rubygems_version: 2.6.8
|
153
154
|
signing_key:
|
154
155
|
specification_version: 4
|
155
|
-
summary:
|
156
|
+
summary: Alternative controllers built with middleware
|
156
157
|
test_files:
|
157
158
|
- spec/lib/coach/handler_spec.rb
|
158
159
|
- spec/lib/coach/middleware_spec.rb
|