rack-app 7.2.2 → 7.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 +4 -4
- data/.travis.yml +0 -5
- data/VERSION +1 -1
- data/lib/rack/app/cli/command.rb +3 -6
- data/lib/rack/app/cli/command/configurator.rb +1 -3
- data/lib/rack/app/cli/default_commands/list_commands.rb +2 -2
- data/lib/rack/app/cli/default_commands/show_routes.rb +98 -5
- data/lib/rack/app/cli/runner.rb +2 -4
- data/lib/rack/app/endpoint.rb +1 -1
- data/lib/rack/app/endpoint/builder.rb +8 -4
- data/lib/rack/app/instance_methods/params.rb +0 -6
- 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: 470832cf00bcd28e1aba12840dea366381926732
|
4
|
+
data.tar.gz: 88c19a8414ba4a2ea6d1c45a420f0143869706b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9232cc283980236bce4ea88899ae68b442f8c75be15cc4d2318c2828646c1c19efee5c83a66ebb8a7d7424ea2f879cf5517501c6f27ac7b49c9c9cdd53983727
|
7
|
+
data.tar.gz: 126ab463a8bb939e0d5ad90514baaeec2bc3086f1d9164527bacece533f2b87c9665d4a46533a3b74c1818c39483d4808dc6aa65ee68daedf3f6c7a0b5a55999
|
data/.travis.yml
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
7.
|
1
|
+
7.3.0
|
data/lib/rack/app/cli/command.rb
CHANGED
@@ -5,7 +5,7 @@ class Rack::App::CLI::Command
|
|
5
5
|
|
6
6
|
class << self
|
7
7
|
|
8
|
-
def
|
8
|
+
def __option_definitions__
|
9
9
|
@options_parser_options ||= []
|
10
10
|
end
|
11
11
|
|
@@ -17,7 +17,7 @@ class Rack::App::CLI::Command
|
|
17
17
|
alias desc description
|
18
18
|
|
19
19
|
def option(*args, &block)
|
20
|
-
|
20
|
+
__option_definitions__ << {:args => args, :block => block}
|
21
21
|
end
|
22
22
|
|
23
23
|
alias on option
|
@@ -28,11 +28,8 @@ class Rack::App::CLI::Command
|
|
28
28
|
|
29
29
|
end
|
30
30
|
|
31
|
-
def options
|
32
|
-
@options ||= {}
|
33
|
-
end
|
34
|
-
|
35
31
|
def action(*argv)
|
32
|
+
raise NotImplementedError
|
36
33
|
end
|
37
34
|
|
38
35
|
def start(argv)
|
@@ -3,10 +3,8 @@ module Rack::App::CLI::Command::Configurator
|
|
3
3
|
extend self
|
4
4
|
|
5
5
|
def configure(command, name, options_parser)
|
6
|
-
|
7
|
-
attach_definitions(command, options_parser, command.class.option_definitions)
|
6
|
+
attach_definitions(command, options_parser, command.class.__option_definitions__)
|
8
7
|
update_banner(command, name, options_parser.banner)
|
9
|
-
|
10
8
|
end
|
11
9
|
|
12
10
|
protected
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Rack::App::CLI::DefaultCommands::ListCommands
|
2
2
|
extend self
|
3
3
|
|
4
|
-
PRESERVED_KEYWORDS = %w[
|
4
|
+
PRESERVED_KEYWORDS = %w[help routes irb].freeze
|
5
5
|
|
6
6
|
DEFAULT_COMMANDS = {
|
7
|
-
'commands' => 'list all available command',
|
8
7
|
'routes' => Rack::App::CLI::DefaultCommands::ShowRoutes.description,
|
8
|
+
'help' => 'list all available command or describe a specific command',
|
9
9
|
'irb' => Rack::App::CLI::DefaultCommands::IRB.description
|
10
10
|
}.freeze
|
11
11
|
|
@@ -1,13 +1,106 @@
|
|
1
1
|
class Rack::App::CLI::DefaultCommands::ShowRoutes < Rack::App::CLI::Command
|
2
|
-
|
3
2
|
description 'list the routes for the application'
|
4
3
|
|
4
|
+
on '-v', '--verbose', 'print out everything' do
|
5
|
+
@verbose = true
|
6
|
+
end
|
7
|
+
|
8
|
+
on '-d', '--desc', '--description', 'include endpoint descriptions too' do
|
9
|
+
@description = true
|
10
|
+
end
|
11
|
+
|
12
|
+
on '-l', '--location', '--source-location', 'show endpoint definition locations' do
|
13
|
+
@source_location = true
|
14
|
+
end
|
15
|
+
|
16
|
+
on '-m', '--middlewares', 'show endpoint definition middleware stack' do
|
17
|
+
@middlewares = true
|
18
|
+
end
|
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
|
+
|
5
33
|
action do
|
6
|
-
|
34
|
+
STDOUT.puts(format(sort(Rack::App::CLI.rack_app.router.endpoints)))
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
|
40
|
+
def get_fields
|
41
|
+
if @verbose
|
42
|
+
return FIELD_FETCHERS.keys
|
43
|
+
end
|
44
|
+
|
45
|
+
fields = [:request_method, :request_path]
|
46
|
+
fields << :description if @description
|
47
|
+
fields << :source_location if @source_location
|
48
|
+
fields
|
7
49
|
end
|
8
50
|
|
9
|
-
def
|
10
|
-
|
51
|
+
def width_by(endpoints, fields)
|
52
|
+
fields.reduce({}) do |widths, property|
|
53
|
+
widths[property] = endpoints.map { |endpoint| FIELD_FETCHERS[property].call(endpoint).to_s.length }.max
|
54
|
+
widths
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def sort(endpoints)
|
60
|
+
endpoints.sort_by { |endpoint| SORT_FIELDS.map { |sf| FIELD_FETCHERS[sf].call(endpoint) } }
|
61
|
+
end
|
62
|
+
|
63
|
+
def format(endpoints)
|
64
|
+
fields = get_fields
|
65
|
+
widths = width_by(endpoints, fields)
|
66
|
+
|
67
|
+
endpoints.map do |endpoint|
|
68
|
+
outputs = []
|
69
|
+
|
70
|
+
outputs << fields.map do |field|
|
71
|
+
FIELD_FETCHERS[field].call(endpoint).to_s.ljust(widths[field])
|
72
|
+
end.join(' ')
|
73
|
+
|
74
|
+
if @middlewares
|
75
|
+
outputs << pretty_print_middlewares(endpoint)
|
76
|
+
end
|
77
|
+
|
78
|
+
outputs.join("\n")
|
79
|
+
end.join("\n")
|
80
|
+
end
|
81
|
+
|
82
|
+
class FakeBuilder
|
83
|
+
attr_reader :middlewares
|
84
|
+
|
85
|
+
def initialize
|
86
|
+
@middlewares = []
|
87
|
+
end
|
88
|
+
|
89
|
+
def use(middleware, *args)
|
90
|
+
@middlewares << middleware
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def pretty_print_middlewares(endpoint)
|
95
|
+
builder = FakeBuilder.new
|
96
|
+
|
97
|
+
endpoint.config.middlewares.each do |builder_block|
|
98
|
+
builder.instance_exec(builder, &builder_block)
|
99
|
+
end
|
100
|
+
|
101
|
+
builder.middlewares.map do |middleware|
|
102
|
+
["\t", '* ', middleware].join
|
103
|
+
end.join("\n")
|
11
104
|
end
|
12
105
|
|
13
|
-
end
|
106
|
+
end
|
data/lib/rack/app/cli/runner.rb
CHANGED
@@ -27,14 +27,12 @@ class Rack::App::CLI::Runner
|
|
27
27
|
def start_command_for(command_name, argv)
|
28
28
|
case command_name.to_s
|
29
29
|
|
30
|
-
when 'commands'
|
31
|
-
show_commands
|
32
|
-
|
33
30
|
when 'help'
|
34
31
|
show_help_message(argv)
|
35
32
|
|
36
33
|
when 'routes'
|
37
|
-
Rack::App::CLI::DefaultCommands::ShowRoutes.new
|
34
|
+
command = Rack::App::CLI::DefaultCommands::ShowRoutes.new
|
35
|
+
run_command(argv, command, "routes")
|
38
36
|
|
39
37
|
when 'irb'
|
40
38
|
Rack::App::CLI::DefaultCommands::IRB.new.start(argv)
|
data/lib/rack/app/endpoint.rb
CHANGED
@@ -5,15 +5,19 @@ class Rack::App::Endpoint::Builder
|
|
5
5
|
@config = config
|
6
6
|
end
|
7
7
|
|
8
|
+
def to_app
|
9
|
+
build.to_app
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
8
14
|
def build
|
9
15
|
builder = Rack::Builder.new
|
10
16
|
apply_middleware_build_blocks(builder)
|
11
17
|
builder.run(app)
|
12
|
-
builder
|
18
|
+
builder
|
13
19
|
end
|
14
20
|
|
15
|
-
protected
|
16
|
-
|
17
21
|
def app
|
18
22
|
case @config.type
|
19
23
|
when :endpoint
|
@@ -25,7 +29,7 @@ class Rack::App::Endpoint::Builder
|
|
25
29
|
|
26
30
|
def apply_middleware_build_blocks(builder)
|
27
31
|
@config.middlewares.each do |builder_block|
|
28
|
-
|
32
|
+
builder.instance_exec(builder, &builder_block)
|
29
33
|
end
|
30
34
|
builder.use(Rack::App::Middlewares::Configuration, @config)
|
31
35
|
|
@@ -6,12 +6,6 @@ module Rack::App::InstanceMethods::Params
|
|
6
6
|
request.env[E::PARAMS].to_hash
|
7
7
|
end
|
8
8
|
|
9
|
-
def validated_params
|
10
|
-
request.env[E::PARAMS].validated_params
|
11
|
-
end
|
12
|
-
|
13
|
-
Rack::App::Utils.deprecate(self, :validated_params, :params, 2017, 07)
|
14
|
-
|
15
9
|
def path_segments_params
|
16
10
|
request.env[E::PARAMS].path_segments_params
|
17
11
|
end
|
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.
|
4
|
+
version: 7.3.0
|
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-
|
11
|
+
date: 2017-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|