Skip to content

On-demand type generation not working #12

@eriknygren

Description

@eriknygren
  • I have tried upgrading by running bundle update types_from_serializers.
  • I have read the troubleshooting section before opening an issue.

Description 📖

On demand generation on change not working, but I found a workaround that does the job for now.

Reproduction/Logs 🐞📜

Hi Máximo, thanks for another awesome gem.

I'm struggling a bit with the autogeneration of types. It seems to be initializing properly, and indeed tracking changes too.

If I make a change to a serializer, and then check the output of running Rails.application.reloaders in my console, I get the following output:

<TypesFromSerializers::Changes:0x0000ffff9862ec68 @added=#<Set: {}>, @modified=#<Set: {"/app/app/typed_serializers/my_serializer.rb"}>, @removed=#<Set: {}>>

So the tracking does seem to be working, but it nothing is ever re-generated, unless I explicitly call TypesFromSerializers.generate_changed in the rails console, then it works.

So I then tried forcing it by adding another hook in my initializer:

  Rails.application.reloader.to_prepare do
    puts "force serializer generation"
    TypesFromSerializers.generate_changed
  end

But at this stage, it doesn't seem to be aware of file changes. Like this hook has a different context to my rails console. So nothing happens.

As a workaround for now I changed this hook to:

  Rails.application.reloader.to_prepare do
    TypesFromSerializers.generate(force: true)
  end

And it works, and it's fast enough re-generating everything that it's an acceptable workaround.

So that's my issue, and I wanted to ask you if you have an idea why this may be happening? Just to mention I have also installed the listen gem.

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions