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