migration_queries 1.0.0 → 1.1.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: d841a636d5ad72e9991f1f87ed98bb4a0a1b51098a674db5dae93f5d2f94ccaa
4
- data.tar.gz: aa79169e44d9ce5adbbf1142d738d49b3aee19048f86baa82be747695b653c8a
3
+ metadata.gz: 62f8b4f72f64212491d3cb2e3062ca7fc2e32a79c951e3c21fc5b23e37286f01
4
+ data.tar.gz: b4c174e6969d8969c169207cb5f1786e8aa66d71b3c3692710b187102efc7986
5
5
  SHA512:
6
- metadata.gz: 65e15bb1a441237afbc72d50a9206334dd7dafee4e0f4af3cbbbb949106e3e3e57088bada8464b781071177219ca366f1ffb1e34b3ef30675ce8117a09d59a27
7
- data.tar.gz: b0cecb473508ad96399022335b6ff0e9decc6951f6f7f6b82f6bdd45a7acd70733a16358a8906f4279a93d8697ba8e9240bef4f0e77798a39d8845ac640ff29c
6
+ metadata.gz: 8205a98bbd53287dd1d984a8a683e6419a3c73bcd938c10772239d11fd36ed8710c778b627ccde5d488335794a2249d4922eceb272c8b624cfabef99229bb85d
7
+ data.tar.gz: 38e06a529ce0ca44b7a362f4f500b8d4d1752f99f97e0f3a48b3dbe7d35be489a30f5b843ea5a8b0a33395ae6a38eb735bae97a4eea465bc7d8658641a018380
data/README.md CHANGED
@@ -44,7 +44,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
44
44
 
45
45
  ## Contributing
46
46
 
47
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/migration_queries. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/migration_queries/blob/master/CODE_OF_CONDUCT.md).
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/szymonlipka/migration_queries. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/migration_queries/blob/master/CODE_OF_CONDUCT.md).
48
48
 
49
49
  ## License
50
50
 
@@ -7,19 +7,38 @@ module MigrationQueries
7
7
  # with logic to capture SQL queries executed during migrations.
8
8
  module Executer
9
9
  def execute(sql, *_args)
10
- stack_trace = caller.detect { |path| path.include?(Rails.root.to_s) && path.include?("db/migrate") }
11
- file_path = stack_trace.match(/(.+):\d+:in/)[1] if stack_trace
12
- if defined?(file_path) && file_path
13
- data_object = MigrationQueries.gatherer.queries_data_objects.detect do |data_object|
14
- data_object.file_path == file_path
15
- end || MigrationQueries::Data.new(file_path: file_path)
16
- data_object.sql_queries << sql
17
-
18
- unless MigrationQueries.gatherer.queries_data_objects.include?(data_object)
19
- MigrationQueries.gatherer.queries_data_objects << data_object
20
- end
21
- end
10
+ gather_queries(sql, caller)
22
11
  super
23
12
  end
13
+
14
+ private
15
+
16
+ def gather_queries(sql, caller)
17
+ stack_trace = detect_stack_trace(caller)
18
+ file_path = extract_file_path(stack_trace) if stack_trace
19
+ gatherer = load_gatherer
20
+ return unless defined?(file_path) && file_path
21
+
22
+ data_object = gatherer.queries_data_objects.detect do |data_object|
23
+ data_object.file_path == file_path
24
+ end || MigrationQueries::Data.new(file_path: file_path)
25
+ data_object.sql_queries << sql
26
+
27
+ return if gatherer.queries_data_objects.include?(data_object)
28
+
29
+ MigrationQueries.gatherer.queries_data_objects << data_object
30
+ end
31
+
32
+ def load_gatherer
33
+ MigrationQueries.gatherer
34
+ end
35
+
36
+ def detect_stack_trace(caller)
37
+ caller.detect { |path| path.include?(Rails.root.to_s) && path.include?("db/migrate") }
38
+ end
39
+
40
+ def extract_file_path(stack_trace)
41
+ stack_trace.match(/(.+):\d+:in/)[1]
42
+ end
24
43
  end
25
44
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MigrationQueries
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -1,5 +1,15 @@
1
1
  module MigrationQueries
2
2
  module Executer
3
3
  def execute: -> untyped
4
+
5
+ private
6
+
7
+ def detect_stack_trace: -> String
8
+
9
+ def extract_file_path: -> String
10
+
11
+ def gather_queries: -> untyped
12
+
13
+ def load_gatherer: -> MigrationQueries::Gatherer
4
14
  end
5
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: migration_queries
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Szymon Lipka