rom-rb / rom

Data mapping and persistence toolkit for Ruby
https://rom-rb.org
MIT License
2.08k stars 161 forks source link

JRuby issue #366

Closed julienXX closed 7 years ago

julienXX commented 7 years ago

Hello I'm having an issue with a lib of mine under JRuby.

It seems that it's related to ROM when doing an auto_registation on a ROM::Configuration the klass_name in lib/ruby/gems/shared/gems/rom-2.0.2/lib/rom/setup/auto_registration.rb is nil for a relationsentity.

Here is a stripped down version of the lib to repro the issue https://github.com/julienXX/jruby_rom_repro

myabc commented 7 years ago

@julienXX the namespace: option should be passed a String and not a class. e.g.

configuration.auto_registration(File.join(__dir__, 'library_api_client'), namespace: 'LibraryApiClient')

(fwiw this results in the same error on CRuby and JRuby)

myabc commented 7 years ago

@julienXX btw I had to make various other fixes (missing requires, removal of Relations, Mappers) to the example project you posted. See here: https://github.com/myabc/jruby_rom_repro/commit/18998eaa53bd0fdfc3ffde0cabea7ca017830c43

solnic commented 7 years ago

Aah! Thanks for help @myabc

I think you just want to add namespace: true because that will make auto-registration assume that the root dir of components is the namespace name. If you pass a namespace name explicitly (which must be a string as Alex mentioned) then auto-registration will load files from the path that you provided but it will not assume Relations and Mappers namespaces, so in this case LibraryApiClient::Books would be the expected relation class when you set namespace: "LibraryApiClient".

Anyhow, just set namespace: true and it'll work (I checked).

julienXX commented 7 years ago

Thanks a lot @myabc & @solnic :)