Stop class_eval/instance_eval being counted as a nested iterator
Reported by Ashley Moran | April 3rd, 2009 @ 03:04 PM
The following code:
@model_class.class_eval do |variable|
persisted_entity_class.entity_class_properties.each do |ecp|
property ecp.identifier.to_sym, String, :nullable => false
end
end
causes this spec failure for me:
'dm-datamapper-adapter has no code smells' FAILED
Expected no smells, but got:
"lib/datamapper_adapter/model_class_factory.rb" -- 1 warnings:
DataMapper::Adapters::DataMapperAdapter#ModelClassFactory#ModelClassBuilder#add_properties!/block/block is nested (Nested Iterators)
Is there another way to structure this code? Or is this reek being over-sensitive to blocks? (I can't see a less-nested solution!)
Comments and changes to this ticket
-
Kevin Rutherford April 5th, 2009 @ 07:50 AM
- Assigned user set to Kevin Rutherford
-
Kevin Rutherford April 5th, 2009 @ 08:13 AM
Can you simply extract the outer block's body into a new method?
-
Kevin Rutherford April 7th, 2009 @ 01:28 PM
Well there's a chunk of duplication in that code: every call to property (where is that defined, btw?) is embedded in a call to class_eval. So one option would be to define a method that rolls the two together, calling property within the class_eval block.
Surely so much class_eval is dodgy anyway? Must be an alternative to be found...
-
Kevin Rutherford April 23rd, 2009 @ 04:16 PM
- State changed from new to resolved
This could be solved when Reek respects config comments in the code.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Defects and feature requests for <a href="http://wiki.github.com/kevinrutherford/reek">Reek</a>, the Ruby code smell detector