rack-useful_procline 0.0.1 → 0.0.3
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/lib/rack/ext/request.rb +7 -0
- data/lib/rack/useful_procline.rb +24 -19
- data/spec/rack/useful_procline_spec.rb +15 -7
- data/spec/spec_helper.rb +2 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9436d55de443b7dd527b513a9406182e6fc15c98
|
4
|
+
data.tar.gz: 0d19a60460afcded878b46ed93782fb232dc311d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66351b202efc0420e225f57e31240aa974a77c38c93326bc03c2f30fffcd81ffc3497ab5913c5695a7d591841538d8bfc26be75b3d22ca2098c3f85dae901557
|
7
|
+
data.tar.gz: cfcbf2a21340326721267c79a9afc5cbeca35f5250e8bfa394f7775e5b31b8b743b265685d0acb103934a47e1552e44a99c811f6f1db138b9924a78908e8591d
|
data/lib/rack/useful_procline.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'rack'
|
2
|
+
require 'rack/request'
|
3
|
+
require 'rack/ext/request'
|
2
4
|
|
3
5
|
module Rack
|
4
6
|
class UsefulProcline
|
5
|
-
VERSION = "0.0.
|
7
|
+
VERSION = "0.0.3"
|
6
8
|
|
7
9
|
class << self
|
8
10
|
attr_accessor :config
|
@@ -36,16 +38,18 @@ module Rack
|
|
36
38
|
|
37
39
|
# Public
|
38
40
|
def call(env)
|
39
|
-
|
41
|
+
@request = Request.new(env)
|
42
|
+
|
43
|
+
prefix = $0.split(']')[0] + "]"
|
40
44
|
procline = prefix.dup
|
41
|
-
procline = procline_before_request(procline
|
45
|
+
procline = procline_before_request(procline)
|
42
46
|
|
43
47
|
set_procline(procline[0..200])
|
44
48
|
|
45
49
|
status, headers, body = @app.call(env)
|
46
50
|
|
47
51
|
procline = prefix.dup
|
48
|
-
procline = procline_after_request(procline,
|
52
|
+
procline = procline_after_request(procline, status)
|
49
53
|
set_procline(procline)
|
50
54
|
|
51
55
|
[status, headers, body]
|
@@ -60,34 +64,35 @@ module Rack
|
|
60
64
|
string.chars.select(&:valid_encoding?).join.force_encoding('utf-8')
|
61
65
|
end
|
62
66
|
|
63
|
-
def procline_before_request(procline
|
64
|
-
if @config.opts[:show_request_method]
|
65
|
-
procline.concat(" : #{
|
67
|
+
def procline_before_request(procline)
|
68
|
+
if @config.opts[:show_request_method] && @request
|
69
|
+
procline.concat(" : #{@request.request_method}")
|
66
70
|
end
|
67
71
|
|
68
|
-
if @config.opts[:show_request_path]
|
69
|
-
procline.concat(" : #{
|
72
|
+
if @config.opts[:show_request_path] && @request
|
73
|
+
procline.concat(" : #{@request.path_info}")
|
70
74
|
end
|
71
75
|
|
72
76
|
if @config.opts[:show_request_uuid]
|
73
|
-
|
74
|
-
procline.concat(" : #{
|
77
|
+
uuid = request_uuid || "No request uuid found"
|
78
|
+
procline.concat(" : #{uuid}")
|
75
79
|
end
|
76
80
|
|
77
81
|
procline
|
78
82
|
end
|
79
83
|
|
80
|
-
def
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
+
def request_uuid
|
85
|
+
if @request
|
86
|
+
uuid = @request.uuid(@config.opts[:request_uuid_key])
|
87
|
+
uuid[0..7] if uuid
|
88
|
+
end
|
84
89
|
end
|
85
90
|
|
86
|
-
def procline_after_request(procline,
|
87
|
-
procline.concat(": last status: #{status}.")
|
91
|
+
def procline_after_request(procline, status)
|
92
|
+
procline.concat(" : last status: #{status}.")
|
88
93
|
if @config.opts[:show_request_uuid]
|
89
|
-
|
90
|
-
procline += " last request_uuid: #{
|
94
|
+
uuid = request_uuid || "No request uuid found"
|
95
|
+
procline += " last request_uuid: #{uuid}."
|
91
96
|
end
|
92
97
|
procline += " Waiting for req."
|
93
98
|
end
|
@@ -65,16 +65,19 @@ describe Rack::UsefulProcline do
|
|
65
65
|
# or here
|
66
66
|
end
|
67
67
|
|
68
|
-
describe '#
|
68
|
+
describe '#request_uuid' do
|
69
69
|
it 'should retrieve the truncated request uuid' do
|
70
70
|
env = {'action_dispatch.request_id' => 'my_request_uuid'}
|
71
|
-
|
71
|
+
subject.instance_variable_set(:@request, Rack::Request.new(env))
|
72
|
+
expect(subject.request_uuid.length).to eql(8)
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
75
76
|
describe '#procline_before_request' do
|
76
77
|
subject do
|
77
|
-
Rack::UsefulProcline.new(rack_app)
|
78
|
+
s = Rack::UsefulProcline.new(rack_app)
|
79
|
+
s.instance_variable_set(:@request, Rack::Request.new(rack_env))
|
80
|
+
s.procline_before_request("")
|
78
81
|
end
|
79
82
|
|
80
83
|
describe "with default config (everything true)" do
|
@@ -90,7 +93,7 @@ describe Rack::UsefulProcline do
|
|
90
93
|
config.opts[:show_request_path] = false
|
91
94
|
config.opts[:show_request_uuid] = false
|
92
95
|
end
|
93
|
-
Rack::UsefulProcline.new(rack_app).procline_before_request(""
|
96
|
+
Rack::UsefulProcline.new(rack_app).procline_before_request("")
|
94
97
|
end
|
95
98
|
|
96
99
|
it do
|
@@ -104,7 +107,10 @@ describe Rack::UsefulProcline do
|
|
104
107
|
subject do
|
105
108
|
key = "my_request_uuid_key"
|
106
109
|
Rack::UsefulProcline.configure { |config| config.opts[:request_uuid_key] = key }
|
107
|
-
Rack::UsefulProcline.new(rack_app)
|
110
|
+
s = Rack::UsefulProcline.new(rack_app)
|
111
|
+
env = rack_env(request_uuid_key: key)
|
112
|
+
s.instance_variable_set(:@request, Rack::Request.new(env))
|
113
|
+
s.procline_before_request("")
|
108
114
|
end
|
109
115
|
|
110
116
|
it { expect(subject).to include("12345678") }
|
@@ -116,7 +122,9 @@ describe Rack::UsefulProcline do
|
|
116
122
|
def create_subject(opts = {})
|
117
123
|
opts[:rack_app] ||= rack_app
|
118
124
|
opts[:rack_env] ||= rack_env
|
119
|
-
Rack::UsefulProcline.new(opts[:rack_app])
|
125
|
+
s = Rack::UsefulProcline.new(opts[:rack_app])
|
126
|
+
s.instance_variable_set(:@request, Rack::Request.new(opts[:rack_env]))
|
127
|
+
s.procline_after_request("", "200")
|
120
128
|
end
|
121
129
|
end
|
122
130
|
|
@@ -151,7 +159,7 @@ describe Rack::UsefulProcline do
|
|
151
159
|
end
|
152
160
|
end
|
153
161
|
|
154
|
-
describe "with custom
|
162
|
+
describe "with custom request_uuid_key" do
|
155
163
|
subject do
|
156
164
|
key = 'my_request_uuid_key'
|
157
165
|
Rack::UsefulProcline.configure { |config| config.opts[:request_uuid_key] = key }
|
data/spec/spec_helper.rb
CHANGED
@@ -17,8 +17,8 @@ RSpec.configure do |config|
|
|
17
17
|
opts[:request_uuid_key] ||= 'action_dispatch.request_id'
|
18
18
|
{
|
19
19
|
opts[:request_uuid_key] => '12345678 longish string',
|
20
|
-
'REQUEST_METHOD'
|
21
|
-
'
|
20
|
+
'REQUEST_METHOD' => 'GET',
|
21
|
+
'PATH_INFO' => '/path/to/things'
|
22
22
|
}
|
23
23
|
end
|
24
24
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-useful_procline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Wallis
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- LICENSE.txt
|
82
82
|
- README.md
|
83
83
|
- Rakefile
|
84
|
+
- lib/rack/ext/request.rb
|
84
85
|
- lib/rack/useful_procline.rb
|
85
86
|
- rack-useful_procline.gemspec
|
86
87
|
- spec/rack/useful_procline_spec.rb
|