grape_on_rails_routes 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ea5b4fcb03255b25d2899c7372a14889cc1b81c
4
- data.tar.gz: e0f564f2a508ddf774a1b3c33c6f89b9c005516a
3
+ metadata.gz: 85d9ff64caf8cbeeb5eead4e7cf3b9ec43c115f7
4
+ data.tar.gz: e22fa7a51ac696748c7020908b1bb6b93e86de0b
5
5
  SHA512:
6
- metadata.gz: d1c526059a055a3a38176d6801aa81243f10d6d52da47a8437f82ff1b5d8c5d0e6e49d2a043102f6d7c6eddf66159dfc22b20f821df7dc51cc076c52e8427f69
7
- data.tar.gz: a9c4f3ff29c0cff0e190b3237999c912bea4aff3931a560bbf573b6555b6b6a6ca1cde1fe5a3ccffc3272190563a2ff63ae505065c4ed491feafc4914deb788d
6
+ metadata.gz: 43073dcd688696c6e2fa4c52148896afce14e3949ccf3f299abf32330b06910a7087d53bb1809ceaa4d30ff570acf69b563c2a1de75e05a96a66130c65ff1e08
7
+ data.tar.gz: 7caabaea4527a70823f6230e9fd2204b01a299339fc110e81027546f9678b14176846dc84d57ba0a1b05124137a2d31ccfae63d7403f0dab91f3bbf2009c0805
@@ -1,3 +1,3 @@
1
1
  module GrapeOnRailsRoutes
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
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.flat_map(&:routes).uniq { |r| r.route_path + r.route_method.to_s }
6
- method_width, path_width, version_width, desc_width = widths(routes)
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.route_method.to_s.rjust(method_width)
9
- path = api.route_path.to_s.ljust(path_width)
10
- version = api.route_version.to_s.ljust(version_width)
11
- desc = api.route_description.to_s.ljust(desc_width)
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
- [routes.map { |r| r.route_method.try(:length) }.compact.max || 0,
18
- routes.map { |r| r.route_path.try(:length) }.compact.max || 0,
19
- routes.map { |r| r.route_version.try(:length) }.compact.max || 0,
20
- routes.map { |r| r.route_description.try(:length) }.compact.max || 0]
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.2.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-03-30 00:00:00.000000000 Z
11
+ date: 2016-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails