Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems upgrading to 0.9.29 and dependencies #556

Closed
simonhambly opened this issue May 24, 2011 · 15 comments
Closed

Problems upgrading to 0.9.29 and dependencies #556

simonhambly opened this issue May 24, 2011 · 15 comments
Assignees
Milestone

Comments

@simonhambly
Copy link

I'm upgrading from 0.9.28 (previously upgrading from 0.9.23) and having some problems loading dependencies. I've followed the instructions on the 0.9.29 blog post about adding dependencies.

In the MyApp.dependencies line I've assumed that MyApp is the application name... so have replaced with my app name (DemoProject). When I run padrino console... I get an "uninitialized constant DemoProject (NameError)"

What am I missing?

@nesquena
Copy link
Member

Excellent question, perhaps you aren't missing anything and the post is incorrect which I apologize for. I'm curious what if you were to try it on the after_load hook? @DAddYE can you help me correct the blog post so the dep declaration works?

@simonhambly
Copy link
Author

Adding the lines to the after_load hook stops that error. After further investigation, if you explicitly require the app/app.rb file then you can add load_paths and dependencies statements in before_load without getting the above error.

However...

Being able to add the statements to the either of the hooks doesn't solve the underlying problem: that files in the app/lib folder aren't being autoloaded.

If you create demo_project as:

$ padrino g project demo_project
$ cd demo_project 
$ padrino g plugin carrierwave
$ mkdir app/lib
$ mv lib/uploader.rb app/lib/uploader.rb

and configure load_paths/dependencies by:

# config/boot.rb
require Padrino.root("app/app.rb")
Padrino.before_load do
  DemoProject.load_paths << ["app/lib/*.rb"]
  DemoProject.dependencies << Padrino.root("app/lib/uploader.rb")
end

then load the app via:

$ padrino console

I get uninitialized constant Upload::Uploader (NameError).

In 0.9.28 and below (at least until 0.9.23) using the following worked and lib files in app/lib were autoloaded correctly

# config/boot.rb
Padrino.custom_dependencies(Padrino.root("app/lib/uploader.rb"))

Is there something else I need to do to get app/lib/*.rb files autoloading?

p.s. I'm using multiple apps in a project and want to keep app specific lib files with the appropriate app (in app/lib, app2/lib etc) - that's why I want to move the carrierwave uploader to app/lib.

@nesquena
Copy link
Member

@DAddYE Thoughts on how he can achieve this in 0.9.29? Considering we removed custom_dependencies?

@DAddYE
Copy link
Member

DAddYE commented May 25, 2011

@simonhambly why you can't simply do that:

class MyApp < Padrino::Application
  dependencies << Padrino.root("app/lib/uploader.rb")
  load_paths     << ["app/lib/*.rb"]
end

@nesquena
Copy link
Member

Oh if that worked, even better I can tweak the blog post. Let me know @simonhambly

@ghost ghost assigned DAddYE May 25, 2011
@simonhambly
Copy link
Author

@nesquena - no joy. Adding @DAddYE's suggestion to to MyApp doesn't work - still get uninitialized constant error.

btw can work around by explicitly requiring the app/lib/uploader.rb file in models/upload.rb works - put kind of defeats auto loading...

Also autoloading works if leave uploader as lib/uploader.rb - so is there a difference between how 'core' (I assume) loads dependencies and how the applications load dependencies?

@nesquena
Copy link
Member

Yes I see that as well, it has to do with order of operations I think, the dependencies/load_paths are being added too late in the loading process. @DAddYE Do you have any other approach for them to try? Hopefully there is a workable solution. If not, we will investigate, fix this and release a new patch ASAP. Thanks for bringing this to our attention.

@nesquena
Copy link
Member

nesquena commented Jun 7, 2011

@DAddYE This seems to be a real problem no? We need a way to recommend people to require deps or what do you recommend?

DAddYE added a commit that referenced this issue Jun 7, 2011
* Enhancement for #556 now is possible to add custom prerequisites to our app
@DAddYE
Copy link
Member

DAddYE commented Jun 7, 2011

Fixed, from our docs:

An array of file to load before your app.rb, basically are files wich our app depends on.

By default we look for files:

  yourapp/models.rb
  yourapp/models/**/*.rb
  yourapp/lib.rb
  yourapp/lib/**/*.rb

Examples

MyApp.prerequisites << Padrino.root('my_app', 'custom_model.rb')

Btw as said we load all deps under app_name/lib/*/.rb so I think is no more necessary.

@DAddYE DAddYE closed this as completed Jun 7, 2011
@nesquena
Copy link
Member

nesquena commented Jun 7, 2011

@simonhambly Can you confirm that the prerequisites method does properly load files now?

DAddYE added a commit that referenced this issue Jun 7, 2011
@simonhambly
Copy link
Author

@nesquena, just had chance to test - the uploader in app/lib is correctly loaded now using the latest code.

Incidently had some issues with carrierwave plugin - it didn't seem to create the upload model in the correct place. Instead it created it as model/upload.rb instead of app/model/upload.rb.

To get the plugin created I had to run:

$ padrino g plugin carrierwave
$ mv model/upload.rb app/model/upload.rb
$ padrino g plugin carrierwave

Then I could test.

Not sure whether this is plugin generator issue or the carrierwave plugin itself.

One last thing on the "Padrino Guides - The Bleeding Edge" instructions... tweaking the version no (appending "-dev") means

$ rake fresh

no longer works.

When I ran

$ bundle install

I got an "Malformed version number string 0.9.29-dev (ArgumentError)" thrown. So the Bleeding Edge guide may need updating.

@nesquena
Copy link
Member

Ok thanks simon, we will tweak the carrierwave plugin to fix that issue and update the bleeding edge guide.

@nesquena
Copy link
Member

@achiu Can you update the plugins? https://github.com/padrino/padrino-recipes/blob/master/plugins/carrierwave_plugin.rb seems to specify app/models but your recent changes to move everything into 'models' by default probably broke several plugins.

@achiurizo
Copy link
Member

@nesquena I made the changes here: padrino/padrino-recipes@4bdb8c5. I'll check out to see if there are any other issues that arise from latest changes but that should cover them.

@nesquena
Copy link
Member

Ah great thanks, I will review the recipes a bit later but will assume they are taken care of now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants