Skip to content

Commit

Permalink
Merge pull request #949 from andrykonchin/optimize-performance-attrib…
Browse files Browse the repository at this point in the history
…ute_defined_statically

Performance. FactoryBot/AttributeDefinedStatically
  • Loading branch information
Darhazer committed Jun 30, 2020
2 parents 87229cc + 97f1b58 commit c51c544
Showing 1 changed file with 5 additions and 2 deletions.
Expand Up @@ -31,12 +31,15 @@ class AttributeDefinedStatically < Cop
(send _ !#reserved_method? $...)
PATTERN

def_node_search :factory_attributes, <<-PATTERN
def_node_matcher :factory_attributes, <<-PATTERN
(block (send _ #attribute_defining_method? ...) _ { (begin $...) $(send ...) } )
PATTERN

def on_block(node)
factory_attributes(node).to_a.flatten.each do |attribute|
attributes = factory_attributes(node) || []
attributes = [attributes] unless attributes.is_a?(Array)

attributes.each do |attribute|
next unless offensive_receiver?(attribute.receiver, node)
next if proc?(attribute) || association?(attribute.first_argument)

Expand Down

0 comments on commit c51c544

Please sign in to comment.