query_diet 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 63b41117d8dd5d5e67272b8d4fcabc22b4068bac
4
- data.tar.gz: '08680b0daeeb2198831f722750cc6d494ff59e82'
2
+ SHA256:
3
+ metadata.gz: d4cbd625d753ea248e00e78049554a3a385dbb1ef3c45d70d77e0b957034538a
4
+ data.tar.gz: 4e636ba8f1a2d39648ec6072d7be893d0e105854f003d26dfd618f4745e1aa2a
5
5
  SHA512:
6
- metadata.gz: f34ca786690572f2b092b4150792be7e8734a74245fb63754b4fbfb8ad1c7caa0f250bb52ec1176b9aa2f57db777ec03413ac1f01be6e90580a844a53bfb8dac
7
- data.tar.gz: b94095083324e7b117315ffb69e6b76b334714daa7e654f14f69425f491dd08fb8d77856126f3781c41522437d0566125f1c4dc39d07170453a8f38c2d0bdf2e
6
+ metadata.gz: d1e410f4870b44b6dfb708292f4e3c01a673572e752f4084e421e4bab74075a207db37e109cdfaf080b9be922c1a760b68c240ebf96a29b8fd29a08681e6d862
7
+ data.tar.gz: 5607974067f7ac67cb619f8f8a89596f8ea39fa52a8adfa9eb6371a26e00e847faeb37319478c64b54ee928539672148074c21251fa6ab09d5bb2147b09fc4eb
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Query Diet [![Build Status](https://travis-ci.org/makandra/query_diet.svg?branch=master)](https://travis-ci.org/makandra/query_diet)
1
+ Query Diet [![Tests](https://github.com/makandra/query_diet/workflows/Tests/badge.svg)](https://github.com/makandra/query_diet/actions)
2
2
  ==========
3
3
 
4
4
  Query Diet counts the number of database queries for the last request and *subtly* displays it in the upper right corner of your screen.
@@ -45,10 +45,29 @@ To change the default, simply pass them to the `query_diet_widget` helper:
45
45
  <%= query_diet_widget(:bad_count => 4, :bad_time => 2000) %>
46
46
  ```
47
47
 
48
+ ### Content Security Policy
49
+
50
+ You can pass whether to use a nonce for style and script tags.
51
+ Note that the key must be a symbol like in the example below, otherwise it defaults to `false`.
52
+
53
+ ```Erb
54
+ <%= query_diet_widget(:nonce => true) if Rails.env.development? %>
55
+ ```
56
+
57
+ In your content security policy initializer of the project you should set the nonce to those directives:
58
+ ```Erb
59
+ Rails.application.config.content_security_policy_nonce_directives = %w[script-src style-src]
60
+ ```
61
+
62
+ When you do not want to use a nonce, but use a style tag, for example, you could use `unsafe_inline`:
63
+ ```Erb
64
+ Rails.application.config.content_security_policy do |policy|
65
+ policy.style_src :self, :unsafe_inline
66
+ ```
48
67
 
49
68
  ### Rails compatibility
50
69
 
51
- The gem is tested to work with Rails 3.2+ and Ruby 2.0+.
70
+ The gem is tested to work with Rails 3.2+ and Ruby 2.5.8+.
52
71
 
53
72
  For Rails 2.3 and Ruby 1.8.7 support, use a version < 0.6.
54
73
 
@@ -1,7 +1,13 @@
1
1
  module QueryDiet
2
2
  module ActiveRecordExt
3
- def log(query, *)
4
- QueryDiet::Logger.log(query) { super }
3
+ if RUBY_VERSION >= '3'
4
+ def log(query, *, **)
5
+ QueryDiet::Logger.log(query) { super }
6
+ end
7
+ else
8
+ def log(query, *)
9
+ QueryDiet::Logger.log(query) { super }
10
+ end
5
11
  end
6
12
  end
7
13
  end
@@ -1,3 +1,3 @@
1
1
  module QueryDiet
2
- VERSION = '0.6.1'
2
+ VERSION = '0.7.1'
3
3
  end
@@ -2,16 +2,16 @@ module QueryDiet
2
2
  module Widget
3
3
  class << self
4
4
 
5
- def css
5
+ def css(nonce_attribute)
6
6
  <<-EOF
7
- <style type="text/css"><!--
7
+ <style type="text/css"#{nonce_attribute}><!--
8
8
  div#query_diet {
9
9
  position: absolute;
10
10
  top: 0;
11
11
  right: 0;
12
12
  background-color: black;
13
13
  color: white;
14
- z-index: 999;
14
+ z-index: 99999;
15
15
  padding: 4px 6px;
16
16
  font: normal bold 12px/12px Arial, sans-serif;
17
17
  cursor: pointer;
@@ -31,9 +31,19 @@ module QueryDiet
31
31
  EOF
32
32
  end
33
33
 
34
+ def js(nonce_attribute)
35
+ <<-EOF
36
+ <script type="text/javascript"#{nonce_attribute}>
37
+ document.getElementById("query_diet").addEventListener("click", function() {
38
+ this.parentNode.removeChild(this);
39
+ });
40
+ </script>
41
+ EOF
42
+ end
43
+
34
44
  def html(options)
35
45
  <<-EOF
36
- <div id="query_diet" class="#{QueryDiet::Logger.bad?(options) ? 'bad' : 'good' }" onclick="this.parentNode.removeChild(this);">
46
+ <div id="query_diet" class="#{QueryDiet::Logger.bad?(options) ? 'bad' : 'good' }">
37
47
  #{QueryDiet::Logger.count} / #{QueryDiet::Logger.time}ms
38
48
  </div>
39
49
  EOF
@@ -43,7 +53,12 @@ module QueryDiet
43
53
 
44
54
  module Helper
45
55
  def query_diet_widget(options = {})
46
- html = Widget.css + Widget.html(options)
56
+ default_html_options = {:nonce => false}
57
+ options = options.reverse_merge(default_html_options)
58
+
59
+ nonce_attribute = options.fetch(:nonce) ? " nonce=\"#{content_security_policy_nonce}\"" : ''
60
+
61
+ html = Widget.css(nonce_attribute) + Widget.html(options) + Widget.js(nonce_attribute)
47
62
  html.respond_to?(:html_safe) ? html.html_safe : html
48
63
  end
49
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: query_diet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-02-07 00:00:00.000000000 Z
12
+ date: 2022-02-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Rails database query counter that stays out of your way
15
15
  email: github@makandra.de
@@ -28,7 +28,8 @@ files:
28
28
  homepage: https://github.com/makandra/query_diet
29
29
  licenses:
30
30
  - MIT
31
- metadata: {}
31
+ metadata:
32
+ rubygems_mfa_required: 'true'
32
33
  post_install_message:
33
34
  rdoc_options: []
34
35
  require_paths:
@@ -44,8 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
45
  - !ruby/object:Gem::Version
45
46
  version: '0'
46
47
  requirements: []
47
- rubyforge_project:
48
- rubygems_version: 2.5.1
48
+ rubygems_version: 3.2.3
49
49
  signing_key:
50
50
  specification_version: 4
51
51
  summary: Rails database query counter that stays out of your way