rails-response-dumper 5.3.0 → 6.1.0

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: 83121f82eb5299087a5a7f51a1a1950767b0ae34e893f5c48005bb288950f634
4
- data.tar.gz: d42cca1ffad83f7df8ffdda62f2b4d2610d98caa21ef96c2cfa52443a47d8386
3
+ metadata.gz: 59962fdb92a1c349f0261e238a2ed342980353b2a3f51c0f61ec13cae47b42dd
4
+ data.tar.gz: 1fbc0d60ce41ed61c956f57d4a473eaa74f88cfe2d66f0198897a8565bb8fd81
5
5
  SHA512:
6
- metadata.gz: 3b4183a48c0ad2d313565a10bfcd995bc6b8325ef1f979771c32958ef79515d73586c1bfdfd7cca1d735abbd185ce0ec8f2031bf0d5e7aac585be1ef4b45b91d
7
- data.tar.gz: cecaddd1391cd0fcbb9560cf251b61769e3ca94a31b45f51d18cd2c4df30e3c73de4fc9b6fac4f0bbb3325df261447e437b35370f43bab0423f709b589a19635
6
+ metadata.gz: 8118f205179b4d16c035ecbe371e35f2eba95befe8196d493ad9c7a7461fcd83e241fcfb1b55cc79ac11458e8c7db59dd72203a3703f56776b6371fea5428944
7
+ data.tar.gz: fe1aed1e3e48342a9665f16254695ebef5acd64213b43e2afcb222455c7c83e08435a13fc26957a49c520f9b1c4bf22df0251e0325e40e5555002b7245711387
@@ -4,9 +4,23 @@ require 'optparse'
4
4
 
5
5
  module RailsResponseDumper
6
6
  def self.parse_options!
7
- options = {}
7
+ options = { 'dumps-dir' => Rails.root.join('dumps') }
8
8
 
9
9
  OptionParser.new do |opts|
10
+ opts.banner += ' [glob]'
11
+
12
+ opts.separator ''
13
+ opts.separator 'Filtering:'
14
+ opts.separator 'Run for specific files or globs:'
15
+ opts.separator ' rails-response-dumper path/to/a_dumper.rb'
16
+
17
+ opts.separator ''
18
+ opts.separator 'Options:'
19
+
20
+ opts.on('--dumps-dir PATH', 'Output dumps to this directory.') do |v|
21
+ options['dumps-dir'] = v
22
+ end
23
+
10
24
  opts.on('--fail-fast', 'Abort the run after first failure.') do |v|
11
25
  options[:fail_fast] = v
12
26
  end
@@ -18,8 +32,14 @@ module RailsResponseDumper
18
32
  opts.on('--order TYPE', 'Run dumps by the specified order type.') do |v|
19
33
  options[:order] = v
20
34
  end
35
+
36
+ opts.on('--exclude-response-headers', 'Do not output response headers.') do |v|
37
+ options[:exclude_response_headers] = v
38
+ end
21
39
  end.parse!
22
40
 
41
+ options[:filenames] = ARGV
42
+
23
43
  options.freeze
24
44
  end
25
45
  end
@@ -12,15 +12,29 @@ module RailsResponseDumper
12
12
  end
13
13
 
14
14
  def run_dumps
15
- dumps_dir = Rails.root.join('dumps')
16
- FileUtils.rm_rf dumps_dir
15
+ dumps_dir = options['dumps-dir']
16
+
17
+ if options[:filenames].present?
18
+ globs = options[:filenames]
19
+ else
20
+ globs = ['dumpers/**/*.rb']
21
+ FileUtils.rm_rf dumps_dir
22
+ end
23
+
17
24
  FileUtils.mkdir_p dumps_dir
18
25
 
19
- Dir[Rails.root.join('dumpers/**/*.rb')].each { |f| require f }
26
+ globs.each do |glob|
27
+ Dir[Rails.root.join(glob)].each { |f| require f }
28
+ end
20
29
 
21
30
  errors = []
22
31
 
23
32
  dumper_blocks = RailsResponseDumper::Defined.dumpers.flat_map do |defined|
33
+ if options[:filenames].present?
34
+ # clear previous dumps for that file in case removed from updated dump file
35
+ FileUtils.rm_rf "#{dumps_dir}/#{defined.name.underscore}/"
36
+ end
37
+
24
38
  defined.blocks.map do |dump_block|
25
39
  [defined, dump_block]
26
40
  end
@@ -81,6 +95,7 @@ module RailsResponseDumper
81
95
  end
82
96
 
83
97
  request = response.request
98
+
84
99
  dump = {
85
100
  request: {
86
101
  method: request.method,
@@ -89,11 +104,14 @@ module RailsResponseDumper
89
104
  },
90
105
  response: {
91
106
  status: response.status,
92
- status_text: response.status_message,
107
+ statusText: response.status_message,
93
108
  headers: response.headers,
94
109
  body: response.body
95
110
  }
96
111
  }
112
+
113
+ dump[:response].delete(:headers) if options[:exclude_response_headers]
114
+
97
115
  File.write("#{dumper_dir}/#{index}.json", JSON.pretty_generate(dump))
98
116
  end
99
117
 
@@ -135,7 +153,7 @@ module RailsResponseDumper
135
153
 
136
154
  def rollback_after
137
155
  if defined?(ActiveRecord::Base)
138
- ActiveRecord::Base.transaction do
156
+ ActiveRecord::Base.transaction(joinable: false) do
139
157
  yield
140
158
  raise ActiveRecord::Rollback
141
159
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-response-dumper
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.0
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pioneer Valley Books
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-07 00:00:00.000000000 Z
11
+ date: 2023-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  requirements: []
85
- rubygems_version: 3.3.7
85
+ rubygems_version: 3.4.10
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Dump HTTP responses from a Rails application to the file system