trace_header 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trace_header/description.rb +37 -39
- data/lib/trace_header/result.rb +37 -39
- data/lib/trace_header/version.rb +1 -1
- data/lib/trace_header.rb +34 -36
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d138fc6179b642bd194e99bbf810d27700a7b74502bcfcdb35699e6328707bf
|
4
|
+
data.tar.gz: cc213beffc427b87913b9c0ccbe45bfd9c6e1d61b77e4e9e65d2770944cb716d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8170f7df29cc4d5c716110f8f2532119718446fba2a1baf10668a96c457f1666190db56b4e146ae026bf844ab8154e44c971f70c8321e86fb697f2a4dc27ad62
|
7
|
+
data.tar.gz: 4f2da6b992bebef5f6bff7551089d669302a77a665db50a535988326badbf9de679c2cd49f0cb03ea3628fec7e9e30e9c2fda2d2de48c3e8802f1393a70cfcac
|
@@ -1,50 +1,48 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
MAXIMUM_LENGTH = 50
|
1
|
+
class TraceHeader
|
2
|
+
module Description
|
3
|
+
MAXIMUM_LENGTH = 50
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
def display(result)
|
6
|
+
puts description(result)
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
private
|
10
|
+
def description(result)
|
11
|
+
<<~"TEXT"
|
12
|
+
----------------------------------------------------
|
14
13
|
|
15
|
-
|
14
|
+
TraceHeader printing...
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
[Target Middleware]
|
17
|
+
#{result.target_app.class}\n
|
18
|
+
[New Headers]
|
19
|
+
#{detailed_description(result.new_headers)}
|
20
|
+
[Changed Headers]
|
21
|
+
#{detailed_description(result.changed_headers)}
|
22
|
+
----------------------------------------------------
|
23
|
+
TEXT
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
26
|
+
def detailed_description(headers)
|
27
|
+
if headers.empty?
|
28
|
+
" - Nothing added. -\n"
|
29
|
+
else
|
30
|
+
<<~"TEXT"
|
31
|
+
#{lined_description(headers).join("\n")}
|
32
|
+
TEXT
|
35
33
|
end
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
36
|
+
def lined_description(headers)
|
37
|
+
headers.flat_map do |header|
|
38
|
+
header.map { |field, value| " - #{field}: #{form(value)}" }
|
41
39
|
end
|
40
|
+
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
42
|
+
def form(text)
|
43
|
+
text.split(';').map do |str|
|
44
|
+
str.size > MAXIMUM_LENGTH ? str[0..MAXIMUM_LENGTH] + '...' : str
|
45
|
+
end.join(';')
|
46
|
+
end
|
49
47
|
end
|
50
48
|
end
|
data/lib/trace_header/result.rb
CHANGED
@@ -1,51 +1,49 @@
|
|
1
|
-
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
1
|
+
class TraceHeader
|
2
|
+
class Result
|
3
|
+
attr_reader :target_app
|
4
|
+
|
5
|
+
def initialize(target_app, outputs)
|
6
|
+
@target_app = target_app
|
7
|
+
@target_hash = outputs.find { |output| output[:middleware].eql?(target_app.class) }
|
8
|
+
@inner_hash = outputs[outputs.index(@target_hash) + 1]
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def new_headers
|
12
|
+
headers(new_fields)
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
def changed_headers
|
16
|
+
headers(changed_fields)
|
17
|
+
end
|
19
18
|
|
20
|
-
|
19
|
+
private
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def common_fields
|
22
|
+
target_header.keys & prev_header.keys
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
def new_fields
|
26
|
+
target_header.keys - common_fields
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
def changed_fields
|
30
|
+
common_fields.select { |field| target_header[field] != prev_header[field] }
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
def target_header
|
34
|
+
@target_header ||= rack_app(@target_hash)[1]
|
35
|
+
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
def prev_header
|
38
|
+
@prev_header ||= rack_app(@inner_hash)[1]
|
39
|
+
end
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
def rack_app(hash)
|
42
|
+
hash[:app].call(hash[:env])
|
43
|
+
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
45
|
+
def headers(fields)
|
46
|
+
fields.map { |field| { field => target_header[field].to_s } }
|
47
|
+
end
|
50
48
|
end
|
51
49
|
end
|
data/lib/trace_header/version.rb
CHANGED
data/lib/trace_header.rb
CHANGED
@@ -3,50 +3,48 @@ require 'active_support/core_ext'
|
|
3
3
|
require_relative 'trace_header/description'
|
4
4
|
require_relative 'trace_header/result'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
include Description
|
6
|
+
class TraceHeader
|
7
|
+
include Description
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
def initialize(app)
|
10
|
+
@app = app
|
11
|
+
@outputs = []
|
12
|
+
@fixed_app = nil
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
def call(env)
|
16
|
+
tracer.enable { @app.call(env) }
|
17
|
+
display(result)
|
18
|
+
@fixed_app
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
21
|
+
private
|
22
|
+
using Module.new {
|
23
|
+
refine TracePoint do
|
24
|
+
def called_rack_middleware?
|
25
|
+
method_id.eql?(:call) && binding.local_variable_defined?(:env)
|
28
26
|
end
|
29
|
-
|
27
|
+
end
|
28
|
+
}
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
30
|
+
def tracer
|
31
|
+
TracePoint.new(:call, :return) do |tp|
|
32
|
+
if tp.called_rack_middleware?
|
33
|
+
if tp.event.eql?(:call) \
|
34
|
+
&& !@outputs.find { |input| input[:middleware].eql? tp.defined_class }
|
35
|
+
@outputs << { middleware: tp.defined_class,
|
36
|
+
app: tp.self.deep_dup,
|
37
|
+
env: tp.binding.local_variable_get(:env).deep_dup }
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
40
|
+
if tp.event.eql?(:return)
|
41
|
+
@fixed_app = tp.return_value
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
45
|
+
end
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
47
|
+
def result
|
48
|
+
TraceHeader::Result.new(@app, @outputs)
|
49
|
+
end
|
52
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trace_header
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Misaki Shioi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|