query_police 0.1.0.beta → 0.1.2.beta

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: 89db06f142d97fcf351d3c2bdadb121a66a4684e9570293ebe15655cb2cbd62d
4
- data.tar.gz: d5d235f590005a175512b9b807afb606634ab28635c4b466220f537e981567d2
3
+ metadata.gz: b3ba602c5b4a73be62b2660559a20d3314acbe30215cdb501163d4ced4851112
4
+ data.tar.gz: defbfd46a5b7702205e0a3acd7c426374eea75ceb477e8e403972ef8519fb9e8
5
5
  SHA512:
6
- metadata.gz: 9ebdfdcdf9fd986143cab1e481a38260294b7588530a2ce79b6e5066651fc0c38dff8d7c3caf445789da9c5d115e75eab5bb4a136ece64647006687b8ecb0e70
7
- data.tar.gz: f98f685595b74e8e0c45a0308f9f933ecd647de4268a6505184fed24649497d9aee3e0636269347f78ca15bf4d6b32fb56b0149b2653243c048f4be49163c252
6
+ metadata.gz: 06dde4464e7020f9bfb187980f77463b96e7b18d25dacfaf6b58f42cfe538d49ad27e49e62a3294b1b8f312e573d8b252a8c7163c83a0f7ee21c59fd95ee2888
7
+ data.tar.gz: 94950f4b507c314b9cd2f8966516826034028a02d38e089a506067f4466f8273031c94b41c6c998299ca24c5315f061ca5315a79504d921bb7b5f1058d74ae9a
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.4
2
+ TargetRubyVersion: 2.4.1
3
3
 
4
4
  Style/StringLiterals:
5
5
  Enabled: true
@@ -9,5 +9,11 @@ Style/StringLiteralsInInterpolation:
9
9
  Enabled: true
10
10
  EnforcedStyle: double_quotes
11
11
 
12
+ Metrics/MethodLength:
13
+ Max: 15
14
+
15
+ Metrics/AbcSize:
16
+ Max: 17
17
+
12
18
  Layout/LineLength:
13
19
  Max: 120
data/Gemfile CHANGED
@@ -9,4 +9,4 @@ gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
- gem "rubocop", "~> 1.12"
12
+ gem "rubocop", "~> 0.80.0"
@@ -14,7 +14,7 @@ module QueryPolice
14
14
  # @return [String]
15
15
  def dynamic_message(opts)
16
16
  table, column, tag, type = opts.values_at("table", "column", "tag", "type")
17
- message = self.tables.dig(table, "analysis", column, "tags", tag, type) || ""
17
+ message = tables.dig(table, "analysis", column, "tags", tag, type) || ""
18
18
 
19
19
  variables = message.scan(/\$(\w+)/).uniq.map { |var| var[0] }
20
20
  variables.each do |var|
@@ -32,14 +32,14 @@ module QueryPolice
32
32
 
33
33
  def relative_value_of(var, table)
34
34
  value_type = var.match(/amount_/).present? ? "amount" : "value"
35
- self.tables.dig(table, "analysis", var.gsub(/amount_/, ""), value_type)
35
+ tables.dig(table, "analysis", var.gsub(/amount_/, ""), value_type)
36
36
  end
37
37
 
38
38
  # dynamic variable methods
39
39
  def amount(opts)
40
40
  table, column = opts.values_at("table", "column")
41
41
 
42
- self.tables.dig(table, "analysis", column, "amount")
42
+ tables.dig(table, "analysis", column, "amount")
43
43
  end
44
44
 
45
45
  def column(opts)
@@ -49,7 +49,7 @@ module QueryPolice
49
49
  def impact(opts)
50
50
  table, column, tag = opts.values_at("table", "column", "tag")
51
51
 
52
- impact = self.tables.dig(table, "analysis", column, "tags", tag, "impact")
52
+ impact = tables.dig(table, "analysis", column, "tags", tag, "impact")
53
53
 
54
54
  opts.dig("colours").present? ? impact.send(IMPACTS[impact].colour) : impact
55
55
  end
@@ -65,7 +65,7 @@ module QueryPolice
65
65
  def value(opts)
66
66
  table, column = opts.values_at("table", "column")
67
67
 
68
- self.tables.dig(table, "analysis", column, "value")
68
+ tables.dig(table, "analysis", column, "value")
69
69
  end
70
70
  end
71
71
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'analysis/dynamic_message'
3
+ require_relative "analysis/dynamic_message"
4
4
 
5
5
  module QueryPolice
6
6
  # This class is used to store analysis of a query and provide methods over them
@@ -49,7 +49,7 @@ module QueryPolice
49
49
  @summary = {}
50
50
  end
51
51
 
52
- attr_accessor :tables, :table_count, :summary
52
+ attr_accessor :table_count, :tables, :summary
53
53
 
54
54
  # register a table analysis in analysis object
55
55
  # @param name [String] name of the table
@@ -71,7 +71,7 @@ module QueryPolice
71
71
  # }
72
72
  def register_table(name, table_analysis)
73
73
  self.table_count += 1
74
- self.tables.merge!(
74
+ tables.merge!(
75
75
  {
76
76
  name => {
77
77
  "id" => self.table_count,
@@ -90,7 +90,7 @@ module QueryPolice
90
90
 
91
91
  # to get analysis in pretty format with warnings and suggestions
92
92
  # @param opts [Hash] - possible options [positive: <boolean>, negative: <boolean>, caution: <boolean>]
93
- # @return [String] pretty analysis
93
+ # @return [String] pretty analysis
94
94
  def pretty_analysis(opts)
95
95
  final_message = ""
96
96
 
@@ -103,12 +103,12 @@ module QueryPolice
103
103
 
104
104
  # to get analysis in pretty format with warnings and suggestions for a impact
105
105
  # @param impact [String]
106
- # @return [String] pretty analysis
106
+ # @return [String] pretty analysis
107
107
  def pretty_analysis_for(impact)
108
108
  final_message = ""
109
109
 
110
- self.tables.keys.each do |table|
111
- table_message = table_pretty_analysis(table, {impact => true})
110
+ tables.keys.each do |table|
111
+ table_message = table_pretty_analysis(table, { impact => true })
112
112
 
113
113
  final_message += "table: #{table}\n#{table_message}\n" if table_message.present?
114
114
  end
@@ -119,11 +119,11 @@ module QueryPolice
119
119
  # to get analysis in pretty format with warnings and suggestions for a table
120
120
  # @param table [String] - table name
121
121
  # @param opts [Hash] - possible options [positive: <boolean>, negative: <boolean>, caution: <boolean>]
122
- # @return [String] pretty analysis
122
+ # @return [String] pretty analysis
123
123
  def table_pretty_analysis(table, opts)
124
124
  table_message = ""
125
125
 
126
- self.tables.dig(table, "analysis").each do |column, column_analysis|
126
+ tables.dig(table, "analysis").each do |column, column_analysis|
127
127
  tags_message = ""
128
128
  column_analysis.dig("tags").each do |tag, tag_analysis|
129
129
  next unless opts.dig(tag_analysis.dig("impact")).present?
@@ -9,6 +9,6 @@ module QueryPolice
9
9
  DEFAULT_LOGGER_CONFIG = {
10
10
  "negative" => true
11
11
  }.freeze
12
- DEFAULT_RULES_PATH = File.join(File.dirname(__FILE__), "rules.json")
12
+ DEFAULT_RULES_PATH = File.join(File.dirname(__FILE__), "rules.json")
13
13
  end
14
14
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # QueryPolice::Helper
3
4
  module QueryPolice
4
5
  # This module define helper methods for query police
5
6
  module Helper
@@ -15,7 +16,7 @@ module QueryPolice
15
16
  flat_hash
16
17
  end
17
18
 
18
- def logger(message, type="info")
19
+ def logger(message, type = "info")
19
20
  if defined?(Rails) && Rails.logger
20
21
  Rails.logger.send(type, message)
21
22
  else
@@ -24,17 +25,13 @@ module QueryPolice
24
25
  end
25
26
 
26
27
  def load_config(rules_path)
27
- unless File.exists?(rules_path)
28
- raise Error.new(
29
- "Failed to load the rule file from '#{rules_path}'. " \
28
+ unless File.exist?(rules_path)
29
+ raise Error, "Failed to load the rule file from '#{rules_path}'. " \
30
30
  "The file may be missing or there is a problem with the path. " \
31
31
  "Please ensure that the file exists and the path is correct."
32
- )
33
32
  end
34
33
 
35
- rules_config = JSON.parse(File.read(rules_path))
36
-
37
- rules_config
34
+ JSON.parse(File.read(rules_path))
38
35
  end
39
36
 
40
37
  module_function :flatten_hash, :logger, :load_config
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QueryPolice
4
- VERSION = "0.1.0.beta"
4
+ VERSION = "0.1.2.beta"
5
5
  end
data/lib/query_police.rb CHANGED
@@ -58,15 +58,13 @@ module QueryPolice
58
58
  begin
59
59
  if !payload[:exception].present? && payload[:name] =~ /.* Load/
60
60
  analysis = analyse(payload[:sql])
61
-
61
+
62
62
  Helper.logger(analysis.pretty_analysis(logger_config))
63
63
  end
64
- rescue => error
65
- if silent.present?
66
- Helper.logger("#{error.class}: #{error.message}", "error")
67
- else
68
- raise error
69
- end
64
+ rescue StandardError => e
65
+ raise e unless silent.present?
66
+
67
+ Helper.logger("#{e.class}: #{e.message}", "error")
70
68
  end
71
69
  end
72
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: query_police
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta
4
+ version: 0.1.2.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - strikeraryu
@@ -11,7 +11,7 @@ cert_chain: []
11
11
  date: 2023-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -31,7 +31,7 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: 6.0.0
33
33
  - !ruby/object:Gem::Dependency
34
- name: activerecord
34
+ name: activesupport
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
@@ -90,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
90
  requirements:
91
91
  - - ">="
92
92
  - !ruby/object:Gem::Version
93
- version: 2.3.0
93
+ version: 2.4.1
94
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - ">="