prosopite 1.0.8 → 1.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: 1af17b69a330a3d3f6671044a52767af5f93c6245c24f8f690320bf70b863b5f
4
- data.tar.gz: 3abb664fad375de93c92f909e42bcc68d89287271b9be57d85a1c1f9cb561cba
3
+ metadata.gz: 56e92147fb7087e1f4248449f64fa9a1e991c1d3646f71e54d74f72f2ccc98c9
4
+ data.tar.gz: c77c7bc6e0b856de8d634f331b9e8cc56f79359921258ba3a033b374c673b4f8
5
5
  SHA512:
6
- metadata.gz: acdecfb19aff6229c9ec15dd62794b786caf21e30a96d5c8a0038412b1805938217f70380d7501054721f8a716ff40c883b12d21e888befcf434f6a503d2cf99
7
- data.tar.gz: 5d71d8b945b92e3db0a3f9993217ab85a363b5e259134f95be03bb214e8ffdb9bd9e814983104571e698dcb1863f9bb9e3ec89bf0246ebdfbc8d15c75fa9a3b9
6
+ metadata.gz: b5da98b794a360629a55c940dfb73972acc2a4871840fc5577abf346e9fd31d4077dfdc27b874c86ce1aeed179246ae74e47082aa8bf893083327e347df8020e
7
+ data.tar.gz: d74e37b39e303c552e087d53dd3aee596ad441d62a2ae6d48f166c0d2452eab01925639b26c0980e1d697dcd6c05d1c9cae7da8484e159ec27355c2cc8a294fb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prosopite (1.0.8)
4
+ prosopite (1.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -115,10 +115,34 @@ Or install it yourself as:
115
115
 
116
116
  The preferred type of notifications can be configured with:
117
117
 
118
+ * `Prosopite.raise = true`: Raise warnings as exceptions
118
119
  * `Prosopite.rails_logger = true`: Send warnings to the Rails log
119
120
  * `Prosopite.prosopite_logger = true`: Send warnings to `log/prosopite.log`
120
121
  * `Prosopite.stderr_logger = true`: Send warnings to STDERR
121
- * `Prosopite.raise = true`: Raise warnings as exceptions
122
+ * `Prosopite.custom_logger = my_custom_logger`:
123
+
124
+ ### Custom Logging Configuration
125
+
126
+ You can supply a custom logger with the `Prosopite.custom_logger` setting.
127
+
128
+ This is useful for circumstances where you don't want your logs to be
129
+ highlighted with red, or you want logs sent to a custom location.
130
+
131
+ One common scenario is that you may be generating json logs and sending them to
132
+ Datadog, ELK stack, or similar, and don't want to have to remove the default red
133
+ escaping data from messages sent to the Rails logger, or want to tag them
134
+ differently with your own custom logger.
135
+
136
+ ```ruby
137
+ # Turns off logging with red highlights, but still sends them to the Rails logger
138
+ Prosopite.custom_logger = Rails.logger
139
+ ```
140
+
141
+ ```ruby
142
+ # Use a completely custom logging instance
143
+ Prosopite.custom_logger = MyLoggerClass.new
144
+
145
+ ```
122
146
 
123
147
  ## Development Environment Usage
124
148
 
@@ -201,11 +225,19 @@ Prosopite.scan
201
225
  Prosopite.finish
202
226
  ```
203
227
 
204
- or
228
+ In block form the `Prosopite.finish` is called automatically for you at the end of the block:
205
229
 
206
230
  ```ruby
207
231
  Prosopite.scan do
208
- <code to scan>
232
+ <code to scan>
233
+ end
234
+ ```
235
+
236
+ The result of the code block is also returned by `Prosopite.scan`, so you can wrap calls as follows:
237
+
238
+ ```ruby
239
+ my_object = Prosopite.scan do
240
+ MyObjectFactory.create(params)
209
241
  end
210
242
  ```
211
243
 
@@ -223,6 +255,20 @@ Prosopite.resume
223
255
  Prosopite.finish
224
256
  ```
225
257
 
258
+ You can also pause items in a block, and the `Prosopite.resume` will be done
259
+ for you automatically:
260
+
261
+ ```ruby
262
+ Prosopite.scan
263
+ # <code to scan>
264
+
265
+ result = Prosopite.pause do
266
+ # <code that has n+1s>
267
+ end
268
+
269
+ Prosopite.finish
270
+ ```
271
+
226
272
  An example of when you might use this is if you are [testing Active Jobs inline](https://guides.rubyonrails.org/testing.html#testing-jobs),
227
273
  and don't want to run Prosopite on background job code, just foreground app code. In that case you could write an [Active Job callback](https://edgeguides.rubyonrails.org/active_job_basics.html#callbacks) that pauses the scan while the job is running.
228
274
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Prosopite
4
- VERSION = "1.0.8"
4
+ VERSION = "1.1.2"
5
5
  end
data/lib/prosopite.rb CHANGED
@@ -8,6 +8,7 @@ module Prosopite
8
8
  :stderr_logger,
9
9
  :rails_logger,
10
10
  :prosopite_logger,
11
+ :custom_logger,
11
12
  :allow_stack_paths,
12
13
  :ignore_queries
13
14
 
@@ -33,8 +34,9 @@ module Prosopite
33
34
 
34
35
  if block_given?
35
36
  begin
36
- yield
37
+ block_result = yield
37
38
  finish
39
+ block_result
38
40
  ensure
39
41
  tc[:prosopite_scan] = false
40
42
  end
@@ -46,7 +48,17 @@ module Prosopite
46
48
  end
47
49
 
48
50
  def pause
49
- tc[:prosopite_scan] = false
51
+ if block_given?
52
+ begin
53
+ previous = tc[:prosopite_scan]
54
+ tc[:prosopite_scan] = false
55
+ yield
56
+ ensure
57
+ tc[:prosopite_scan] = previous
58
+ end
59
+ else
60
+ tc[:prosopite_scan] = false
61
+ end
50
62
  end
51
63
 
52
64
  def resume
@@ -155,6 +167,7 @@ module Prosopite
155
167
  end
156
168
 
157
169
  def send_notifications
170
+ @custom_logger ||= false
158
171
  @rails_logger ||= false
159
172
  @stderr_logger ||= false
160
173
  @prosopite_logger ||= false
@@ -172,6 +185,8 @@ module Prosopite
172
185
  notifications_str << "\n"
173
186
  end
174
187
 
188
+ @custom_logger.warn(notifications_str) if @custom_logger
189
+
175
190
  Rails.logger.warn(red(notifications_str)) if @rails_logger
176
191
  $stderr.puts(red(notifications_str)) if @stderr_logger
177
192
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prosopite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mpampis Kostas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-25 00:00:00.000000000 Z
11
+ date: 2022-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry