eager_eye 0.2.1 → 0.2.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: 2c1781e66205a83557a9751b64f19c44d70f90efbd04423d63e847d4e4a06c6e
4
- data.tar.gz: eac8bb2e4a8b86017804b2c9662074ece08346a5303b5760bdba6dc7d939b3d9
3
+ metadata.gz: 6329285c3bdd39b8c99bbf665ffef121ac0dc5530b26b8e125d71ca04239a7a4
4
+ data.tar.gz: 78a608b043a06a58b22a54553d0c0b4ee459c2ee921405f01c5a216a77e801fb
5
5
  SHA512:
6
- metadata.gz: 9a9fec60ec826824ef8b331f95f33918265f51ea027b43f60852656a0b1420622b9405a78f0fdc4ba3e32c9a30159deb5104fe7432b35fdf9bdea8e5325aa120
7
- data.tar.gz: fe4032176ada8b10c84ee56c48a8ee60aadbf7c6547e98e0f36def0226a119a7383e6258a060a197b4b6276667fd65f30707dbaeda155ff9410551b2111167ed
6
+ metadata.gz: 5d985342e6d3bc4a09dab284b153807b4cda7a7dce898c4dca9ca3e0223e6fb2f575b369426a2a04c30f4d04b557749be8091ee4ed23de4c4a86522d410867ec
7
+ data.tar.gz: 18ba07590dce273befec6295f0ce05702241ee46a727c05825dd573d44e3019839655f0da14dc9674f5ded7d56b7ee21d802b6264a2b2a85c5f6859928c887da
@@ -49,7 +49,11 @@ module EagerEye
49
49
  block_body = node.children[2]
50
50
  next unless block_body
51
51
 
52
- find_association_calls(block_body, block_var, file_path, issues)
52
+ # Check if the collection already has includes
53
+ collection_node = node.children[0]
54
+ included_associations = extract_included_associations(collection_node)
55
+
56
+ find_association_calls(block_body, block_var, file_path, issues, included_associations)
53
57
  end
54
58
 
55
59
  issues
@@ -78,7 +82,44 @@ module EagerEye
78
82
  first_arg.children[0]
79
83
  end
80
84
 
81
- def find_association_calls(node, block_var, file_path, issues)
85
+ def extract_included_associations(collection_node)
86
+ included = Set.new
87
+ return included unless collection_node&.type == :send
88
+
89
+ # Traverse through chained method calls to find includes()
90
+ current = collection_node
91
+ while current&.type == :send
92
+ method_name = current.children[1]
93
+ extract_includes_from_method(current, included) if method_name == :includes
94
+
95
+ current = current.children[0]
96
+ end
97
+
98
+ included
99
+ end
100
+
101
+ def extract_includes_from_method(method_node, included_set)
102
+ args = method_node.children[2..]
103
+ args&.each do |arg|
104
+ case arg&.type
105
+ when :sym
106
+ # includes(:product)
107
+ included_set.add(arg.children[0])
108
+ when :hash
109
+ # includes(product: :manufacturer)
110
+ extract_from_hash(arg, included_set)
111
+ end
112
+ end
113
+ end
114
+
115
+ def extract_from_hash(hash_node, included_set)
116
+ hash_node.children.each do |pair|
117
+ key = pair.children[0]
118
+ included_set.add(key.children[0]) if key&.type == :sym
119
+ end
120
+ end
121
+
122
+ def find_association_calls(node, block_var, file_path, issues, included_associations = Set.new)
82
123
  reported_associations = Set.new
83
124
 
84
125
  traverse_ast(node) do |child|
@@ -91,6 +132,9 @@ module EagerEye
91
132
  next unless direct_call_on_block_var?(receiver, block_var)
92
133
  next unless likely_association?(method_name)
93
134
 
135
+ # Skip if association is already included
136
+ next if included_associations.include?(method_name)
137
+
94
138
  # Avoid duplicate reports for same association on same line
95
139
  report_key = "#{child.loc.line}:#{method_name}"
96
140
  next if reported_associations.include?(report_key)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EagerEye
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eager_eye
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - hamzagedikkaya