Giter Site home page Giter Site logo

Comments (5)

ElMassimo avatar ElMassimo commented on June 8, 2024

Hi Erik! Thanks for reporting.

It would be interesting to know if in your app the following condition is met when the gem is loaded.

You can try opening the gem by running bundle open types_from_serializers, and adding a binding.pry or debug statement to check if Rails.env is available.

The most likely scenario is that this condition is false, so maybe the reloader and the to_prepare hook are not registered in the running server (even though they are registered in the console).


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

That makes sense, because it's the TypesFromSerializers.track_changes reloader that gathers the changes for generate_changes to handle it.

from types_from_serializers.

eriknygren avatar eriknygren commented on June 8, 2024

Hi Máximo, thanks for the quick response!

Following your steps, I can see that the Rails.env is indeed correctly set, but the problem seems to be that code in the following block does not run:

initializer "types_from_serializers.reloader" do |app|

I'm not sure if this is due to something being odd with my app's set up that leads to an incorrect load order, and this hook getting registered too late. But after reading this thread, I tried changing the hook mentioned above to:

config.after_initialize do |app|

and then everything works as expected.

I don't know enough about the inner workings of Rails to say if this is a issue with this gem or the problem is in my app.

from types_from_serializers.

ElMassimo avatar ElMassimo commented on June 8, 2024

That thread suggests that by the time the railtie is loaded, Rails.application.initialize! might have already been called.

You could try debugging to see in which order the code loads in your app.

Another thing that might be affecting how things load is whether you have this gem in a non-standard group in your Gemfile or something that causes this line not to load the gem:

Bundler.require(*Rails.groups)

from types_from_serializers.

eriknygren avatar eriknygren commented on June 8, 2024

Hi, apologies the load order might have been a false flag, using docker I struggled a bit to patch the installed version of the gem inside the container but I have now succeeded with that. Putting debug prints in there I can see the initializer firing as expected.

I have now put some console outputs around the generator class, and I can see that changes.updated? is always false. So it gets to this stage, but never regenerates anything because of that.

So the problem seems to be the changes aren’t being successfully tracked, and I’m not sure exactly why. This is where it gets tricky because if look in the rails console, I can see entries in the @modified list if I inspect the rails reloaders, highly confusing!

Possibly the bug could be related to the fact that I've changed the default folder to:

    config.serializers_dirs = [Rails.root.join("app/typed_serializers").to_s]

but this has not caused any other issues.

If there’s nothing else obvious to try, nothing to worry about as it works pretty well with this hook set up as a workaround

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

from types_from_serializers.

ElMassimo avatar ElMassimo commented on June 8, 2024

using docker

It could be related to the volume that is mounted, and whether listen is able to detect changes and notify them.

Thanks for sharing a workaround, it should be helpful for other folks using Docker in development.

from types_from_serializers.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.