coach 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 583ecf9273bec38ea336716e04040e1a54963420
4
- data.tar.gz: c146e2fae603876b52609e84b9072286ce7ebc7a
3
+ metadata.gz: 4ebc75727eb21c437f4c87e17c22cfa510cf1099
4
+ data.tar.gz: 7692f0ca06eda58733aa439d59f199be7cc3006b
5
5
  SHA512:
6
- metadata.gz: 15a7a7b2c1ceaa01b1517cae1b3092376fcfa21447f100d48323b5140a866d22b41f033091cefa1817824cffe69f98253daa92fa8dac71be9e6116dd2caf1720
7
- data.tar.gz: 344e639454c1438bc1621da64580c975f6e1e062d35b9318d808e04d16f933eee5587075b7847bb107a284b78a91027d78ec41d49255b93d8005ff0384b6c3af
6
+ metadata.gz: 7da80cb20c4ef1540313b237fb1a6ce85eb4568e8e130ececb62c16573edd6aef795bd6b6492c98d4fe8bffb0330ff994e2298b8c5ead69f0a5365662888a944
7
+ data.tar.gz: fca5266c4df70946d81f497f242a0c7549ea9897975e4b60f570c91fa616c98dbbcb5deb320a3a909982e892a33e80c37e4a5fcfe9c4c4fa6726933463de9e5a
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  *.gem
2
+ Gemfile.lock
@@ -0,0 +1,33 @@
1
+ # 0.4.0 / 2015-12-21
2
+
3
+ * `Coach::Router.new` now accepts a `ActionDispatch::Routing::Mapper`, rather
4
+ than a `Rails::Application`. This means that when initialising a
5
+ `Coach::Router` from within a `routes.draw` block, you may now pass `self` to
6
+ the router, preserving surrounding context (e.g. block-level scopes).
7
+
8
+
9
+ # 0.3.0 / 2015-11-24
10
+
11
+ * Allow Handler to take a config hash, just like Middleware
12
+
13
+
14
+ # 0.2.3 / 2015-08-24
15
+
16
+ * Allow config values to be inherited
17
+
18
+
19
+ # 0.2.2 / 2015-07-17
20
+
21
+ * Diagramatic errors of missing requirements
22
+
23
+
24
+ # 0.2.1 / 2015-06-29
25
+
26
+ * Logging of metadata with ActiveSupport notifications
27
+
28
+
29
+ # 0.2.0 / 2015-06-17
30
+
31
+ Initial public release. This library is in beta until it hits 1.0, so backwards
32
+ incompatible changes may be made in minor version releases.
33
+
data/README.md CHANGED
@@ -224,20 +224,22 @@ end
224
224
  ## Routing
225
225
 
226
226
  For routes that represent resource actions, Coach provides some syntactic sugar to
227
- allow concise mapping of endpoint to handler.
227
+ allow concise mapping of endpoint to handler in Rails apps.
228
228
 
229
229
  ```ruby
230
- router = Coach::Router.new(Example::Application)
231
-
232
- router.draw(Routes::Users,
233
- base: "/users",
234
- actions: [
235
- :index,
236
- :show,
237
- :create,
238
- :update,
239
- disable: { method: :post, url: "/:id/actions/disable" }
240
- ])
230
+ # config/routes.rb
231
+ Example::Application.routes.draw do
232
+ router = Coach::Router.new(self)
233
+ router.draw(Routes::Users,
234
+ base: "/users",
235
+ actions: [
236
+ :index,
237
+ :show,
238
+ :create,
239
+ :update,
240
+ disable: { method: :post, url: "/:id/actions/disable" }
241
+ ])
242
+ end
241
243
  ```
242
244
 
243
245
  Default actions that conform to standard REST principles can be easily loaded, with the
@@ -6,7 +6,6 @@ require 'coach/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'coach'
8
8
  spec.version = Coach::VERSION
9
- spec.date = '2015-11-24'
10
9
  spec.summary = 'coach middleware'
11
10
  spec.description = 'Controller framework'
12
11
  spec.authors = %w(GoCardless)
@@ -21,8 +20,8 @@ Gem::Specification.new do |spec|
21
20
  spec.add_dependency 'actionpack', '~> 4.2'
22
21
  spec.add_dependency 'activesupport', '~> 4.2'
23
22
 
24
- spec.add_development_dependency 'rspec', '~> 3.2.0'
25
- spec.add_development_dependency 'rspec-its', '~> 1.2.0'
26
- spec.add_development_dependency 'pry'
27
- spec.add_development_dependency 'rubocop'
23
+ spec.add_development_dependency 'rspec', '~> 3.2'
24
+ spec.add_development_dependency 'rspec-its', '~> 1.2'
25
+ spec.add_development_dependency 'pry', '~> 0.10'
26
+ spec.add_development_dependency 'rubocop', '~> 0.32'
28
27
  end
@@ -2,8 +2,8 @@ require "coach/errors"
2
2
 
3
3
  module Coach
4
4
  class Handler
5
- def initialize(middleware)
6
- @root_item = MiddlewareItem.new(middleware)
5
+ def initialize(middleware, config = {})
6
+ @root_item = MiddlewareItem.new(middleware, config)
7
7
  validate!
8
8
  rescue Coach::Errors::MiddlewareDependencyNotMet => error
9
9
  # Remove noise of validation stack trace, reset to the handler callsite
@@ -11,8 +11,8 @@ module Coach
11
11
  destroy: { method: :delete, url: ':id' }
12
12
  }.each_value(&:freeze).freeze
13
13
 
14
- def initialize(app)
15
- @app = app
14
+ def initialize(mapper)
15
+ @mapper = mapper
16
16
  end
17
17
 
18
18
  def draw(routes, base: nil, as: nil, constraints: nil, actions: [])
@@ -27,9 +27,7 @@ module Coach
27
27
  end
28
28
 
29
29
  def match(url, **args)
30
- @app.routes.draw do
31
- match url, args
32
- end
30
+ @mapper.match(url, args)
33
31
  end
34
32
 
35
33
  private
@@ -1,3 +1,3 @@
1
1
  module Coach
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -14,11 +14,13 @@ def build_middleware(name)
14
14
  config[:callback].call if config.include?(:callback)
15
15
  log_metadata(Hash[name.to_sym, true])
16
16
 
17
+ response = [name + config.except(:callback).inspect.to_s]
18
+
17
19
  # Build up a list of middleware called, in the order they were called
18
20
  if next_middleware
19
- [name + config.except(:callback).inspect.to_s].concat(next_middleware.call)
21
+ response.concat(next_middleware.call)
20
22
  else
21
- [name]
23
+ response
22
24
  end
23
25
  end
24
26
  end
@@ -11,7 +11,7 @@ describe Coach::Handler do
11
11
  let(:middleware_d) { build_middleware("D") }
12
12
 
13
13
  let(:terminal_middleware) { build_middleware("Terminal") }
14
- let(:handler) { Coach::Handler.new(terminal_middleware) }
14
+ let(:handler) { Coach::Handler.new(terminal_middleware, handler: true) }
15
15
 
16
16
  before { Coach::Notifications.unsubscribe! }
17
17
 
@@ -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(A{} B{} Terminal))
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(A{} B{:b=>true} Terminal))
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(A{} C{:b=>true} D{} B{:b=>true} Terminal))
106
+ to eq(%w(A{} C{:b=>true} D{} B{:b=>true} Terminal{}))
107
107
  end
108
108
  end
109
109
  end
@@ -123,10 +123,9 @@ describe Coach::Handler do
123
123
 
124
124
  subject(:coach_events) do
125
125
  events = []
126
- subscription =
127
- ActiveSupport::Notifications.subscribe(/coach/) do |name, *args|
128
- events << name
129
- end
126
+ subscription = ActiveSupport::Notifications.subscribe(/coach/) do |name, *args|
127
+ events << name
128
+ end
130
129
 
131
130
  handler.call({})
132
131
  ActiveSupport::Notifications.unsubscribe(subscription)
@@ -4,8 +4,8 @@ require 'coach/router'
4
4
  require 'coach/handler'
5
5
 
6
6
  describe Coach::Router do
7
- subject(:router) { described_class.new(app) }
8
- let(:app) { double(:rails_app, routes: double(draw: nil)) }
7
+ subject(:router) { described_class.new(mapper) }
8
+ let(:mapper) { double(:mapper) }
9
9
 
10
10
  before do
11
11
  allow(Coach::Handler).to receive(:new) { |route| route }
@@ -26,12 +26,12 @@ describe Coach::Router do
26
26
  let(:actions) { [action] }
27
27
 
28
28
  it "correctly mounts url for :#{action}" do
29
- expect(router).to receive(:match).with(params[:url], anything)
29
+ expect(mapper).to receive(:match).with(params[:url], anything)
30
30
  draw
31
31
  end
32
32
 
33
33
  it "correctly mounts on method for :#{action}" do
34
- expect(router).to receive(:match).
34
+ expect(mapper).to receive(:match).
35
35
  with(anything, hash_including(via: params[:method]))
36
36
  draw
37
37
  end
@@ -54,7 +54,7 @@ describe Coach::Router do
54
54
  context "with no slash" do
55
55
  let(:custom_url) { ':id/refund' }
56
56
  it "mounts correct url" do
57
- expect(router).to receive(:match).with('/resource/:id/refund', anything)
57
+ expect(mapper).to receive(:match).with('/resource/:id/refund', anything)
58
58
  draw
59
59
  end
60
60
  end
@@ -62,7 +62,7 @@ describe Coach::Router do
62
62
  context "with multiple /'s" do
63
63
  let(:custom_url) { '//:id/refund' }
64
64
  it "mounts correct url" do
65
- expect(router).to receive(:match).with('/resource/:id/refund', anything)
65
+ expect(mapper).to receive(:match).with('/resource/:id/refund', anything)
66
66
  draw
67
67
  end
68
68
  end
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-24 00:00:00.000000000 Z
11
+ date: 2015-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -44,56 +44,56 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.2.0
47
+ version: '3.2'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.2.0
54
+ version: '3.2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec-its
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.2.0
61
+ version: '1.2'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.2.0
68
+ version: '1.2'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '0.10'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '0.10'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '0.32'
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.32'
97
97
  description: Controller framework
98
98
  email:
99
99
  - developers@gocardless.com
@@ -105,8 +105,8 @@ files:
105
105
  - ".rspec"
106
106
  - ".rubocop.yml"
107
107
  - ".travis.yml"
108
+ - CHANGELOG.md
108
109
  - Gemfile
109
- - Gemfile.lock
110
110
  - README.md
111
111
  - coach.gemspec
112
112
  - lib/coach.rb
@@ -1,104 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- coach (0.3.0)
5
- actionpack (~> 4.2)
6
- activesupport (~> 4.2)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- actionpack (4.2.3)
12
- actionview (= 4.2.3)
13
- activesupport (= 4.2.3)
14
- rack (~> 1.6)
15
- rack-test (~> 0.6.2)
16
- rails-dom-testing (~> 1.0, >= 1.0.5)
17
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
18
- actionview (4.2.3)
19
- activesupport (= 4.2.3)
20
- builder (~> 3.1)
21
- erubis (~> 2.7.0)
22
- rails-dom-testing (~> 1.0, >= 1.0.5)
23
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
- activesupport (4.2.3)
25
- i18n (~> 0.7)
26
- json (~> 1.7, >= 1.7.7)
27
- minitest (~> 5.1)
28
- thread_safe (~> 0.3, >= 0.3.4)
29
- tzinfo (~> 1.1)
30
- ast (2.0.0)
31
- astrolabe (1.3.0)
32
- parser (>= 2.2.0.pre.3, < 3.0)
33
- builder (3.2.2)
34
- coderay (1.1.0)
35
- diff-lcs (1.2.5)
36
- erubis (2.7.0)
37
- i18n (0.7.0)
38
- json (1.8.3)
39
- loofah (2.0.3)
40
- nokogiri (>= 1.5.9)
41
- method_source (0.8.2)
42
- mini_portile (0.6.2)
43
- minitest (5.8.0)
44
- nokogiri (1.6.6.2)
45
- mini_portile (~> 0.6.0)
46
- parser (2.2.2.5)
47
- ast (>= 1.1, < 3.0)
48
- powerpack (0.1.1)
49
- pry (0.10.1)
50
- coderay (~> 1.1.0)
51
- method_source (~> 0.8.1)
52
- slop (~> 3.4)
53
- rack (1.6.4)
54
- rack-test (0.6.3)
55
- rack (>= 1.0)
56
- rails-deprecated_sanitizer (1.0.3)
57
- activesupport (>= 4.2.0.alpha)
58
- rails-dom-testing (1.0.7)
59
- activesupport (>= 4.2.0.beta, < 5.0)
60
- nokogiri (~> 1.6.0)
61
- rails-deprecated_sanitizer (>= 1.0.1)
62
- rails-html-sanitizer (1.0.2)
63
- loofah (~> 2.0)
64
- rainbow (2.0.0)
65
- rspec (3.2.0)
66
- rspec-core (~> 3.2.0)
67
- rspec-expectations (~> 3.2.0)
68
- rspec-mocks (~> 3.2.0)
69
- rspec-core (3.2.3)
70
- rspec-support (~> 3.2.0)
71
- rspec-expectations (3.2.1)
72
- diff-lcs (>= 1.2.0, < 2.0)
73
- rspec-support (~> 3.2.0)
74
- rspec-its (1.2.0)
75
- rspec-core (>= 3.0.0)
76
- rspec-expectations (>= 3.0.0)
77
- rspec-mocks (3.2.1)
78
- diff-lcs (>= 1.2.0, < 2.0)
79
- rspec-support (~> 3.2.0)
80
- rspec-support (3.2.2)
81
- rubocop (0.32.0)
82
- astrolabe (~> 1.3)
83
- parser (>= 2.2.2.5, < 3.0)
84
- powerpack (~> 0.1)
85
- rainbow (>= 1.99.1, < 3.0)
86
- ruby-progressbar (~> 1.4)
87
- ruby-progressbar (1.7.5)
88
- slop (3.6.0)
89
- thread_safe (0.3.5)
90
- tzinfo (1.2.2)
91
- thread_safe (~> 0.1)
92
-
93
- PLATFORMS
94
- ruby
95
-
96
- DEPENDENCIES
97
- coach!
98
- pry
99
- rspec (~> 3.2.0)
100
- rspec-its (~> 1.2.0)
101
- rubocop
102
-
103
- BUNDLED WITH
104
- 1.10.6