napa-ext 0.0.2 → 0.0.3

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: 2971fd9c274c0b30b900d2aebb221bc23c253a87
4
- data.tar.gz: eeea6facc5acb6f92e9cc12594e60c5627c73615
3
+ metadata.gz: 51fa537664dece05e4b531864907c154f317e353
4
+ data.tar.gz: 7294b9ba02815b63f975f0fb72712a6a9bd5bf31
5
5
  SHA512:
6
- metadata.gz: 9c60d7adfbf07a840b1970619ef8f30d8e9cded4a91d3810fe23e37c6a6535c5b078618b316bb52582f981bc3da674aa9ffadc7df4ea5f213880ddf49bba6f04
7
- data.tar.gz: 0c14bcb4c00cbcb7f013fe925feab6ce2797b7bcb5dc0d8a44abd445f5498cba7d7ada4d616611f1489b0c6a1c172d69d71c638923e614cc0ee4e15606fda98d
6
+ metadata.gz: d078613aac1dfe53acb444b6a98210fec08b4d05e8abb2990edda49573272a53399fde5891be47202caab7f2771f0fa857c26cdfe58b05e80654000e7d45d314
7
+ data.tar.gz: 7b20e2416bcc225ba9768863fea92008657de64e0c2ce9a967c467fc524ce2c0effebeea963fdaf031df0a55b58d524d94d88d8ac64148ce8b6fba1c496dcf15
@@ -0,0 +1,40 @@
1
+ module Napa
2
+ module Ext
3
+ class SwaggerDoc
4
+ def initialize app, api_doc_path: '/api_doc'
5
+ @app = app
6
+ @api_doc_path = api_doc_path
7
+ end
8
+
9
+ def call env
10
+ if enabled? && api_doc?(env)
11
+ [
12
+ '301',
13
+ { 'Location' => target_swagger_url(env), 'Content-Type' => 'text/html' },
14
+ []
15
+ ]
16
+ else
17
+ app.call env
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :app, :api_doc_path
24
+
25
+ def api_doc? env
26
+ env['PATH_INFO'] == api_doc_path
27
+ end
28
+
29
+ def enabled?
30
+ ENV.key? 'SWAGGER_UI_URL'
31
+ end
32
+
33
+ def target_swagger_url env
34
+ swagger_api_uri = env['REQUEST_URI'].gsub api_doc_path, '/swagger_doc'
35
+
36
+ "#{ENV['SWAGGER_UI_URL']}?swagger_doc=#{swagger_api_uri}"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  module Napa
2
2
  module Ext
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: napa-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - soloman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-30 00:00:00.000000000 Z
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -97,6 +97,7 @@ files:
97
97
  - Rakefile
98
98
  - lib/napa/ext.rb
99
99
  - lib/napa/ext/poison.rb
100
+ - lib/napa/ext/swagger_doc.rb
100
101
  - lib/napa/ext/version.rb
101
102
  - napa-ext.gemspec
102
103
  homepage: ''
@@ -119,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  version: '0'
120
121
  requirements: []
121
122
  rubyforge_project:
122
- rubygems_version: 2.4.2
123
+ rubygems_version: 2.2.2
123
124
  signing_key:
124
125
  specification_version: 4
125
126
  summary: Some additional Napa middlewares