Rake question

I’ve searched this group and google, but have not found the answer to my
question. If there is a post about it somewhere, I’d greatly appreciate
a link. I also started to dig into the rake code, but, frankly, didn’t
understand it.

Question:

Why does it seem that :environment is required in order to have
ActiveRecord::Base.configurations populated with the contents of
database.yml.

Explanation:

namespace :phillip do
task :mytask do
ActiveRecord::Base.configurations.each_value do |config|
p config[‘database’]
end
end
end

prints nothing. Yet

namespace :phillip do
task :mytask => :environment do
ActiveRecord::Base.configurations.each_value do |config|
p config[‘database’]
end
end
end

outputs the database names in my database.yml file.

I understand that if I’m actually trying to do something, I’d need the
environment. But it seems that the configurations would be available
without knowing a specific environment.

Peace,
Phillip

:environment is a task that loads up environment.rb.

When you do

task :foo => :environment

you’re saying “my task depends on another task called :environment, so
invoke that first , and then do my stuff”

On Tue, Jul 1, 2008 at 1:10 PM, Phillip K. <

On 1 Jul 2008, at 19:10, Phillip K. wrote:

outputs the database names in my database.yml file.

I understand that if I’m actually trying to do something, I’d need the
environment. But it seems that the configurations would be available
without knowing a specific environment.

Well at a very basic level, ActiveRecord::Base.configurations isn’t
going to populate itself. rails isn’t even loaded if your task doesn’t
depend on :environment

Fred

Brian H. wrote:

:environment is a task that loads up environment.rb.

When you do

task :foo => :environment

you’re saying “my task depends on another task called :environment, so
invoke that first , and then do my stuff”

Thanks for the explanation, Brian. That makes much more sense now. I see
that I was confusing a task with a variable/parameter/argument.

Peace,
Phillip

Thanks for that Brian I didn’t know either!

Frederick C. wrote:

Well at a very basic level, ActiveRecord::Base.configurations isn’t
going to populate itself. rails isn’t even loaded if your task doesn’t
depend on :environment

Fred

Thanks, Fred. I’m understanding now. I haven’t ventured into rake until
now and didn’t get it. I read through some of the rake docs, but
apparently didn’t actually digest anything.

Phillip