Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Stop class_eval/instance_eval being counted as a nested iterator

#34

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!)

Reported by Ashley Moran · April 3rd, 2009 @ 03:04 PM

State: resolved
Milestone: none
Assigned to: Kevin Rutherford Kevin Rutherford

Activity

  1. Kevin Rutherford
    Kevin Rutherford
    • Assigned user set to Kevin Rutherford

    April 5th, 2009 @ 07:50 AM

  2. Kevin Rutherford
    Kevin Rutherford

    Can you simply extract the outer block's body into a new method?

    April 5th, 2009 @ 08:13 AM

  3. Kevin Rutherford
    Kevin Rutherford

    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...

    April 7th, 2009 @ 01:28 PM

  4. Kevin Rutherford
    Kevin Rutherford
    • State changed from new to resolved

    This could be solved when Reek respects config comments in the code.

    April 23rd, 2009 @ 04:16 PM

  5. Kevin Rutherford

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.