trailblazer / trailblazer-loader

Require concept files, models and more without any autoloading magic.
MIT License
17 stars 23 forks source link

Error loading constant in non-alphabetical order #8

Closed fernandes closed 8 years ago

fernandes commented 8 years ago

Problem:

When you have two files like:

"app/concepts/thing/operation/enable.rb"
"app/concepts/thing/operation/update.rb"

and enable inheriting update

class Thing::Enable < Thing::Update

I got a NameError

Workaround

but if rename files to:

"app/concepts/thing/operation/aupdate.rb"
"app/concepts/thing/operation/enable.rb"

it works, I suspect its because Trailblazer::Loader loads in alphabetical order, makes sense?

trailblazer loader loads operation after all, but we are getting the error on Thing::Enable::Contract as shown on backtrace below

I'm gonna try to add a test (may I use fakefs on test?) but if you have any suggestion on how to workaround this heheh

Backtrace

/home/user/rails/app/concepts/thing/contract/enable.rb:2:in `<top (required)>': uninitialized constant Thing::Update (NameError)
    from /home/user/rails/vendor/bundle/ruby/2.2.0/gems/trailblazer-rails-0.2.4/lib/trailblazer/rails/railtie.rb:7:in `block in load_concepts'
    from /home/user/rails/vendor/bundle/ruby/2.2.0/gems/trailblazer-loader-0.0.9/lib/trailblazer/loader.rb:69:in `block in load_files'
    from /home/user/rails/vendor/bundle/ruby/2.2.0/gems/trailblazer-loader-0.0.9/lib/trailblazer/loader.rb:69:in `each'
    from /home/user/rails/vendor/bundle/ruby/2.2.0/gems/trailblazer-loader-0.0.9/lib/trailblazer/loader.rb:69:in `load_files'
    from /home/user/rails/vendor/bundle/ruby/2.2.0/gems/trailblazer-loader-0.0.9/lib/trailblazer/loader.rb:30:in `call'
    from /home/user/rails/vendor/bundle/ruby/2.2.0/gems/trailblazer-rails-0.2.4/lib/trailblazer/rails/railtie.rb:7:in `load_concepts'
    from /home/user/rails/vendor/bundle/ruby/2.2.0/gems/trailblazer-rails-0.2.4/lib/trailblazer/rails/railtie.rb:20:in `block (2 levels) in <class:Railtie>'
    from /home/user/rails/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/callbacks.rb:446:in `instance_exec'
    from /home/user/rails/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/callbacks.rb:446:in `block in make_lambda'
    from /home/user/rails/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5.2/lib/active_support/callbacks.rb:192:in `call'

ty! 🌹

apotonick commented 8 years ago

I am not sure if it's better to simply do

require_dependency "user/operation/update"

class Enable < User::Update

instead of having to configure the loader. I think the default setup (alphabetical) covers 95% and some manual requires I don't see as a problem?

fernandes commented 8 years ago

I was facing some problems using require, I'm gonna test with require_dependency and if it persists I reopen, otherwise it's solved... thank you! :)

apotonick commented 8 years ago

require_dependency is the "Rails Way" and registers the constants for reloading, it actually works pretty well!

fernandes commented 8 years ago

yeah.. it seems to be working, thanks for the tip ;)

apotonick commented 8 years ago

Documented here, BTW :stuck_out_tongue_winking_eye: https://github.com/trailblazer/trailblazer-loader/#debugging

fernandes commented 8 years ago

🙇