rack-useful_procline 0.0.1 → 0.0.3

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: 5789281f880a804629b7efb859f4873b88a2149a
4
- data.tar.gz: 0991ec2800518435f9413a7e2bb1b62342432050
3
+ metadata.gz: 9436d55de443b7dd527b513a9406182e6fc15c98
4
+ data.tar.gz: 0d19a60460afcded878b46ed93782fb232dc311d
5
5
  SHA512:
6
- metadata.gz: c08f84c878b7016cfaa61f16cbb20d02491e33d87a133b34ad3092bb433bd72bb8f117248575bb1c52066232e9766d873cb995c9dbf0865825f2ec5adf350731
7
- data.tar.gz: 6ae5560e7f5eaf1ad12ddc72d2c48d70c94d0a30e787de911c96318863fc3246e5e49f79dda1a605a22a62ec73b00e1e15ae240ecb3e4cf8945f8e1b731fe350
6
+ metadata.gz: 66351b202efc0420e225f57e31240aa974a77c38c93326bc03c2f30fffcd81ffc3497ab5913c5695a7d591841538d8bfc26be75b3d22ca2098c3f85dae901557
7
+ data.tar.gz: cfcbf2a21340326721267c79a9afc5cbeca35f5250e8bfa394f7775e5b31b8b743b265685d0acb103934a47e1552e44a99c811f6f1db138b9924a78908e8591d
@@ -0,0 +1,7 @@
1
+ module Rack
2
+ class Request
3
+ def uuid(env_key = nil)
4
+ @env[env_key] if env_key
5
+ end
6
+ end
7
+ end
@@ -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.1"
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
- prefix = $0.split(']')[0] + "] "
41
+ @request = Request.new(env)
42
+
43
+ prefix = $0.split(']')[0] + "]"
40
44
  procline = prefix.dup
41
- procline = procline_before_request(procline, env)
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, env, status)
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, env)
64
- if @config.opts[:show_request_method]
65
- procline.concat(" : #{env['REQUEST_METHOD']}")
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(" : #{env['REQUEST_PATH']}")
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
- request_uuid = request_uuid_from(env) || "No request uuid found"
74
- procline.concat(" : #{request_uuid_from(env)}")
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 request_uuid_from(env)
81
- request_uuid = env[@config.opts[:request_uuid_key]]
82
- request_uuid = request_uuid[0..7] if request_uuid
83
- request_uuid
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, env, status)
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
- request_uuid = request_uuid_from(env) || "No request uuid found"
90
- procline += " last request_uuid: #{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 '#request_uuid_from' do
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
- expect(subject.request_uuid_from(env).length).to eql(8)
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).procline_before_request("", rack_env)
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("", rack_env)
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).procline_before_request("", rack_env(request_uuid_key: key))
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]).procline_after_request("", opts[:rack_env], "200")
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 request uuid key" do
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 }
@@ -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' => 'GET',
21
- 'REQUEST_PATH' => '/path/to/things'
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.1
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