On Tue, Jan 5, 2010 at 12:22 PM, Marius Mårnes Mathiesen
<[email protected]> wrote:
> On Tue, Jan 5, 2010 at 11:14 AM, Benjamin Podszun
> <[email protected]> wrote:
>>
>> On Tue, Jan 5, 2010 at 10:51 AM, Marius Mårnes Mathiesen
>> > environment.rb is the file normally included/required in order to load
>> > the
>> > Rails environment; boot.rb is loaded from this.
>>
>> The other way around, no?
>
> Actually, no - Rails takes care of loading the files for you provided you
> load environment.rb
> If you open an IRB session and "require config/environment" everything
> needed is loaded, which is not the case if you "require config/boot":
> <RAILS_ROOT> irb
> irb(main):001:0> require "config/boot"
> => true
> irb(main):002:0> User
> NameError: uninitialized constant User
> from (irb):2
> from /usr/local/bin/irb:12:in `<main>'
>
> <RAILS_ROOT> irb
> irb(main):001:0> require "config/environment"
> => true
> irb(main):002:0> User
> => User(id: integer, login: string, email: string, crypted_password: string,
> salt: string, created_at: datetime, updated_at: datetime, remember_token:
> string, remember_token_expires_at: datetime, activation_code: string,
> activated_at: datetime, ssh_key_id: integer, fullname: string, url: text,
> identity_url: text, is_admin: boolean, suspended_at: datetime, aasm_state:
> string, public_email: boolean, wants_email_notifications: boolean,
> password_key: string, avatar_file_name: string, avatar_content_type: string,
> avatar_file_size: integer, avatar_updated_at: datetime)
> In my understanding, including environment.rb should be enough to get a
> working Rails environment.
> Side note: The poller script is basically part of the activemessaging Rails
> plugin (http://code.google.com/p/activemessaging/), with only slight
> modifications for Gitorious.

Thank you for the ruby quickstart. Poking around in irb I created this
series of "tests". Are they useful?

Reminder: This is what I have now:

bpods...@tis-gitorious:/var/www/git.devtools/gitorious$ git diff script/poller
diff --git a/script/poller b/script/poller
index 9a4ee3f..7881cf1 100755
--- a/script/poller
+++ b/script/poller
@@ -8,6 +8,7 @@ else
   Encoding.default_external = Encoding::UTF_8
 end

+require File.dirname(__FILE__) + '/../config/boot'
 require 'rubygems' if RUBY_VERSION < '1.9'
 require 'daemons'

I created a copy of the poller script that just sources everything and
outputs the settings I need:

bpods...@tis-gitorious:/var/www/git.devtools/gitorious$ diff
script/poller script/poller_test
11d10
< require File.dirname(__FILE__) + '/../config/boot'
31c30,31
< Daemons.run(script_file,options)
---
> puts ActionMailer::Base.smtp_settings
> #Daemons.run(script_file,options)

bpods...@tis-gitorious:/var/www/git.devtools/gitorious$
RAILS_ENV=production script/poller_test
script/poller_test:30:in `<main>': uninitialized constant ActionMailer
(NameError)

Modified the test script to include environment:

bpods...@tis-gitorious:/var/www/git.devtools/gitorious$ diff
script/poller script/poller_test
11c11
< require File.dirname(__FILE__) + '/../config/boot'
---
> require 'config/environment'
31c31,32
< Daemons.run(script_file,options)
---
> puts ActionMailer::Base.smtp_settings
> #Daemons.run(script_file,options)
bpods...@tis-gitorious:/var/www/git.devtools/gitorious$
RAILS_ENV=production script/poller_test
{:address=>"MyHost", :port=>"25", :domain=>"MyHost",
:authentication=>:plain, :user_name=>"f...@myhost",
:password=>"MyPassword"}

So that works. Going back to 'config/boot' instead doesn't work, as
you said, and results in the same error as above (uninitialized
constant).

Two questions at this point:

1) Why does the initial change that I made work at all (it does, just
verified it again). I'll play around some after work/tonight..

2) Should these settings be available at that point of the script at all?

Thanks,
Ben

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]

Reply via email to