query_guard 0.1.0 → 0.2.0

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
2
  SHA256:
3
- metadata.gz: ab42a4becef74dd106779b1e16f65f3e0178762531ede328212958cb36dbb2f5
4
- data.tar.gz: e49b0e60d3ede416580c4e92e2f46142f3bbcc0c13da5ac9fde9024a001cccca
3
+ metadata.gz: 1529067d785bd02d4c390bc24108a5b6f8c63c97cc20584bb8246b02c28e3b22
4
+ data.tar.gz: 144be63e0f488a7c9f781bd74f70821405283b6dba481703013d1d6af51c8e30
5
5
  SHA512:
6
- metadata.gz: 756393f33c6e2c44650b377db916c3c516f5d49191ba9557461b8dfa9bcc8a977048fcf919b71c2ef101b0cb2bfe9f92fefe639ab88d28d01a09f9d565855046
7
- data.tar.gz: 77f0b2337a0330922438eeb20ed1b946b0b0e1264622e577a4ad005cf7e9288efda5fafb34351d0691fa489cf2dc4f123c6ec8b1c9b4f413d1c5acf8fc770122
6
+ metadata.gz: 6a47f42d0dd115dab29043257c4c261fc9b80ee2a8912ede41df214a8f6e4ba538c4ef2cf395947241e713947284cce86da07bd7c0539a290a4b15b37ee72054
7
+ data.tar.gz: 8248d356a8dea4031c2d52fca8bb5e0529d30177aad57165a142982f0104a526a42ac5611190dba003b19d087e913a4a6f0501160c1c9408aed3a102518fa5f0
data/README.md CHANGED
@@ -8,3 +8,56 @@ Add to your Gemfile:
8
8
 
9
9
  ```ruby
10
10
  gem "query_guard"
11
+ ```
12
+
13
+ ## ⚙️ Configuration File
14
+
15
+ To enable and configure `QueryGuard` in your Rails application,
16
+ you need to create an initializer file with the configuration options below.
17
+
18
+ ---
19
+
20
+ ### 1️⃣ Create the configuration file
21
+
22
+ Run this command inside your Rails app:
23
+
24
+ ```bash
25
+ touch config/initializers/query_guard.rb
26
+ ```
27
+
28
+ ### 2️⃣ Add the following code inside that file:
29
+
30
+ ```ruby
31
+ # config/initializers/query_guard.rb
32
+
33
+ # Configure QueryGuard settings
34
+ QueryGuard.configure do |config|
35
+ # Environments where QueryGuard should be active
36
+ # By default: [:development, :test]
37
+ config.enabled_environments = %i[development test]
38
+
39
+ # Maximum number of SQL queries allowed per request
40
+ # Use nil to disable this limit
41
+ config.max_queries_per_request = 100
42
+
43
+ # Maximum duration (milliseconds) for a single SQL query
44
+ # Logs as a slow query if exceeded
45
+ config.max_duration_ms_per_query = 100.0
46
+
47
+ # Whether to flag or block SELECT * statements
48
+ config.block_select_star = true
49
+
50
+ # Ignore certain SQL patterns (e.g., schema and transaction queries)
51
+ config.ignored_sql = [
52
+ /^PRAGMA /i, # SQLite schema queries
53
+ /^BEGIN/i,
54
+ /^COMMIT/i
55
+ ]
56
+
57
+ # Raise exception on violation instead of just logging
58
+ config.raise_on_violation = false
59
+
60
+ # Prefix for log messages in Rails logs
61
+ config.log_prefix = "[QueryGuard]"
62
+ end
63
+ ```
@@ -3,7 +3,8 @@ module QueryGuard
3
3
  class Config
4
4
  attr_accessor :enabled_environments, :max_queries_per_request,
5
5
  :max_duration_ms_per_query, :block_select_star,
6
- :ignored_sql, :raise_on_violation, :log_prefix
6
+ :ignored_sql, :raise_on_violation, :log_prefix,
7
+ :base_url, :api_key, :project, :env
7
8
 
8
9
  def initialize
9
10
  @enabled_environments = %i[development test]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QueryGuard
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/query_guard.rb CHANGED
@@ -8,6 +8,8 @@ require "query_guard/middleware"
8
8
 
9
9
  module QueryGuard
10
10
  class << self
11
+ mattr_accessor :client, :config
12
+
11
13
  def config
12
14
  @config ||= Config.new
13
15
  end
@@ -17,6 +19,17 @@ module QueryGuard
17
19
  self
18
20
  end
19
21
 
22
+ def configure
23
+ config ||= Config.new
24
+ yield(config)
25
+ client = Client.new(
26
+ base_url: config.base_url,
27
+ api_key: config.api_key,
28
+ project: config.project,
29
+ env: config.env
30
+ )
31
+ end
32
+
20
33
  def install!(app = nil)
21
34
  # Install SQL subscriber once
22
35
  Subscriber.install!(config)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: query_guard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chitradevi36
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-11-02 00:00:00.000000000 Z
11
+ date: 2025-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake