eager_eye 1.2.10 → 1.2.11
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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +1 -1
- data/lib/eager_eye/detectors/base.rb +12 -0
- data/lib/eager_eye/detectors/custom_method_query.rb +2 -1
- data/lib/eager_eye/detectors/loop_association.rb +2 -1
- data/lib/eager_eye/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6f108cfabf63f2311f76b96145ea91535ef022703c3d10f73f04cbf6132110ba
|
|
4
|
+
data.tar.gz: ee909d0893f862770c3e481adf5e9041da306c86e821458dd5c069404738ff1a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 387702e5516001bd86637e039c999dbb52cf30e1d20ec293afd23c70a4b591be34f0aa245bc96eb6d5bec4e1e34a3a9bc9e09295525db53550b2df6833a3a06c
|
|
7
|
+
data.tar.gz: 605eec5df28fdaf038d77c95c564e8ee3eb4768be9e900be58c96b99a0b715ad4d28b286c65a2c7844f61906146db39168761744386f73ce5f61e1e77fe7c4cb
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.2.11] - 2026-03-17
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **`each_with_object` / `reduce` / `inject` Support** - `LoopAssociation` and `CustomMethodQuery` detectors now recognize these iteration methods
|
|
15
|
+
- `each_with_object` and `each_with_index` blocks are detected (item is first param)
|
|
16
|
+
- `reduce` and `inject` blocks are detected with correct variable extraction (item is second param: `|memo, item|`)
|
|
17
|
+
- `extract_iteration_variable` helper added to `Base` for reuse across detectors
|
|
18
|
+
|
|
10
19
|
## [1.2.10] - 2026-03-16
|
|
11
20
|
|
|
12
21
|
### Added
|
data/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
12
12
|
<a href="https://github.com/hamzagedikkaya/eager_eye/actions/workflows/main.yml"><img src="https://github.com/hamzagedikkaya/eager_eye/actions/workflows/main.yml/badge.svg" alt="CI"></a>
|
|
13
|
-
<a href="https://rubygems.org/gems/eager_eye"><img src="https://img.shields.io/badge/gem-v1.2.
|
|
13
|
+
<a href="https://rubygems.org/gems/eager_eye"><img src="https://img.shields.io/badge/gem-v1.2.11-red.svg" alt="Gem Version"></a>
|
|
14
14
|
<a href="https://github.com/hamzagedikkaya/eager_eye"><img src="https://img.shields.io/badge/coverage-95%25-brightgreen.svg" alt="Coverage"></a>
|
|
15
15
|
<a href="https://www.ruby-lang.org/"><img src="https://img.shields.io/badge/ruby-%3E%3D%203.1-ruby.svg" alt="Ruby"></a>
|
|
16
16
|
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
|
|
@@ -73,12 +73,24 @@ module EagerEye
|
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
+
ACCUMULATOR_FIRST_METHODS = %i[reduce inject].freeze
|
|
77
|
+
|
|
76
78
|
def extract_block_variable(block_node)
|
|
77
79
|
args = block_node&.children&.[](1)
|
|
78
80
|
first_arg = args&.children&.first
|
|
79
81
|
first_arg&.type == :arg ? first_arg.children[0] : nil
|
|
80
82
|
end
|
|
81
83
|
|
|
84
|
+
def extract_iteration_variable(block_node)
|
|
85
|
+
idx = accumulator_first?(block_node) ? 1 : 0
|
|
86
|
+
arg = block_node.children[1]&.children&.[](idx)
|
|
87
|
+
arg&.type == :arg ? arg.children[0] : nil
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def accumulator_first?(block_node)
|
|
91
|
+
ACCUMULATOR_FIRST_METHODS.include?(block_node.children[0]&.children&.[](1))
|
|
92
|
+
end
|
|
93
|
+
|
|
82
94
|
def receiver_chain_starts_with?(node, target_var)
|
|
83
95
|
return false unless node.is_a?(Parser::AST::Node)
|
|
84
96
|
|
|
@@ -9,6 +9,7 @@ module EagerEye
|
|
|
9
9
|
SAFE_TRANSFORM_METHODS = %i[keys values split [] params sort pluck ids to_s to_a to_i chars bytes].freeze
|
|
10
10
|
ARRAY_COLUMN_SUFFIXES = %w[_ids _tags _types _codes _names _values _arr].freeze
|
|
11
11
|
ITERATION_METHODS = %i[each map select find_all reject collect detect find_index flat_map
|
|
12
|
+
each_with_index each_with_object reduce inject
|
|
12
13
|
find_each find_in_batches in_batches].freeze
|
|
13
14
|
|
|
14
15
|
def self.detector_name
|
|
@@ -38,7 +39,7 @@ module EagerEye
|
|
|
38
39
|
definitions[node.children[0]] = node.children[1] if node.type == :lvasgn
|
|
39
40
|
|
|
40
41
|
if iteration_block?(node)
|
|
41
|
-
block_var =
|
|
42
|
+
block_var = extract_iteration_variable(node)
|
|
42
43
|
block_body = node.children[2]
|
|
43
44
|
yield(block_body, block_var, node.children[0], definitions) if block_var && block_body
|
|
44
45
|
end
|
|
@@ -4,6 +4,7 @@ module EagerEye
|
|
|
4
4
|
module Detectors
|
|
5
5
|
class LoopAssociation < Base
|
|
6
6
|
ITERATION_METHODS = %i[each map collect select find find_all reject filter filter_map flat_map
|
|
7
|
+
each_with_index each_with_object reduce inject
|
|
7
8
|
find_each find_in_batches in_batches].freeze
|
|
8
9
|
PRELOAD_METHODS = %i[includes preload eager_load].freeze
|
|
9
10
|
SINGLE_RECORD_METHODS = %i[find find_by find_by! first first! last last! take take! second third fourth fifth
|
|
@@ -42,7 +43,7 @@ module EagerEye
|
|
|
42
43
|
traverse_ast(ast) do |node|
|
|
43
44
|
next unless iteration_block?(node)
|
|
44
45
|
|
|
45
|
-
block_var =
|
|
46
|
+
block_var = extract_iteration_variable(node)
|
|
46
47
|
next unless block_var
|
|
47
48
|
|
|
48
49
|
block_body = node.children[2]
|
data/lib/eager_eye/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: eager_eye
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- hamzagedikkaya
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-03-
|
|
11
|
+
date: 2026-03-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ast
|