Support transient attributes in rom-factory

It would be useful to have something similar to FactoryBot transient attributes in rom-factory.

Something like this.

Factory.define(:user) do |f|
  f.transient do |t|
    t.password { 'P@ssword123!' }
  end

  f.name { FFaker::Name.name }
  f.email { FFaker::Internet.email }
  f.password_digest { |password| BCrypt::Password.create(password).to_s }

  f.timestamps
end

Do you think this is something that could be interesting to add to the library?

1 Like

Hey, thanks for the suggestion. Yes, it’s something that we’ve wanted to add :slight_smile:

This is also something I would like to have, so I’ve been poking around the codebase to see what implementation would be like.

It started out simple enough but I’m coming to the conclusion that TupleEvaluator needs attention. It’s really hard to follow the execution process, and attributes are being evaluated multiple times. There’s probably quite a lot of allocations that could be removed.

@solnic you’ve mentioned that you intend to do some refactoring on this for ROM 6.0 so I don’t want to step on your toes here, but I’m guessing this is probably not the highest priority either.

For starters, rom-factory still depends on rom-core and technically supports Ruby >= 2.4 which is long past time to retire. The main ROM gems however have already set 2.7 as the lower bound, so an easy win would be to upgrade this code for kwargs and remove all the compatibility stuff with ruby2_keywords.

Open to a PR (or more) to set the lowest Ruby support to 2.7? This could also simplify some stuff with new language features.

Feel free to work on it. I won’t be working on it until after we release Hanami 2.0.