grape_on_rails_routes 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/grape_on_rails_routes/version.rb +1 -1
- data/lib/tasks/grape.rake +37 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85d9ff64caf8cbeeb5eead4e7cf3b9ec43c115f7
|
4
|
+
data.tar.gz: e22fa7a51ac696748c7020908b1bb6b93e86de0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43073dcd688696c6e2fa4c52148896afce14e3949ccf3f299abf32330b06910a7087d53bb1809ceaa4d30ff570acf69b563c2a1de75e05a96a66130c65ff1e08
|
7
|
+
data.tar.gz: 7caabaea4527a70823f6230e9fd2204b01a299339fc110e81027546f9678b14176846dc84d57ba0a1b05124137a2d31ccfae63d7403f0dab91f3bbf2009c0805
|
data/lib/tasks/grape.rake
CHANGED
@@ -1,22 +1,48 @@
|
|
1
1
|
namespace :grape do
|
2
2
|
desc "show API routes"
|
3
3
|
task routes: :environment do
|
4
|
+
mapping = method_mapping
|
5
|
+
|
4
6
|
grape_klasses = ObjectSpace.each_object(Class).select { |klass| klass < Grape::API }
|
5
|
-
routes = grape_klasses.
|
6
|
-
|
7
|
+
routes = grape_klasses.
|
8
|
+
flat_map(&:routes).
|
9
|
+
uniq { |r| r.send(mapping[:path]) + r.send(mapping[:method]).to_s }
|
10
|
+
|
11
|
+
method_width, path_width, version_width, desc_width = widths(routes, mapping)
|
12
|
+
|
7
13
|
routes.each do |api|
|
8
|
-
method = api.
|
9
|
-
path = api.
|
10
|
-
version = api.
|
11
|
-
desc = api.
|
14
|
+
method = api.send(mapping[:method]).to_s.rjust(method_width)
|
15
|
+
path = api.send(mapping[:path]).to_s.ljust(path_width)
|
16
|
+
version = api.send(mapping[:version]).to_s.ljust(version_width)
|
17
|
+
desc = api.send(mapping[:description]).to_s.ljust(desc_width)
|
12
18
|
puts " #{method} | #{path} | #{version} | #{desc}"
|
13
19
|
end
|
14
20
|
end
|
15
21
|
|
16
|
-
def widths(routes)
|
17
|
-
[
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
def widths(routes, mapping)
|
23
|
+
[
|
24
|
+
routes.map { |r| r.send(mapping[:method]).try(:length) }.compact.max || 0,
|
25
|
+
routes.map { |r| r.send(mapping[:path]).try(:length) }.compact.max || 0,
|
26
|
+
routes.map { |r| r.send(mapping[:version]).try(:length) }.compact.max || 0,
|
27
|
+
routes.map { |r| r.send(mapping[:description]).try(:length) }.compact.max || 0
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
31
|
+
def method_mapping
|
32
|
+
if Gem.loaded_specs['grape'].version.to_s >= "0.15.1"
|
33
|
+
{
|
34
|
+
method: 'request_method',
|
35
|
+
path: 'path',
|
36
|
+
version: 'version',
|
37
|
+
description: 'description'
|
38
|
+
}
|
39
|
+
else
|
40
|
+
{
|
41
|
+
method: 'route_method',
|
42
|
+
path: 'route_path',
|
43
|
+
version: 'route_version',
|
44
|
+
description: 'route_description'
|
45
|
+
}
|
46
|
+
end
|
21
47
|
end
|
22
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape_on_rails_routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- syedmusamah
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|