Gemfiles not loaded in time for environment settings

30 views
Skip to first unread message

Farrel Lifson

unread,
Jun 21, 2011, 9:17:31 AM6/21/11
to daemo...@googlegroups.com
Hi all,

I have a daemon-kit (0.1.8.1) project where I've included the Mail gem in my Gemfile. In development mode I'd like it to fake sending messages so in config/development.rb I put

  ::Mail.default_options do
    deliver_method( :test )
  end

And I get the following error:

/home/farrel/projects/data_cleaner/green/config/environments/development.rb:3:in `load_environment': uninitialized constant Mail (NameError)
from /usr/lib/ruby/gems/1.8/gems/daemon-kit-0.1.8.1/lib/daemon_kit/initializer.rb:142:in `load_environment'
from /usr/lib/ruby/gems/1.8/gems/daemon-kit-0.1.8.1/lib/daemon_kit/initializer.rb:94:in `before_daemonize'
from /usr/lib/ruby/gems/1.8/gems/daemon-kit-0.1.8.1/lib/daemon_kit/initializer.rb:54:in `run'
from /home/bob/projects/data_cleaner/green/config/boot.rb:39:in `run'
from /home/bob/projects/data_cleaner/green/config/boot.rb:19:in `boot!'
from /home/bob/projects/data_cleaner/green/config/boot.rb:70
from /home/bob/projects/data_cleaner/green/config/environment.rb:7:in `require'
from /home/bob/projects/data_cleaner/green/config/environment.rb:7
from ./bin/green:6:in `require'
from ./bin/green:6

Are the bundled gems not being loaded by the time the environment files are loaded? If not is this expected and should I be doing environment specific configuration somewhere else?

Thanks
Farrel

Kenneth Kalmer

unread,
Jun 21, 2011, 12:17:05 PM6/21/11
to daemo...@googlegroups.com
On Tue, Jun 21, 2011 at 3:17 PM, Farrel Lifson <farrel...@gmail.com> wrote:
> Hi all,
>
> I have a daemon-kit (0.1.8.1) project where I've included the Mail gem in my
> Gemfile. In development mode I'd like it to fake sending messages so in
> config/development.rb I put
>
>   ::Mail.default_options do
>     deliver_method( :test )
>   end
>
> And I get the following error:
>
> /home/farrel/projects/data_cleaner/green/config/environments/development.rb:3:in
> `load_environment': uninitialized constant Mail (NameError)
>
> Are the bundled gems not being loaded by the time the environment files are
> loaded? If not is this expected and should I be doing environment specific
> configuration somewhere else?

Hi Farrel

Please create a 'pre-initializer' where you require the mail gem and
see if this solves it. I don't think bundler by default does any
requiring of the gems, it just isolates the gem environment.

Best

--
Kenneth Kalmer
kenneth...@gmail.com
http://opensourcery.co.za
@kennethkalmer

Farrel Lifson

unread,
Jun 22, 2011, 5:33:31 AM6/22/11
to daemo...@googlegroups.com
I put a file in the pre-daemonize directory with "require 'mail'" but that didn't help, same error.

I then put "Bundler.require" in boot.rb right after the Bundler.setup, and everything worked. I know this probably isn't the correct way to do things but it works.

Kenneth Kalmer

unread,
Jun 22, 2011, 6:02:40 AM6/22/11
to daemo...@googlegroups.com

Thanks, I'll have a look at that part of the code since it came from
Bundler 0.9.26 and hasn't been changed since.

Ciao !

Farrel Lifson

unread,
Jun 22, 2011, 6:41:05 AM6/22/11
to daemo...@googlegroups.com
Just a note that in environment.rb we call

    Bundler.require :default, DaemonKit.env

which requires all the gems plus gems in any special groups (test,production). In boot.rb I only put

    Bundler.require

as DaemonKit is not initialised but then.

I'm hoping that having two Bundler.require in boot.rb and environment.rb will load everything up correctly.
Reply all
Reply to author
Forward
0 new messages