You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then you will see the issue that I am facing. It's a two-parter:
The class of instance that is returned by repo.all.firstshould be a Projects::Project, and it is... but it's seemingly coming from Dry::Core::ClassBuilder, rather than the one defined in the application.
The instance should respond to a to_model call, but it doesn't. This call should be inherited from ApplicationModel, by way of the Projects::Project class within the application.
So in effect, both of the last statements in projects.rb should return true if this code is working as it should.
To attempt to work around this, I've tried doing require "projects/project" in project_repository.rb, but this flips it around:
It defines the class as an anonymous class.
The instance does respond to a to_model call.
The source of this problem appears to be this code within ClassBuilder:
If I remove the if statement from this line and manually require the projects/project file in my ProjectRepository class, everything works correctly, at least in my application.
That line -- in its entirety -- was added in abdb106, but the reasoning for this is opaque to me. Seems to be fixing / working around some sort of Ruby bug that only existed pre-Ruby 2.4? Well, my app is using Ruby 2.5 so this line doesn't do anything.
I'm betting this is going to be down to some weird combination between dry-core and Rails' own auto-loading mumbo-jumbo. I'd just like to get an expert opinion before I go blaming Rails (again).
The text was updated successfully, but these errors were encountered:
radar
pushed a commit
to radar/exploding-rails-rom-dry-example-app
that referenced
this issue
Apr 25, 2018
I suspect if I turn eager_load to true in both development.rb and test.rb it would work around my problem, but I want to see if there's another potential solution first.
Hello!
I have a Rails application which has some unusual behaviour when paired with dry-core.
Here's the branch that replicates the issue. If you clone down this app with this branch and run:
Then you will see the issue that I am facing. It's a two-parter:
repo.all.first
should be aProjects::Project
, and it is... but it's seemingly coming fromDry::Core::ClassBuilder
, rather than the one defined in the application.to_model
call, but it doesn't. This call should be inherited fromApplicationModel
, by way of theProjects::Project
class within the application.So in effect, both of the last statements in
projects.rb
should returntrue
if this code is working as it should.To attempt to work around this, I've tried doing
require "projects/project"
inproject_repository.rb
, but this flips it around:to_model
call.The source of this problem appears to be this code within
ClassBuilder
:dry-core/lib/dry/core/class_builder.rb
Lines 69 to 77 in 3b26625
In particular:
dry-core/lib/dry/core/class_builder.rb
Line 73 in 3b26625
If I remove the
if
statement from this line and manually require theprojects/project
file in myProjectRepository
class, everything works correctly, at least in my application.That line -- in its entirety -- was added in abdb106, but the reasoning for this is opaque to me. Seems to be fixing / working around some sort of Ruby bug that only existed pre-Ruby 2.4? Well, my app is using Ruby 2.5 so this line doesn't do anything.
I'm betting this is going to be down to some weird combination between dry-core and Rails' own auto-loading mumbo-jumbo. I'd just like to get an expert opinion before I go blaming Rails (again).
The text was updated successfully, but these errors were encountered: