bulletmark_repairer 0.1.0 → 0.1.2

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: 90214d67d25519f3e4b352583ad3631773d29444e28ce319d62c89d11fa0149e
4
- data.tar.gz: 59bda8070c7e775774e6d52af33687f3a1da3e26889fe51a2ce71069fb211498
3
+ metadata.gz: 533eed3a74c78c89236e5c1355f588814c6a4017cf79af12f0a0e23fe030fcde
4
+ data.tar.gz: bf8a718e822ba241ab3299f675db3809870d955257bc5279644285373a619141
5
5
  SHA512:
6
- metadata.gz: 2ad6acf09c537b4c283a9404c3518d43f176cc0078406b0371d44f1ea86222e041ddb1f19e9607df95948149f899cc5cda3584753899cc4a85f64232389c2beb
7
- data.tar.gz: a2f5532b82a8f2d9a60d5a72b986d8c81d0d5709905226fb9a5ceac1ddebe1e325039e2870ecc020293b87ed36b10a4aa0ff97a1bd920f09a83e1c2f63268573
6
+ metadata.gz: a33cc9ba73a76ebca97b8293677d8498761a07c2a6680e5182a65b2d8f7cb6237196506aedee63ed4f798168beb4161072ee5e62cbcee9506c4040e4584a508f
7
+ data.tar.gz: 2fb1af553ee13ca638023120306f6284b4d04ae567171616cee658ee5277f1bb33a589d769d7625ad0d6b445d06664a068dc49db479e8ac91934d36aef3553d6
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 3.2
2
+ TargetRubyVersion: 2.7
3
3
  NewCops: enable
4
4
  SuggestExtensions: false
5
5
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.1.2] - 2023-10-16
2
+
3
+ - Reduce dependencies [#1](https://github.com/makicamel/bulletmark_repairer/pull/1) [@tricknotes]()
4
+ - Stop using class instance variables for thread safe [024f6c5](https://github.com/makicamel/bulletmark_repairer/commit/024f6c53f82b182a998c1e43de48d8c6c9ce5bf3)
5
+
6
+ ## [0.1.1] - 2023-10-11
7
+
8
+ - Support Ruby 3.0 [dbdf27c](https://github.com/makicamel/bulletmark_repairer/commit/dbdf27c6c9a7259ad9474153d2394da5bac45b43)
9
+
1
10
  ## [0.1.0] - 2023-10-10
2
11
 
3
12
  - Initial release
data/Gemfile CHANGED
@@ -8,7 +8,6 @@ gemspec
8
8
  gem 'rake', '~> 13.0'
9
9
 
10
10
  gem 'factory_bot_rails'
11
- gem 'rails'
12
11
  gem 'rspec', '~> 3.0'
13
12
  gem 'rspec-rails', '~> 3.0'
14
13
  gem 'sqlite3'
data/README.md CHANGED
@@ -7,7 +7,7 @@ BulletmarkRepairer is an auto corrector for N+1 queries detected at runtime on R
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'bulletmark_repairer', group :development, :test
10
+ gem 'bulletmark_repairer', group: %w(development test)
11
11
  ```
12
12
 
13
13
  ## Usage
@@ -1,18 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BulletmarkRepairer
4
- def self.associations
5
- @associations ||= ApplicationAssociations.new
6
- end
7
-
8
- def self.key(target_klass_name, base_klass_name, candidates)
9
- associations.key(target_klass_name, base_klass_name, candidates)
10
- end
11
-
12
- def self.reset_associations
13
- @associations = nil
14
- end
15
-
16
4
  class ApplicationAssociations
17
5
  def key(target_klass_name, base_klass_name, candidates)
18
6
  key = target_klass_name.underscore
@@ -10,13 +10,19 @@ module BulletmarkRepairer
10
10
  if associations[marker.index]
11
11
  associations[marker.index].add(marker)
12
12
  else
13
- associations[marker.index] = Associations.new(marker)
13
+ associations[marker.index] = Associations.new(marker, @application_associations)
14
14
  end
15
15
  end
16
16
 
17
17
  def associations
18
18
  @associations ||= {}
19
19
  end
20
+
21
+ private
22
+
23
+ def initialize
24
+ @application_associations = BulletmarkRepairer::ApplicationAssociations.new
25
+ end
20
26
  end
21
27
 
22
28
  class Associations
@@ -30,7 +36,7 @@ module BulletmarkRepairer
30
36
 
31
37
  def corrector(dir)
32
38
  BulletmarkRepairer::CorrectorBuilder.new(
33
- dir:,
39
+ dir: dir,
34
40
  marker: @marker,
35
41
  associations: @associations
36
42
  ).execute
@@ -38,16 +44,17 @@ module BulletmarkRepairer
38
44
 
39
45
  private
40
46
 
41
- def initialize(marker)
47
+ def initialize(marker, application_associations)
42
48
  @marker = marker
43
49
  @associations = { base: marker.associations }
50
+ @application_associations = application_associations
44
51
  end
45
52
 
46
53
  # @return [Hash, nil]
47
54
  def build_associations!(marker:, associations:, parent_keys:)
48
- key = formed_key(marker:, associations:)
55
+ key = formed_key(marker: marker, associations: associations)
49
56
  if key
50
- modify_value(key:, marker:, parent_keys:)
57
+ modify_value(key: key, marker: marker, parent_keys: parent_keys)
51
58
  else
52
59
  new_parent_keys = parent_keys
53
60
  new_parent_keys.append(0) if associations.is_a?(Array)
@@ -56,7 +63,7 @@ module BulletmarkRepairer
56
63
 
57
64
  association_values.each do |key, value|
58
65
  values = value.is_a?(Array) ? value : [value]
59
- build_associations!(marker:, associations: { key => values }, parent_keys: new_parent_keys)
66
+ build_associations!(marker: marker, associations: { key => values }, parent_keys: new_parent_keys)
60
67
  end
61
68
  end
62
69
  end
@@ -66,12 +73,12 @@ module BulletmarkRepairer
66
73
  def formed_key(marker:, associations:)
67
74
  case associations
68
75
  when Hash
69
- BulletmarkRepairer.key(marker.base_class, @marker.base_class, associations.keys) ||
70
- BulletmarkRepairer.key(marker.base_class, @marker.base_class, associations.values.flatten)
76
+ @application_associations.key(marker.base_class, @marker.base_class, associations.keys) ||
77
+ @application_associations.key(marker.base_class, @marker.base_class, associations.values.flatten)
71
78
  when Array
72
- BulletmarkRepairer.key(marker.base_class, @marker.base_class, associations)
79
+ @application_associations.key(marker.base_class, @marker.base_class, associations)
73
80
  else # Symbol, String
74
- BulletmarkRepairer.key(marker.base_class, @marker.base_class, [associations])
81
+ @application_associations.key(marker.base_class, @marker.base_class, [associations])
75
82
  end
76
83
  end
77
84
 
@@ -42,7 +42,7 @@ class Corrector < Parser::TreeRewriter
42
42
  insert_after node.children.last.location.expression, ".includes(#{associations})"
43
43
  @patched = true
44
44
  else
45
- node.children.each { |child_node| insert_includes_for_vasgn(node: child_node, type:) }
45
+ node.children.each { |child_node| insert_includes_for_vasgn(node: child_node, type: type) }
46
46
  end
47
47
  end
48
48
 
@@ -19,8 +19,8 @@ module BulletmarkRepairer
19
19
  else
20
20
  @markers[base_class] = Marker.new(
21
21
  notification,
22
- controller:,
23
- action:
22
+ controller: controller,
23
+ action: action
24
24
  )
25
25
  end
26
26
  end
@@ -5,9 +5,9 @@ require 'securerandom'
5
5
  require 'parser/runner/ruby_rewrite'
6
6
 
7
7
  module BulletmarkRepairer
8
- class Pathcer
8
+ class Patcher
9
9
  def self.execute(notifications:, controller:, action:)
10
- new(notifications:, controller:, action:).execute
10
+ new(notifications: notifications, controller: controller, action: action).execute
11
11
  end
12
12
 
13
13
  def execute
@@ -25,7 +25,7 @@ module BulletmarkRepairer
25
25
  private
26
26
 
27
27
  def initialize(notifications:, controller:, action:)
28
- @markers = Markers.new(notifications, controller:, action:)
28
+ @markers = Markers.new(notifications, controller: controller, action: action)
29
29
  @associations_builder = BulletmarkRepairer::AssociationsBuilder.new
30
30
  end
31
31
  end
@@ -7,12 +7,11 @@ module BulletmarkRepairer
7
7
  end
8
8
 
9
9
  def call(env)
10
- BulletmarkRepairer.reset_associations
11
10
  @app.call(env)
12
11
  ensure
13
12
  begin
14
13
  if Thread.current[:bullet_notification_collector].notifications_present?
15
- BulletmarkRepairer::Pathcer.execute(
14
+ BulletmarkRepairer::Patcher.execute(
16
15
  notifications: Thread.current[:bullet_notification_collector],
17
16
  controller: env['action_dispatch.request.parameters']['controller'],
18
17
  action: env['action_dispatch.request.parameters']['action']
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BulletmarkRepairer
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'bulletmark_repairer/version'
4
4
  require 'bulletmark_repairer/railtie' if ENV['REPAIR']
5
- require 'bulletmark_repairer/bulletmark_repairer'
5
+ require 'bulletmark_repairer/application_associations'
6
6
  require 'bulletmark_repairer/associations_builder'
7
7
  require 'bulletmark_repairer/configuration'
8
8
  require 'bulletmark_repairer/corrector_builder'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulletmark_repairer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - makicamel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-10 00:00:00.000000000 Z
11
+ date: 2023-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bullet
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +53,7 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: rails
56
+ name: railties
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -68,8 +82,8 @@ files:
68
82
  - README.md
69
83
  - Rakefile
70
84
  - lib/bulletmark_repairer.rb
85
+ - lib/bulletmark_repairer/application_associations.rb
71
86
  - lib/bulletmark_repairer/associations_builder.rb
72
- - lib/bulletmark_repairer/bulletmark_repairer.rb
73
87
  - lib/bulletmark_repairer/configuration.rb
74
88
  - lib/bulletmark_repairer/controller_corrector.rb
75
89
  - lib/bulletmark_repairer/corrector.rb
@@ -96,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
110
  requirements:
97
111
  - - ">="
98
112
  - !ruby/object:Gem::Version
99
- version: 2.6.0
113
+ version: 2.7.0
100
114
  required_rubygems_version: !ruby/object:Gem::Requirement
101
115
  requirements:
102
116
  - - ">="