rack-app 7.3.0 → 7.3.1

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: 470832cf00bcd28e1aba12840dea366381926732
4
- data.tar.gz: 88c19a8414ba4a2ea6d1c45a420f0143869706b8
3
+ metadata.gz: 79271c60c490af09f3db3df4e6907210529bf0d0
4
+ data.tar.gz: b14fc9c9169e980aee20a59c1384dadc27166df6
5
5
  SHA512:
6
- metadata.gz: 9232cc283980236bce4ea88899ae68b442f8c75be15cc4d2318c2828646c1c19efee5c83a66ebb8a7d7424ea2f879cf5517501c6f27ac7b49c9c9cdd53983727
7
- data.tar.gz: 126ab463a8bb939e0d5ad90514baaeec2bc3086f1d9164527bacece533f2b87c9665d4a46533a3b74c1818c39483d4808dc6aa65ee68daedf3f6c7a0b5a55999
6
+ metadata.gz: e02bcb5f6aba359290b0231bd22a0b4cdab6def0b885f7ee05383024027d5044308453d9c1a8df35b654f08b96283546330fd7032603ee8a35ed339f87a83f7c
7
+ data.tar.gz: 135399af68864242bb24bd985a07e8b83b8767c8e484715d99a2f3c21acfb0d0448ade94f5a5072f5ef6612a2fc4ee6ac10d88bddce108f45e0f11c827e47173
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.3.0
1
+ 7.3.1
@@ -17,26 +17,12 @@ class Rack::App::CLI::DefaultCommands::ShowRoutes < Rack::App::CLI::Command
17
17
  @middlewares = true
18
18
  end
19
19
 
20
- FIELD_FETCHERS = {
21
- :request_method => proc { |endpoint| endpoint.request_method },
22
- :request_path => proc { |endpoint| endpoint.request_path },
23
- :description => proc { |endpoint| endpoint.description },
24
- :source_location => proc do |endpoint|
25
- callable = endpoint.properties[:callable]
26
- callable = callable.method(:call) unless callable.is_a?(::Proc)
27
- callable.source_location.join(':')
28
- end
29
- }.freeze
30
-
31
- SORT_FIELDS = [:request_method, :request_path].freeze
32
-
33
20
  action do
34
21
  STDOUT.puts(format(sort(Rack::App::CLI.rack_app.router.endpoints)))
35
22
  end
36
23
 
37
24
  private
38
25
 
39
-
40
26
  def get_fields
41
27
  if @verbose
42
28
  return FIELD_FETCHERS.keys
@@ -50,14 +36,32 @@ class Rack::App::CLI::DefaultCommands::ShowRoutes < Rack::App::CLI::Command
50
36
 
51
37
  def width_by(endpoints, fields)
52
38
  fields.reduce({}) do |widths, property|
53
- widths[property] = endpoints.map { |endpoint| FIELD_FETCHERS[property].call(endpoint).to_s.length }.max
39
+ widths[property] = endpoints.map { |endpoint| fetch_field(endpoint, property).to_s.length }.max
54
40
  widths
55
41
  end
56
42
  end
57
43
 
44
+ SORT_FIELDS = [:request_method, :request_path].freeze
58
45
 
59
46
  def sort(endpoints)
60
- endpoints.sort_by { |endpoint| SORT_FIELDS.map { |sf| FIELD_FETCHERS[sf].call(endpoint) } }
47
+ endpoints.sort_by { |endpoint| SORT_FIELDS.map { |sf| fetch_field(endpoint, sf) } }
48
+ end
49
+
50
+ FIELD_FETCHERS = {
51
+ :request_method => proc { |endpoint| endpoint.request_method },
52
+ :request_path => proc { |endpoint| endpoint.request_path },
53
+ :description => proc { |endpoint| endpoint.description },
54
+ :source_location => proc do |endpoint|
55
+ callable = endpoint.properties[:callable]
56
+ callable = callable.method(:call) unless callable.is_a?(::Proc)
57
+ path = callable.source_location.join(':')
58
+ relative_path_rgx = Regexp.new(sprintf('^%s', Regexp.escape(Rack::App::Utils.pwd('/'))))
59
+ path.sub(relative_path_rgx, '')
60
+ end
61
+ }.freeze
62
+
63
+ def fetch_field(endpoint, field)
64
+ instance_exec(endpoint, &FIELD_FETCHERS[field])
61
65
  end
62
66
 
63
67
  def format(endpoints)
@@ -68,7 +72,7 @@ class Rack::App::CLI::DefaultCommands::ShowRoutes < Rack::App::CLI::Command
68
72
  outputs = []
69
73
 
70
74
  outputs << fields.map do |field|
71
- FIELD_FETCHERS[field].call(endpoint).to_s.ljust(widths[field])
75
+ fetch_field(endpoint, field).to_s.ljust(widths[field])
72
76
  end.join(' ')
73
77
 
74
78
  if @middlewares
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.3.0
4
+ version: 7.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-05 00:00:00.000000000 Z
11
+ date: 2017-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler